Seam頁面導出Excel
程序员文章站
2024-03-12 20:32:08
...
public void exportData() {
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.responseComplete();
HttpServletResponse response = (HttpServletResponse) ctx
.getExternalContext().getResponse();
response.reset();
response.setContentType("application/vnd.ms-excel");
WritableWorkbook wwb = null;
try {
wwb = Workbook.createWorkbook(response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
if (wwb != null) {
WritableSheet ws = wwb.createSheet("sheet1", 0);
for (int i = 0; i < incomeTaxList.size(); i++) {
try {
ws.addCell(new Label(0, i, incomeTaxList.get(i)
.getSalaryStart().toString()
+ "~"
+ incomeTaxList.get(i).getSalaryEnd().toString()));
ws.addCell(new Label(1, i, incomeTaxList.get(i).getTax0()
.toString()));
ws.addCell(new Label(2, i, incomeTaxList.get(i).getTax1()
.toString()));
ws.addCell(new Label(3, i, incomeTaxList.get(i).getTax2()
.toString()));
ws.addCell(new Label(4, i, incomeTaxList.get(i).getTax3()
.toString()));
ws.addCell(new Label(5, i, incomeTaxList.get(i).getTax4()
.toString()));
ws.addCell(new Label(6, i, incomeTaxList.get(i).getTax5()
.toString()));
ws.addCell(new Label(7, i, incomeTaxList.get(i).getTax6()
.toString()));
ws.addCell(new Label(8, i, incomeTaxList.get(i).getTax7()
.toString()));
ws.addCell(new Label(9, i, incomeTaxList.get(i).getTax8()
.toString()));
ws.addCell(new Label(10, i, incomeTaxList.get(i).getTax9()
.toString()));
ws.addCell(new Label(11, i, incomeTaxList.get(i).getTax10()
.toString()));
ws.addCell(new Label(12, i, incomeTaxList.get(i).getTax11()
.toString()));
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
wwb.write();
wwb.close();
} catch (IOException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
}
}
Java操作Excel:http://www.iteye.com/topic/55844
上一篇: hive中判断A表时间字段是否在B表的两个时间字段中
下一篇: lombok使用及常用注解