我有一个ms word文档,正在用Java创建它。该文档有很多图像,因为word文档的大小太大(例如300 mb)。当我打开文档时,它冻结了,图像像这样消失了。
我正在像这样用ms字输入图片
int picturesCount=imgPaths.size();
int tableRows=(int)Math.round(picturesCount/2d);
XWPFParagraph parag=document.createParagraph();
XWPFRun run=parag.createRun();
InputStream is2 = null;
XWPFTable imgTable;
XWPFTableCell cell;
int TableRows=0;
for(int f=0;f<imgPaths.size();f++)
{
if(!imgPaths.get(f).equals("-"))
{
TableRows++;
}
}
int rows=(int)Math.round(TableRows/2d);
imgTable=document.createTable(rows,2);
imgTable.removeBorders();
int tableRow=0;
int tableCell=0;
int des=0;
for(String pictureURL:imgPaths) {
if(!"-".equals(pictureURL)) {
try {
cell=imgTable.getRow(tableRow).getCell(tableCell++);
if(tableCell==2) {
tableCell=0;
tableRow++;
}
is2 = new FileInputStream(pictureURL);
if(cell.getParagraphs().size()>0) parag=cell.getParagraphs().get(0);else parag=cell.addParagraph();
if(parag.getRuns().size()>0) run=parag.getRuns().get(0);else run=parag.createRun();
run.addPicture(is2, XWPFDocument.PICTURE_TYPE_JPEG, "Images", Units.toEMU(250), Units.toEMU(250));
parag=cell.addParagraph();
run.setText(des_img.get(des));
des++;
run.getCTR().getDrawingArray(0).getInlineArray(0).addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoChangeAspect(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
任何建议如何解决这个问题?