导出excel

<%@page import="java.util.*"%>
<jsp:directive.page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"/>
<jsp:directive.page import="org.apache.poi.hssf.usermodel.HSSFSheet"/>
<jsp:directive.page import="org.apache.poi.hssf.usermodel.HSSFRow"/>
<jsp:directive.page import="org.apache.poi.hssf.usermodel.HSSFCell"/>
<jsp:directive.page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"/>
<jsp:directive.page import="org.apache.poi.hssf.util.HSSFColor"/>
<jsp:directive.page import="org.apache.poi.hssf.usermodel.HSSFFont"/>

<%
try
{
List list = (List)request.getAttribute("list");
if(list == null) list = new ArrayList();

response.reset();
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setCharacterEncoding("GBK");
response.setHeader("Content-Disposition","attachment;filename=\"Export.xls\"");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("HWM_HJ");
HSSFCellStyle style = wb.createCellStyle();
HSSFFont ft = wb.createFont();
ft.setColor(HSSFColor.RED.index);
style.setFont(ft);
HSSFRow headerRow = sheet.createRow(0);
HSSFCell headerCell0 = headerRow.createCell((short)0);
headerCell0.setCellValue("Item");
HSSFCell headerCell1 = headerRow.createCell((short)1);
headerCell1.setCellValue("PartNo");
HSSFCell headerCell2 = headerRow.createCell((short)2);
headerCell2.setCellValue("HWM date");
HSSFCell headerCell3 = headerRow.createCell((short)3);
headerCell3.setCellValue("HWM");
HSSFCell headerCell4 = headerRow.createCell((short)4);
headerCell4.setCellValue("Shipped Qty");
HSSFCell headerCell5 = headerRow.createCell((short)5);
headerCell5.setCellValue("Gross use");
HSSFCell headerCell6 = headerRow.createCell((short)6);
headerCell6.setCellValue("Liability");
if(list!=null && list.size()>0){
for(int i=0;i<list.size();i++){
HWMHJ obj = (HWMHJ)list.get(i);

HSSFRow lineRow = sheet.createRow(i+1);
HSSFCell lineCell0 = lineRow.createCell((short)0);
lineCell0.setCellValue(obj.getItem());
HSSFCell lineCell1 = lineRow.createCell((short)1);
lineCell1.setCellValue(obj.getPartNo());
HSSFCell lineCell2 = lineRow.createCell((short)2);
lineCell2.setCellValue(obj.getHwmName());
HSSFCell lineCell3 = lineRow.createCell((short)3);
lineCell3.setCellValue(obj.getHwmQty());
HSSFCell lineCell4 = lineRow.createCell((short)4);
lineCell4.setCellValue(obj.getShippedQty());
HSSFCell lineCell5 = lineRow.createCell((short)5);
lineCell5.setCellValue(obj.getGrossUse());
HSSFCell lineCell9 = lineRow.createCell((short)6);
lineCell9.setCellValue(obj.getLiability());
}
}
wb.write(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();

}catch(Exception e)
{
e.printStackTrace();
throw new HSException("Export xls error!" + e.getMessage());
}
%>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值