笨蛋炒面 2015-10-20 06:00 采纳率: 0%
浏览 1590

OpenXml 单元格合并后Word打开提示错误

public static OutputStream creatWord(ArrayList<String> imageUrllist,String[] names,OutputStream os) {
    int imageSize = imageUrllist.size();
    try {
        //word模板的路径
        CustomXWPFDocument doc = new CustomXWPFDocument(new FileInputStream(templePath+"exp.docx"));
        Iterator<XWPFTable> it = doc.getTablesIterator();  
        while(it.hasNext()){  
            XWPFTable table = it.next();  
            List<XWPFTableRow> rows = table.getRows(); 
            int num = 0;
            for(int i =0;i<rows.size();i++){  
                List<XWPFTableCell> cells = rows.get(i).getTableCells();  
                for(int j=0;j<cells.size();j++){
                    //num+1
                    num++;
                    if(num <= imageSize){
                        CustomXWPFDocument docTemp = ExpWordUtil.addPic(imageUrllist.get(2*i+j), doc, cells.get(j), 2*i+j+1, names[2*i+j]);
                        doc = docTemp!=null?docTemp:doc;
                    }else{
                        cells.get(j).removeParagraph(0); 
                    }
                    List<XWPFParagraph> pars = cells.get(j).getParagraphs();  
                    for(XWPFParagraph par:pars){  
                        List<XWPFRun> runs = par.getRuns();  
                        for(XWPFRun run:runs){  
                            run.removeBreak();  

                        }  
                    }  
                }  
            }  
        }
        doc.write(os);
        os.flush();
        os.close();
        return os;
    }  catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (InvalidFormatException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

  • 写回答

1条回答 默认 最新

  • 笨蛋炒面 2016-03-12 00:46
    关注

    发现是Excel版本问题

    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波