乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > java程序,使用poi,用word模板,如何在分页后重复展...-poi合并word,poi拼接word

java程序,使用poi,用word模板,如何在分页后重复展...-poi合并word,poi拼接word

作者:乔山办公网日期:

返回目录:word文档


光看这个问题,就觉得很复杂,其中如果再出现单元格合并分隔的情况,就更不好搞了。复杂的表格,即使在excel里,用java来处理,也是一项庞大的工程。况且,在office03版以上,用poi读取excel,很容易出现内存溢出。个人觉得这样做似乎意义不大,编程不就是把复杂问题简单化嘛。不如直接手动复制粘贴来得快。

这个可以直接在要被载入的word模板里面设置好,直接用就行了。
这个可以直接在要被载入的word模板里面设置好,直接用就行了。

给你个例子

iText-2.1.5.jar、iTextAsian.jar、iText-rtf-2.1.4.jar
public String CreateWord() {

try {
Document document = new Document(PageSize.A4);
RtfWriter2.getInstance(document, new FileOutputStream("c:\\"));
document.open();

for (int i = 0; i < datalist.size(); i++) {
Lawmanager lawmanager = (Lawmanager) datalist.get(i);

Paragraph title = new Paragraph("行 政 执 法7a64e78988e69d83365 人 员 登 记 表");
title.setAlignment(Element.ALIGN_CENTER);
title.setFont(new RtfFont("仿 宋__GB2312", 18, Font.BOLD, Color.BLACK));
document.add(title);

Table table = new Table(7);
table.setWidth(100);
table.setBorderWidth(1);
table.setBorderColor(Color.BLACK);
table.setPadding(0);
table.setSpacing(0);
table.setAlignment("CENTER");
table.setWidths(new float[]{16.0f,16.0f,15.0f,15.0f,16.0f,22.0f,0.0f});
table.setAutoFillEmptyCells(true);

RtfFont font = new RtfFont("仿 宋__GB2312", 12, Font.COURIER, Color.BLACK);

Cell cell = new Cell(new Phrase("姓 名", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase(lawmanager.getLawname(), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setColspan(2);
table.addCell(cell);
cell = new Cell(new Phrase("性 别", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase(lawmanager.getLawsex(), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
try {
Image lawPic = Image.getInstance(publicTools.getPath() + "/" + lawmanager.getLawpic());
lawPic.scaleAbsolute(105, 135);
cell = new Cell(lawPic);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setRowspan(4);
table.addCell(cell);
} catch (IOException e) {
publicTools.OutputLog(e.toString(), "ERROR", 0);
Image lawPic = Image.getInstance(publicTools.getPath("upfile/pic") + "pic.jpg");
lawPic.scaleAbsolute(105, 135);
cell = new Cell(lawPic);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setRowspan(4);
table.addCell(cell);
}
cell = new Cell("\n\n");
cell.setBorderColor(new Color(255, 255, 255));
cell.setBackgroundColor(new Color(255, 255, 255));
table.addCell(cell);

cell = new Cell(new Phrase("出生年月日", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase(lawmanager.getLawbirthdate(), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setColspan(2);
table.addCell(cell);
cell = new Cell(new Phrase("民 族", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase(lawmanager.getVolkdictionaryname(), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell("\n\n");
cell.setBorderColor(new Color(255, 255, 255));
cell.setBackgroundColor(new Color(255, 255, 255));
table.addCell(cell);

cell = new Cell(new Phrase("工作单位", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase(" " + lawmanager.getDeptname(), font));
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setColspan(4);
table.addCell(cell);
cell = new Cell("\n\n");
cell.setBorderColor(new Color(255, 255, 255));
cell.setBackgroundColor(new Color(255, 255, 255));
table.addCell(cell);

cell = new Cell(new Phrase("职 务", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase(lawmanager.getPostdictionaryname(), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase("参加工作时间", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
cell = new Cell(new Phrase(lawmanager.getLawworkdate(), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setColspan(2);
table.addCell(cell);
cell = new Cell("\n\n");
cell.setBorderColor(new Color(255, 255, 255));
cell.setBackgroundColor(new Color(255, 255, 255));
table.addCell(cell);

document.add(table);

Phrase phrase = new Phrase("\n注:如未取得行政执法证件、行政执法资格的,在表中“行政执法证件编号”、“行政执法资格编号”栏中显示“0”。", new RtfFont("黑 体", 10, Font.TIMES_ROMAN, Color.red));
document.add(phrase);

if(i < datalist.size() - 1){
document.newPage();
}
}
document.close();
publicTools.insertLog("5", "下载Word文件", userSession);
} catch (FileNotFoundException e) {
publicTools.OutputLog(e.toString(), "ERROR", 0);
e.printStackTrace();
} catch (DocumentException e) {
publicTools.OutputLog(e.toString(), "ERROR", 0);
e.printStackTrace();
} catch (MalformedURLException e) {
publicTools.OutputLog(e.toString(), "ERROR", 0);
e.printStackTrace();
} catch (IOException e) {
publicTools.OutputLog(e.toString(), "ERROR", 0);
e.printStackTrace();
}
return "upfile/download/" + fileName;
}

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网