发布网友 发布时间:2022-04-23 19:46
共2个回答
懂视网 时间:2022-04-21 03:49
请大家帮个忙啊为什么非要在jsp上写java代码,很麻烦的。一般的做法是把取数据的条件提交到后台,然后从数据库里重新取一边,用POI操作Excel,生出完了,再导出来。
这事情应该交给数据库做
热心网友 时间:2022-04-21 00:57
public static void crExcel(List list, String absoluteFileString)
throws Exception {
// 字体格式
WritableFont wfc0 = new WritableFont(WritableFont.ARIAL, 22,WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
WritableCellFormat wcfFC0 = new WritableCellFormat(wfc0);
wcfFC0.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC0.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
wcfFC0.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.GRAY_25);
// 表头字体
WritableFont wfc8 = new WritableFont(WritableFont.ARIAL, 12,WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
WritableCellFormat wcfFC8 = new WritableCellFormat(wfc8);
wcfFC8.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC8.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
wcfFC8.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.GRAY_25);
WritableFont wfc1 = new WritableFont(WritableFont.ARIAL, 10,WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
WritableCellFormat wcfFC1 = new WritableCellFormat(wfc1);
wcfFC1.setAlignment(jxl.format.Alignment.CENTRE);
wcfFC1.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.GRAY_25);
// 创建excel
OutputStream os = new FileOutputStream(absoluteFileString);
String readPath = I18nMessages.getText("efine.excel.dir");
InputStream input = new FileInputStream(readPath
+ "FKBalanceReport.xls");
Workbook workbook = Workbook.getWorkbook(input);
WritableWorkbook book = Workbook.createWorkbook(os, workbook);
WritableSheet sheet = book.getSheet(0);
// 数据写入
Label label = null;
// Title
//label = new jxl.write.Label(3, 0, "到期付款信息表", wcfFC0);
//sheet.addCell(label);
/*
* label = new jxl.write.Label(0, 3, "备注", wcfFC4);
* sheet.addCell(label);
*/
label = new jxl.write.Label(0, 0, "到期日", wcfFC8);
sheet.addCell(label);
label = new jxl.write.Label(1, 0, "部门名称", wcfFC8);
sheet.addCell(label);
label = new jxl.write.Label(2, 0, "币种", wcfFC8);
sheet.addCell(label);
label = new jxl.write.Label(3, 0, "银行", wcfFC8);
sheet.addCell(label);
label = new jxl.write.Label(4, 0, "金额", wcfFC8);
sheet.addCell(label);
label = new jxl.write.Label(5, 0, "业务类型", wcfFC8);
sheet.addCell(label);
label = new jxl.write.Label(6, 0, "摘要", wcfFC8);
sheet.addCell(label);
sheet.setName("到期付款信息查询");
int j = 1;
for (int i = 0; i <list.size(); i++) {
DNCM02 dto = (DNCM02) list.get(i);
label = new Label(0, i + j, CommonUtil.dateToStr(dto.getEndDay()),
wcfFC1);
sheet.addCell(label);
label = new Label(1, i + j, dto.getEndDeptName(), wcfFC1);
sheet.addCell(label);
label = new Label(2, i + j, dto.getCurrencyName(), wcfFC1);
sheet.addCell(label);
label = new Label(3, i + j, dto.getEndBankName(), wcfFC1);
sheet.addCell(label);
label = new Label(4, i + j, CommonUtil.formatString(dto
.getEndAmount().toString()), wcfFC1);
sheet.addCell(label);
label = new Label(5, i + j, dto.getEndTypeName(), wcfFC1);
sheet.addCell(label);
label = new Label(6, i + j, dto.getRemark(), wcfFC1);
sheet.addCell(label);
}
book.write();
book.close();
os.close();
}
先看看 不会再说 参数 list 是你查询结果,另一个是excel路径