POI写Excel

import java.io.FileOutputStream;
import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
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.ss.util.Region;
public class ExcelWrite {
	
	public static void main(String[]args) throws Exception{
		HSSFWorkbook hssfworkbook = new HSSFWorkbook();
        HSSFSheet    hssfsheet    = hssfworkbook.createSheet("哈哈中文咯");
        hssfsheet.addMergedRegion(new Region(0,(short)0,0,(short) 10));
        HSSFRow      hssfrow0      = hssfsheet.createRow(0); 
        HSSFCell     hssfcell0     = hssfrow0.createCell((short)0);
        hssfcell0.setCellValue("Test Report");
        
        HSSFRow      hssfrow      = hssfsheet.createRow(1); 
        HSSFCell     hssfcell     = hssfrow.createCell((short)0);
        // hssfcell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
        hssfcell.setCellValue("哈哈也是中文咯");
        HSSFCellStyle hssfcellstyle = hssfworkbook.createCellStyle();
        hssfcellstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
       
        HSSFCell celldate = hssfrow.createCell((short)1);
        celldate.setCellValue(new Date());
        celldate.setCellStyle(hssfcellstyle);
        hssfrow.createCell((short)2).setCellValue(false);
        hssfrow.createCell((short)3).setCellValue(12.00);
        FileOutputStream fileoutputstream = new FileOutputStream("d:\\exceltext.xls");
        hssfworkbook.write(fileoutputstream);
        fileoutputstream.close();
	}

}

你可能感兴趣的:(apache,Excel)