poi 导出excel

1.poi.jar 包

2.代码:

              // 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("设备信息列表");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
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);

productAssets.setDeviceType(java.net.URLDecoder.decode(productAssets.getDeviceType(), "UTF-8"));
productAssets.setSerialNumber(java.net.URLDecoder.decode(productAssets.getSerialNumber(), "UTF-8"));
productAssets.setFixedaAssetsNumber(java.net.URLDecoder.decode(productAssets.getFixedaAssetsNumber(), "UTF-8"));
productAssets.setStatus(java.net.URLDecoder.decode(productAssets.getStatus(), "UTF-8"));
productAssets.setCurrentDepartments(java.net.URLDecoder.decode(productAssets.getCurrentDepartments(), "UTF-8"));

productAssetsList = productAssetDAO.findProductAssetsList(productAssets,null);


// 第五步,写入实体数据 实际应用中这些数据从数据库得到,
if(productAssetsList !=null && productAssetsList.size()>0)
{

for (int i = 0; i < productAssetsList.size(); i++)
{
row = sheet.createRow((int) i + 1);
ProductAssets proAsset = (ProductAssets) productAssetsList.get(i);
// 第四步,创建单元格,并设置值
row.createCell((short)0).setCellValue(proAsset.getBrands());
row.createCell((short)1).setCellValue(proAsset.getModel());
row.createCell((short)2).setCellValue(proAsset.getSerialNumber());
row.createCell((short)3).setCellValue(proAsset.getDeviceType());
row.createCell((short)4).setCellValue(proAsset.getAccountingDate());
row.createCell((short)5).setCellValue(proAsset.getCurrentDepartments());
row.createCell((short)6).setCellValue(proAsset.getSourceWhere());
String st=null;
if(proAsset.getStatus().equals("0")){st="正常";}else{st="维修";}
row.createCell((short)7).setCellValue(st);
}
// 第六步,将文件存到指定位置
try
{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String fileName = "设备信息列表"+sdf.format(new Date())+".xls";   
       fileName = new String(fileName.getBytes("GBK"),"iso8859-1");   
       response.reset();   
       response.setHeader("Content-Disposition","attachment;filename="+fileName);//指定下载的文件名   
       response.setContentType("application/vnd.ms-excel");   
       response.setHeader("Pragma", "no-cache");   
       response.setHeader("Cache-Control", "no-cache");   
       response.setDateHeader("Expires", 0);   
       OutputStream output = response.getOutputStream();   
       BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);   
       bufferedOutPut.flush();   
       wb.write(bufferedOutPut);   
       bufferedOutPut.close();   
   }
catch (Exception e)
{
e.printStackTrace();
}


}
productAssetsList.clear();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园建设方案旨在通过信息化手段提升教育、管理和服务水平,实现资源数字化、工作流程化、管理高效化和决策智能化。方案包括智慧校园信息化平台和安防平台的建设,涉及教学、科研、管理和服务等多个方面,以满足现代教育和培训需求。 技术服务要求强调了统一支撑平台的建设,包括数据标准、接口标准、代码标准和用户信息标准的统一制定。平台需满足信创和X86交叉适配要求,确保安全自主可控的系统开发环境。此外,方案还涵盖了用户中心系统、统一认证授权中心、统一工作流中心、统一智能报表中心等多个模块,以及数据共享中心、语音识别、移动服务终端等功能,以实现校园内外部信息的互联互通和资源共享。 智慧校园信息化平台的建设还包括了对教学管理、人事管理、公文管理、档案管理、即时通讯、会议管理、督办工作、资产管理等方面的数字化和自动化升级。这些模块的集成旨在提高工作效率,优化资源配置,加强监督管理,并通过移动应用等技术手段,实现随时随地的信息访问和业务处理。 安防平台的建设则侧重于校园安全,包括停车场管理、人脸识别测温、访客自助登记、视频监控等多个系统。这些系统的集成旨在提高校园的安全管理水平,实现对校园内外人员和车辆的有效监控和管理,确保校园环境的安全稳定。 最后,方案还提到了对固定资产的管理,包括购置、使用、归还、报废等全生命周期的管理,以及对网络设备、安防设备、服务器等硬件设施的配置和管理。通过这些措施,智慧校园建设方案旨在为校园提供一个安全、高效、便捷的学习和工作环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值