导出 excel
来源:互联网 发布:黄岛宏智软件 编辑:程序博客网 时间:2024/05/18 00:41
// 导出成Excel
public void exproEXCEL(List<CmwMaintenceBill> ls){
//第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
//第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("正式上海MIS维护单");
//第三步,在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("维护单ID"); cell.setCellStyle(style);
cell = row.createCell((short)1);
cell.setCellValue("维护单号"); cell.setCellStyle(style);
cell = row.createCell((short)2);
cell.setCellValue("创建时间"); cell.setCellStyle(style);
System.out.println("---ls.size()----"+ls.size());
//第五步,写入实体数据 实际应用中这些数据从数据库得到,
for(int i=0;i<ls.size();i++){
row = sheet.createRow((int)i+1);
CmwMaintenceBill cm = (CmwMaintenceBill) ls.get(i);
//第四步,创建单元格,并设置值
// System.out.println("维护单ID --"+cm.getId()+"--维护单号--"+cm.getMbillNo());
java.text.DateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s1=df.format(cm.getUpdateTime());
row.createCell((short)0).setCellValue((double)cm.getId());
row.createCell((short)1).setCellValue(cm.getMbillNo());
row.createCell((short)2).setCellValue(s1);
}
//第六步,将文件存到指定位置
try {
FileOutputStream fout = new FileOutputStream("d:/shmis.xls");
wb.write(fout);
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
//return information;
}
public void exproEXCEL(List<CmwMaintenceBill> ls){
//第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
//第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("正式上海MIS维护单");
//第三步,在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("维护单ID"); cell.setCellStyle(style);
cell = row.createCell((short)1);
cell.setCellValue("维护单号"); cell.setCellStyle(style);
cell = row.createCell((short)2);
cell.setCellValue("创建时间"); cell.setCellStyle(style);
System.out.println("---ls.size()----"+ls.size());
//第五步,写入实体数据 实际应用中这些数据从数据库得到,
for(int i=0;i<ls.size();i++){
row = sheet.createRow((int)i+1);
CmwMaintenceBill cm = (CmwMaintenceBill) ls.get(i);
//第四步,创建单元格,并设置值
// System.out.println("维护单ID --"+cm.getId()+"--维护单号--"+cm.getMbillNo());
java.text.DateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s1=df.format(cm.getUpdateTime());
row.createCell((short)0).setCellValue((double)cm.getId());
row.createCell((short)1).setCellValue(cm.getMbillNo());
row.createCell((short)2).setCellValue(s1);
}
//第六步,将文件存到指定位置
try {
FileOutputStream fout = new FileOutputStream("d:/shmis.xls");
wb.write(fout);
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
//return information;
}
- 导出EXCEL
- Excel导出
- 导出Excel
- 导出EXCEL
- 导出Excel
- EXCEL导出
- 导出Excel
- 导出excel
- 导出excel
- EXCEL导出
- 导出excel
- 导出Excel
- Excel导出。
- 导出excel
- Excel 导出
- 导出excel
- 导出excel
- 导出excel
- S5PV210 -- UBOOT启动过程解析(TINY210)
- Ajax!
- MySQL5.5.24编译安装
- 如何在 SQL 2008 安裝 Performance Dashboard Reports
- upx最新壳脱壳测试
- 导出 excel
- magento相关
- 【转】MiniGUI 1.3.3 移植详解 作者:大漠孤狼
- windows 创建线程和线程同步
- 黑客专家教你如何设计不易破解的密码
- Django Model Object Serialize By SpitEat
- google-Gson
- 在和同事调protobuf接口的时候,看下ruby,记录下。
- ARM、DSP、FPGA的区别