java 导出到excel----POI

package  POI;

import  org.apache.poi.hssf.usermodel.HSSFSheet;
import  org.apache.poi.hssf.usermodel.HSSFRow;
import  org.apache.poi.hssf.usermodel.HSSFCell;
import  org.apache.poi.hssf.usermodel.HSSFWorkbook;

import  java.io.FileNotFoundException;
import  java.io.FileOutputStream;
import  java.text.DecimalFormat;

public   class  ExpExcel  {
    
    
public static void main(String[] args) throws Exception {
        HSSFWorkbook wb
=new HSSFWorkbook();
        HSSFSheet sheet
=wb.createSheet();
        
for(int i=0;i<100;i++){
            HSSFRow row 
=sheet.createRow((short)i);
            HSSFCell cell0
=row.createCell((short)0);
            HSSFCell cell1
=row.createCell((short)1);
            HSSFCell cell2 
=row.createCell((short)2);
            HSSFCell cell3 
=row.createCell((short)3);
            HSSFCell cell4 
=row.createCell((short)4);
            cell0.setCellValue(i
*1);
            cell1.setCellValue(
"test");
            cell2.setEncoding(HSSFCell.ENCODING_UTF_16);
//设置cell编码解决中文高位字节截断
            cell2.setCellType(1);
            cell2.setCellValue(
"你好_hello");//设置中西文结合字符串
            cell3.setCellValue(i*4);
            cell4.setCellValue(i
*5);
        }
    
        
        FileOutputStream fileout 
= new FileOutputStream("c:/workbook.xls");
        wb.write(fileout);
        fileout.close();
        System.out.println(
"export over!");
    }


}

 

你可能感兴趣的:(java 导出到excel----POI)