POI导出excel典型代码
来源:互联网 发布:如何关闭电脑端口 编辑:程序博客网 时间:2024/06/05 17:13
记录一下,以后备用:
一:代码
//创建excel表格对象
XSSFWorkbook xs=new XSSFWorkbook();
XSSFSheet sheet=xs.createSheet(excelTitle);
XSSFRow row=sheet.createRow((short)0);//数据展示行对象创建
sheet.createFreezePane( 0, 1, 0, 1 );//冻结窗口 需优化 根据需求可改
//数据展示行填充标题
String display = "";
for(int i = 0;i<displayInfo.size();i++){
display = displayInfo.get(i);
row.createCell((short)i).setCellValue(display);
}
String rowDatekey = "";
//数据展示
for(int i = 0;i<list.size();i++){
XSSFRow rowdata=sheet.createRow((short)(i+1));
Map map =list.get(i);
for(int y = 0;y<rowDataKeys.size();y++){
rowDatekey = rowDataKeys.get(y);
rowdata.createCell((short)y).setCellValue(map.get(rowDatekey)==null?"":map.get(rowDatekey).toString());
}
}
long t2=new Date().getTime();
System.out.println("写入excel共耗时:"+(t2-t1));
//以下为excel导出部分
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HHmmss");//设置日期格式
String dowmFileRight = df.format(new Date());
response.reset();
response.setContentType("application/x-download;charset=GBK");
String downFileName = excelTitle + dowmFileRight+ ".xlsx";
response.setHeader("content-disposition", "attachment;filename="+URLEncoder.encode(downFileName, "UTF-8"));
OutputStream out=response.getOutputStream();
xs.write(out);
out.flush();
out.close();
二:对冻结行的解释
Excel冻结行/列释义:
在Excel中,有时可能会出现列数太多或是行数太多的情况,
这时可以通过锁定列来冻结部分列,不随滚动条滑动,方便查看。
//示例代码:
HSSFSheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
HSSFRow row1 = sheet1.CreateRow(0);
row1.CreateCell(0).SetCellValue("冻结列");
sheet1.CreateFreezePane(1, 0, 1, 0);
//参数说明:
第一个参数表示要冻结的列数;
第二个参数表示要冻结的行数,这里只冻结列所以为0;
第三个参数表示右边区域可见的首列序号,从1开始计算;
第四个参数表示下边区域可见的首行序号,也是从1开始计算,这里是冻结列,所以为0;
- POI导出excel典型代码
- poi导出excel代码
- POI导出Excel代码片段
- POI Excel导出,模板导出,代码解析
- java poi 导出excel 部分代码
- 使用poi操作导出excel代码示例
- struts2 poi导出excel实例代码下载
- 使用poi操作导出excel代码示例
- poi导出excel后台代码示例
- java poi 导出excel表格 代码
- Excel POI导出excel
- POI-----POI导出Excel实例
- jsp导出excel poi
- POI导出EXCEL
- poi导出Excel
- poi导出excel
- POI 导出excel
- POI 导出excel
- eclipse启动出现“An Error has Occurred. See the log file”解决方法
- MD5加密
- 软件开发的11种模式
- Catalan数计算及应用
- MySQL中竖表和横表之间的相互转换
- POI导出excel典型代码
- java的关键字和保留字
- 位图BitMap与布隆过滤器BloomFilter
- maven学习系列8----将resources目录下的文件打包到jar包外
- Commons DbUtils入门教程(CRUD)
- UDC (usb device controller) Framework - USB gadget driver framework
- Linux下使用原始套接字实现ping命令
- 移动支付的小demo,做个备份的备份,
- redis基本命令:二