poi操作word_poi word操作,2024年最新大数据开发开发进大厂面试必备技能

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新大数据全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注大数据)
img

正文

Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: ‘org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream$Builder org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream.builder()’
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1087)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)

上述报错是由于导入的依赖版本冲突,以下更正

单元格字体居中
XWPFParagraph para1 = cell1.getParagraphs().get(0);
para1.setAlignment(ParagraphAlignment.CENTER);

  <!-- https://mvnrepository.com/artifact/org.apache.poi/poi生成word文档 -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>

/\*\*
 \* 动态填充word
 \*/
@Component
public class ToDocUtils {
    //使用示例
    /\*\*
 \* 导出docx
 \*
 \* @param wesInfoService
 \* @param templatePath
 \* @param outPath
 \* @param map
 \*/
    public static boolean  getDocx(WesInfoServiceImpl wesInfoService, String templatePath, String outPath, Map<String, String> map, String familyNum, List<UnionFilter> list, List<UnionFilter> list1, List<UnionFilter> list2, List<QualityControlData> list3, HttpServletRequest request, HttpServletResponse response, InspectionReport report, List<OmimData> omimDatas){
        XWPFDocument document = null;
        try{
            File file = new File(templatePath);
            InputStream in = new FileInputStream(file);
            document = new XWPFDocument(in);
            //获取表格对象集合
            List<XWPFTable> tables = document.getTables();
            insertTable3(document,tables.get(4),list3,omimDatas); //质控表
            Iterator<XWPFHeader> headerIterator = document.getHeaderList().iterator();
            while (headerIterator.hasNext()){
                XWPFHeader header = headerIterator.next();
                List<XWPFParagraph> paragraphs = header.getParagraphs();
                for (XWPFParagraph paragraph : paragraphs) {
                    List<XWPFRun> runs = paragraph.getRuns();
                    for (XWPFRun run : runs) {
                        String text = run.getText(0);
                        if (text != null && text.contains("医院LOGO")) {
                            int index = text.indexOf("医院LOGO");
                            run.setText("",index);
                            // 插入新的图片
                            InputStream imgStream = new FileInputStream("src/main/resources/templates/head1.png");
                            run.addPicture(imgStream, XWPFDocument.PICTURE\_TYPE\_PNG, "src/main/resources/templates/head1.png", Units.toEMU(75), Units.toEMU(65));
                        }
                        if(text!=null&&text.contains("proband\_NO")){
                            int index = text.indexOf("proband\_NO");
                            run.setText(map.get("proband\_NO"),index);
                        }
                        if(text!=null&&text.contains("proband\_name")){
                            int index = text.indexOf("proband\_name");
                            run.setText(map.get("proband\_name"),index);
                        }
                    }
                }
            }
            Iterator<XWPFFooter> footerIterator = document.getFooterList().iterator();
            while (footerIterator.hasNext()){
                XWPFFooter footer = footerIterator.next();
                List<XWPFParagraph> paragraphs = footer.getParagraphs();
                for (XWPFParagraph paragraph : paragraphs) {
// paragraph.setAlignment(ParagraphAlignment.LEFT);
                    replaceParagraph(paragraph,map);
                }
            }
            replaceInTable(document,map);  //替换表格里面的变量
            //替换段落里的
            for (XWPFParagraph paragraph : document.getParagraphs()) {
                replaceParagraph(paragraph, map);
            }
            // 如果文件夹不存在 则建立新文件夹
            File dir= new File(outPath);
            if (!!dir.exists()) {
                dir.mkdirs();
            }
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            OutputStream out = new FileOutputStream(outPath);
            document.write(bos);
            out.write(bos.toByteArray());
            FileInputStream inputStream = new FileInputStream(dir);
            XWPFDocument xwpfDocument = new XWPFDocument(inputStream);
            List<XWPFTable> xwpftables = xwpfDocument.getTables();
            for (int i = 1; i < xwpftables.size(); i++) {
                for (int i1 = 1; i1 < xwpftables.get(i).getRows().size(); i1++) {
                    for (int i2 = 0; i2 < xwpftables.get(i).getRows().get(i1).getTableCells().size(); i2++) {
                        if(xwpftables.get(i).getRows().get(i1).getTableCells().get(i2).getParagraphs().get(0).getRuns().size()==0){
                            continue;
                        }
                        for (XWPFParagraph paragraph : xwpftables.get(i).getRows().get(i1).getTableCells().get(i2).getParagraphs()) {
                            for (XWPFRun run : paragraph.getRuns()) {
                                \*\*run.setFontSize(8);\*\*
                            }
                        }
                    }
                }
            }

            ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
            OutputStream out1 = new FileOutputStream(outPath);
            xwpfDocument.write(bos1);
            out1.write(bos1.toByteArray());
            InputStream fis1 = new BufferedInputStream(new FileInputStream(outPath));
            response.reset();//重置 响应头
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/msword");//告知浏览器下载文件,而不是直接打开,浏览器默认为打开
            response.setHeader(CONTENT\_DISPOSITION, "attachment;filename=" +  URLEncoder.encode(familyNum+report.getName()+".doc", "UTF-8"));
            byte[] b1 = new byte[1024];
            int len1;
            while ((len1 = fis1.read(b1)) > 0){
                response.getOutputStream().write(b1, 0, len1);
            }
            return true;
        }
        catch (Exception e){
            e.printStackTrace();
            return false;
        } finally{
            try
            {
                if ( document != null )
                {
                    document.close();
                }
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }

    /\*\*
 \* 表格质控
 \* @param document
 \* @param table
 \* @param tableList
 \* @param omimDatas
 \*/
    public static void insertTable3(XWPFDocument document,XWPFTable table, List<QualityControlData> tableList,List<OmimData> omimDatas){
        //创建行,根据需要插入的数据添加新行c,不处理表头
        //判断需要插入的数量
        if (tableList.size() > 3) {//我的模板预留了1行
            for (int i=0;i<tableList.size()-3;i++) {
                insertRow(table,2 ,4+i);
            }
        }
        //遍历表格插入数据
        List<XWPFTableRow> rows = table.getRows();
        for(int i = 1; i < tableList.size() + 1; i++){


**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)**
![img](https://img-blog.csdnimg.cn/img_convert/3f44fe1950caec6c8a7fb25ad94c7e03.png)

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)**
[外链图片转存中...(img-0UBQw8AJ-1713149413747)]

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Java的POI库可以很方便地操作Word文档,包括复制表格。 下面是一个示例代码,演示如何使用POI库复制Word文档中的表格: ```java import java.io.*; import org.apache.poi.xwpf.usermodel.*; public class CopyTable { public static void main(String[] args) throws Exception { // 读取Word文档 FileInputStream fis = new FileInputStream("input.docx"); XWPFDocument doc = new XWPFDocument(fis); // 获取第一个表格 XWPFTable table = doc.getTables().get(0); // 创建新表格 XWPFTable newTable = doc.createTable(); // 复制表格内容 for (int i = 0; i < table.getNumberOfRows(); i++) { XWPFTableRow oldRow = table.getRow(i); XWPFTableRow newRow = newTable.createRow(); newRow.setHeight(oldRow.getHeight()); for (int j = 0; j < oldRow.getTableCells().size(); j++) { XWPFTableCell oldCell = oldRow.getCell(j); XWPFTableCell newCell = newRow.createCell(); newCell.getCTTc().set(oldCell.getCTTc()); newCell.setText(oldCell.getText()); } } // 保存Word文档 FileOutputStream fos = new FileOutputStream("output.docx"); doc.write(fos); // 关闭文件流 fos.close(); fis.close(); } } ``` 这段代码首先读取名为“input.docx”的Word文档,并获取其中的第一个表格。然后,它创建一个新表格,并将第一个表格的内容复制到新表格中。最后,它将修改后的Word文档保存为名为“output.docx”的文件。 注意,这段代码只复制了表格的内容,而没有复制表格的样式。如果需要复制表格的样式,请参考POI库的API文档,查找相应的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值