Java中导出数据到Excel示例—poi
package biz;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.util.Date;
importorg.apache.poi.hssf.usermodel.HSSFCell;
importorg.apache.poi.hssf.usermodel.HSSFCellStyle;
importorg.apache.poi.hssf.usermodel.HSSFDataFormat;
importorg.apache.poi.hssf.usermodel.HSSFRow;
importorg.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;public class Test {
public static void main(String[] args) throws IOException {
HSSFWorkbookwb=newHSSFWorkbook();
HSSFSheetsheet=wb.createSheet("newsheet");
HSSFRowrow=sheet.createRow((short)0);
HSSFCellcell=row.createCell((short)0);
cell.setCellValue(1);
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("test");
row.createCell((short)3).setCellValue(true);
HSSFCellStylecellStyle=wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yyh:mm"));
HSSFCelldCell=row.createCell((short)4);
dCell.setCellValue(newDate());
dCell.setCellStyle(cellStyle);
HSSFCellcsCell=row.createCell((short)5);
csCell.setEncoding(HSSFCell.ENCODING_UTF_16);
csCell.setCellValue("中文测试_ChineseWordsTest");
row.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_ERROR);
//定义文件输出流输出文件
FileOutputStreamfileOut=newFileOutputStream("D:\\workbook.xls");
wb.write(fileOut);
fileOut.close();
}}