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 ... {

publicstaticvoidmain(String[]args)throwsException...{
HSSFWorkbookwb
=newHSSFWorkbook();
HSSFSheetsheet
=wb.createSheet();
for(inti=0;i<100;i++)...{
HSSFRowrow
=sheet.createRow((short)i);
HSSFCellcell0
=row.createCell((short)0);
HSSFCellcell1
=row.createCell((short)1);
HSSFCellcell2
=row.createCell((short)2);
HSSFCellcell3
=row.createCell((short)3);
HSSFCellcell4
=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);
}


FileOutputStreamfileout
=newFileOutputStream("c:/workbook.xls");
wb.write(fileout);
fileout.close();
System.out.println(
"exportover!");
}


}

你可能感兴趣的:(java,apache,C++,c,Excel)