Java ms word';s图像在我打开它10秒后消失
我有一个ms word文档,我正在用java创建它ApachePOI。此文档有很多图像,因为word文档的大小太大(如300MB)。当我打开文档时,它冻结了,图像就这样消失了 我在微软word里放了这样的图片Java ms word';s图像在我打开它10秒后消失,java,ms-word,apache-poi,Java,Ms Word,Apache Poi,我有一个ms word文档,我正在用java创建它ApachePOI。此文档有很多图像,因为word文档的大小太大(如300MB)。当我打开文档时,它冻结了,图像就这样消失了 我在微软word里放了这样的图片 int picturesCount=imgPaths.size(); int tableRows=(int)Math.round(picturesCount/2d); XWPFParagraph parag=document.creat
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();
}
}
}
int picturesCount=imgPaths.size();
int tableRows=(int)Math.round(picturesCount/2d);
XWPFParagraph parag=document.createParagraph();
XWPFRun=parag.createRun();
InputStream为2=null;
XWPFTable imgTable;
XWPFTableCell细胞;
int TableRows=0;
for(int f=0;f0)parag=cell.getparations().get(0);else parag=cell.addParague();
如果(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=单元格。添加段落();
run.setText(des_img.get(des));
des++;
运行.getCTR().getDrawingArray(0).getInlineArray(0).addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoChangeAspect(true);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(无效格式){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
}
我该如何解决这个问题?有什么建议吗?也许不用那么多图片?没有人想处理300MB的word文件。它的方式太慢了,因为word无法处理that@XtremeBaumer我必须使用许多图片,因为我从access数据库中得到一份包含许多图片的报告。然后将其拆分。要处理的word文件最大应为20MB。顺便说一句,内容消失是word的问题,如果可以的话,apache poiTry将其写入PDF格式不会导致内容消失。MS Word无法处理300 MB的大小。单个
JPEG
文件的大小(以字节为单位)有多大?也许在将它们嵌入word之前,您可以使用buffereImage
将它们缩放到较小的大小?当然,尺寸越小,质量也越差。