JAVA导出word文档,在循环的时候只写出第一次是为什么?
/**word模板*/FontfontChinese=newFont(bfChinese,12,Font.NORMAL,Color.BLACK);for(inti=0;i...
/*
*word模板
*/
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.BLACK);
for (int i = 0; i < list.size(); i++) {
File_name filename = (File_name) list.get(i);
Cell cell01 = new Cell(new Phrase("过车时间"));
cell01.setColspan(2);//设置当前单元格占据的列数
cell01.setVerticalAlignment(Element.ALIGN_CENTER);
cell01.setHorizontalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell01);
Cell cell02 = new Cell(new Phrase(filename.getRel_filename()));
cell02.setColspan(3);//设置当前单元格占据的列数
cell02.setVerticalAlignment(Element.ALIGN_CENTER);
cell02.setHorizontalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell02);
Cell cell1 = new Cell(new Phrase("车型", fontChinese));
cell1.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell1);
Cell cell2 = new Cell(new Phrase("车号", fontChinese));
cell2.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell2);
Cell cell3 = new Cell(new Phrase("开车时间", fontChinese));
cell3.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell3);
Cell cell4 = new Cell(new Phrase("过车时间", fontChinese));
cell4.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell4);
Cell cell5 = new Cell(new Phrase("车速", fontChinese));
cell5.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell5);
}
document.add(aTable);
document.add(new Paragraph("\n"));
document.close();
}
/*
*方法
*/
public void downloads(String[] dl) {
Download download = new Download();
for (int i = 0; i < dl.length; i++) {
String hql = "from File_name where fileid='" + dl[i] + "'";
List<File_name> list = super.findAllss(hql);
for (File_name file_name : list) {
System.out.println("data=" + file_name.getRel_filename());
super.download(file_name);
}
try {
download.getworddoc("d:/outFile.doc", list);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
查询的条件是前端checkbox传回的fileid,在控制台都能输出,就是在word写入的时候只能写入第一次,求大神帮忙,在线等 展开
*word模板
*/
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.BLACK);
for (int i = 0; i < list.size(); i++) {
File_name filename = (File_name) list.get(i);
Cell cell01 = new Cell(new Phrase("过车时间"));
cell01.setColspan(2);//设置当前单元格占据的列数
cell01.setVerticalAlignment(Element.ALIGN_CENTER);
cell01.setHorizontalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell01);
Cell cell02 = new Cell(new Phrase(filename.getRel_filename()));
cell02.setColspan(3);//设置当前单元格占据的列数
cell02.setVerticalAlignment(Element.ALIGN_CENTER);
cell02.setHorizontalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell02);
Cell cell1 = new Cell(new Phrase("车型", fontChinese));
cell1.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell1);
Cell cell2 = new Cell(new Phrase("车号", fontChinese));
cell2.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell2);
Cell cell3 = new Cell(new Phrase("开车时间", fontChinese));
cell3.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell3);
Cell cell4 = new Cell(new Phrase("过车时间", fontChinese));
cell4.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell4);
Cell cell5 = new Cell(new Phrase("车速", fontChinese));
cell5.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell5);
}
document.add(aTable);
document.add(new Paragraph("\n"));
document.close();
}
/*
*方法
*/
public void downloads(String[] dl) {
Download download = new Download();
for (int i = 0; i < dl.length; i++) {
String hql = "from File_name where fileid='" + dl[i] + "'";
List<File_name> list = super.findAllss(hql);
for (File_name file_name : list) {
System.out.println("data=" + file_name.getRel_filename());
super.download(file_name);
}
try {
download.getworddoc("d:/outFile.doc", list);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
查询的条件是前端checkbox传回的fileid,在控制台都能输出,就是在word写入的时候只能写入第一次,求大神帮忙,在线等 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询