poi 导入excel源码
来源:互联网 发布:手机网络赚钱资源 编辑:程序博客网 时间:2024/05/01 11:07
package excel;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import means.ShowProduct;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import domain.Product;
public class CreateExcel {
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import means.ShowProduct;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import domain.Product;
public class CreateExcel {
/**
* @author LIANAN
* @param list 给一个查询集合
*
*/
public static void createExcels(List<Product> list){
long t1 = new Date().getTime();HSSFWorkbook workbook=new HSSFWorkbook(); //create a excel fileHSSFSheet sheet = workbook.createSheet(); //create a excel sheetHSSFCellStyle cellstyle = workbook.createCellStyle(); //create a excel stylecellstyle.setFillForegroundColor(HSSFColor.BLUE_GREY.index);// set excel style colorint temp=60000; //一个sheet装6万条数据getRow(sheet, cellstyle); //装入表头HSSFRow row=null;HSSFSheet sheet1=workbook.createSheet();int k=0;for (int i = 0; i < list.size(); i++) {
if(i<=temp){row=sheet.createRow(i+1);}else if(i>temp){getRow(sheet1, cellstyle);row=sheet1.createRow(k++);}row.createCell(0,HSSFCell.CELL_TYPE_NUMERIC).setCellValue(list.get(i).getId());row.createCell(1,HSSFCell.CELL_TYPE_STRING).setCellValue(list.get(i).getKw());row.createCell(2,HSSFCell.CELL_TYPE_NUMERIC).setCellValue(list.get(i).getSta());row.createCell(3,HSSFCell.CELL_TYPE_STRING).setCellValue(list.get(i).getIndate());
}try {
SimpleDateFormat sim=new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");String date=sim.format(new Date());FileOutputStream out = new FileOutputStream("E:/lianan"+date+".xls");workbook.write(out);out.flush();out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}long t2=new Date().getTime();System.out.println(t2-t1);//5S左右时间
}
public static HSSFRow getRow(HSSFSheet sheet,HSSFCellStyle cellstyle){
HSSFRow titleRow=sheet.createRow(0);
titleRow.createCell(0).setCellValue("id");titleRow.createCell(1).setCellValue("kw");titleRow.createCell(2).setCellValue("sta");titleRow.createCell(3).setCellValue("indate");titleRow.setRowStyle(cellstyle);
return titleRow;
}
public static void main(String arg0[]){
createExcels(ShowProduct.showProduct());
}}
- poi 导入excel源码
- excel poi 批量导入源码
- poi 机制 效率最高的 excel 导入Oracle (源码)
- POI导入excel出错
- 使用POI 导入excel
- POI导入Excel
- excel导入(poi)
- poi导入导出excel
- poi excel导入导出
- poi 导入 Excel
- POI实现excel导入
- java poi 导入excel
- 使用poi 导入 excel
- poi导入excel
- POI数据导入Excel
- poi之excel导入
- POI方法导入Excel
- POI导入/导出 EXCEL
- 第16周项目1——小心的放开玩儿字符串
- c# Socket同步发送接收数据
- 设计模式十六(职责链模式,python实现)
- 优秀程序员不得不知道的20个位运算技巧
- centos 163源 更换 --来源于网络
- poi 导入excel源码
- Origin_8.0_crack(origin8.0序列号(origin8.0破解补丁))
- 配置文件当中怎样修改request validation mode
- Linux修改SSH端口和禁止Root远程登陆
- 在WYSIWYG模块中为Drupal 7配置CKEditor 4
- Python Windows Service的方式运行
- hdu4324
- 算两个日期相差天数之使用Calendar类型注意事项
- magento 开发者笔记1