导出Excel数据:
import java.io.FileOutputStream;
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;
/**
* 数据导出
* Excel表格的一个Sheet只能存储 65536行数据,除去表头只能存储65535行
* @author mt
*
*/
public class ExprotExcel {
public static void main(String[] args){
long begin = System.currentTimeMillis();
Test();
long end = System.currentTimeMillis();
System.out.println("总耗时 : "+(end - begin));
}
private static void Test(){
/* 第一步, 创建一个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 = row.createCell((short) 1);
cell.setCellValue("性别");
cell = row.createCell((short) 2)