简单的poi导出

@Override
public void exportXlsNotBill(HttpServletResponse response, TSBaseUser user) throws UnsupportedEncodingException {
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("无审批单特殊物品信息");
sheet.setDefaultRowHeightInPoints(20);
sheet.setDefaultColumnWidth((short) 20);
// 第三步,在sheet中添加表头第0行
HSSFRow row = sheet.createRow((int) 0);
// 创建一个居中格式
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 第四步 设置值表头 设置表头
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("上报人姓名 ");
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setCellValue("上报单位单位");
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setCellValue("联系电话 ");
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setCellValue("申请时间");
cell.setCellStyle(style);
cell = row.createCell((short) 4);
cell.setCellValue("出入境方式 ");
cell.setCellStyle(style);
cell = row.createCell((short) 5);
cell.setCellValue("物品类别 ");
cell.setCellStyle(style);
cell = row.createCell((short) 6);
cell.setCellValue("产品名称");
cell.setCellStyle(style);
cell = row.createCell((short) 7);
cell.setCellValue("数量 ");
cell.setCellStyle(style);
cell = row.createCell((short) 8);
cell.setCellValue("重量");
cell.setCellStyle(style);
cell = row.createCell((short) 9);
cell.setCellValue("货值");
cell.setCellStyle(style);
cell = row.createCell((short) 10);
cell.setCellValue("处理方式");
cell.setCellStyle(style);
cell = row.createCell((short) 11);
cell.setCellValue("运输方式");
cell.setCellStyle(style);
cell = row.createCell((short) 12);
cell.setCellValue("备注");
cell.setCellStyle(style);
//第五步 设置数据集
StringBuffer hql = new StringBuffer();
hql.append("from NotBillProductEntity where 1=1 ");
if (ResourceUtil.getSessionUser().getManagerRole()== Manager_Role.SHENGJU_ADMIN) {
hql.append(" and depart like '" + user.getDepartid().substring(0, 2) + "%'");
} else if (ResourceUtil.getSessionUser().getManagerRole() == Manager_Role.FENZHIJU_ADMIN) {
hql.append(" and depart='" + user.getDepartid() + "'");
}

List<NotBillProductEntity> list = findHql(hql.toString());
for (int i = 0; i < list.size(); i++) {
row = sheet.createRow(i + 1);
NotBillProductEntity np = list.get(i);
HSSFCell dataCell = row.createCell((short) 0);
dataCell.setCellValue(np.getCreateUserName());
dataCell = row.createCell((short) 1);
dataCell.setCellValue(np.getCreateCorpId());
dataCell = row.createCell((short) 2);
dataCell.setCellValue(np.getPhone());
dataCell = row.createCell((short) 3);
dataCell.setCellValue(DateUtils.dateToStr(np.getCreateDate(),DateUtils.YYYY_MM_DD));
dataCell = row.createCell((short) 4);
dataCell.setCellValue(np.getExitWay() == 1 ? "入境" : "出境");
dataCell = row.createCell((short) 5);
ProductCategoryEntity pro = getEntity(ProductCategoryEntity.class, np.getPcategory());
dataCell.setCellValue(pro.getName()); //特殊物品类别
dataCell = row.createCell((short) 6);
dataCell.setCellValue(np.getProductName()); //特殊物品类别
dataCell = row.createCell((short) 7);
dataCell.setCellValue(np.getGrossNum() + np.getGrossUnit());
dataCell = row.createCell((short) 8);
dataCell.setCellValue(np.getWeightNum() + np.getWeightUnit());
dataCell = row.createCell((short) 9);
dataCell.setCellValue(np.getValueNum() + "美元USD");
dataCell = row.createCell((short) 10);
String clfs = "其他";
if (np.getDisposeWay() == 1) {
clfs = "截留";
} else if (np.getDisposeWay() == 2) {
clfs = "销毁";
} else if (np.getDisposeWay() == 3) {
clfs = "退运";
}
dataCell.setCellValue(clfs);
dataCell = row.createCell((short) 11);
String ysfs = "货运";
if (np.getTransportWay() == 1) {
clfs = "旅客携带";
} else if (np.getTransportWay() == 2) {
clfs = "邮件";
} else if (np.getTransportWay() == 3) {
clfs = "快件";
}
dataCell.setCellValue(ysfs);
dataCell = row.createCell((short) 12);
dataCell.setCellValue(np.getRemark());
}
// 第六步,将文件存到指定位置
response.setHeader("Content-disposition", "attachment;filename=" + new String(("无审批的特殊物品.xls").getBytes("GBK"), "ISO8859-1"));
try {
wb.write(response.getOutputStream());
response.getOutputStream().close();
} catch (Exception e) {
logger.error("exportXlsNotBill(HttpServletResponse, TSBaseUser)", e); //$NON-NLS-1$
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值