我的访问数据库中有图像路径,并且正在将图像放入Word文档表中。我想在每个表格后添加分页符。我编写了此代码来执行此操作,但它并没有在每个表之后添加分页符。
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 c=0;c<imgPaths.size();c++)
{
if(!imgPaths.get(c).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();
}
}
}
parag.setPageBreak(true);
我在每个表端点之后编写了此代码 parag.setPageBreak(true); 。