poi api poi 入门 poi 代码 poi 实例

http://poi.apache.org/spreadsheet/quick-guide.html 官方文档是最好的。。很简洁、很强大。

api http://d.download.csdn.net/down/1933917/cyc_uf

这里更多

http://search.download.csdn.net/search/api%20chm

New Workbook

    HSSFWorkbook wb = new HSSFWorkbook();

    FileOutputStream fileOut = new FileOutputStream("workbook.xls");

    wb.write(fileOut);

    fileOut.close();

                   

New Sheet

    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFSheet sheet1 = wb.createSheet("new sheet");

    HSSFSheet sheet2 = wb.createSheet("second sheet");

    FileOutputStream fileOut = new FileOutputStream("workbook.xls");

    wb.write(fileOut);

    fileOut.close();

                   

Creating Cells

    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFSheet sheet = wb.createSheet("new sheet");

    // Create a row and put some cells in it. Rows are 0 based.

    HSSFRow row = sheet.createRow((short)0);

    // Create a cell and put a value in it.

    HSSFCell cell = row.createCell((short)0);

    cell.setCellValue(1);

    // Or do it on one line.

    row.createCell((short)1).setCellValue(1.2);

    row.createCell((short)2).setCellValue("This is a string");

    row.createCell((short)3).setCellValue(true);

    // Write the output to a file

  FileOutputStream fileOut = new FileOutputStream("workbook.xls");

    wb.write(fileOut);

    fileOut.close();

                   

Creating Date Cells

    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFSheet sheet = wb.createSheet("new sheet");

    // Create a row and put some cells in it. Rows are 0 based.

    HSSFRow row = sheet.createRow((short)0);

    // Create a cell and put a date value in it. The first cell is not styled

    // as a date.

    HSSFCell cell = row.createCell((short)0);

    cell.setCellValue(new Date());

    // we style the second cell as a date (and time). It is important to

    // create a new cell style from the workbook otherwise you can end up

    // modifying the built in style and effecting not only this cell but other cells.

    HSSFCellStyle cellStyle = wb.createCellStyle();

    cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));

    cell = row.createCell((short)1);

    cell.setCellValue(new Date());

    cell.setCellStyle(cellStyle);

    // Write the output to a file

    FileOutputStream fileOut = new FileOutputStream("workbook.xls");

    wb.write(fileOut);

    fileOut.close();

                   

Working with different types of cells

    HSSFWorkbook wb = new HSSFWorkbook();

    HSSFSheet sheet = wb.createSheet("new sheet");

    HSSFRow row = sheet.createRow((short)2);

    row.createCell((short) 0).setCellValue(1.1);

    row.createCell((short) 1).setCellValue(new Date());

    row.createCell((short) 2).setCellValue("a string");

    row.createCell((short) 3).setCellValue(true);

    row.createCell((short) 4).setCellType(HSSFCell.CELL_TYPE_ERROR);

    // Write the output to a file

    FileOutputStream fileOut = new FileOutputStream("workbook.xls");

    wb.write(fileOut);

    fileOut.close();

                    

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>