PoI帮助文档

时间:2016-08-09 16:39:29
【文件属性】:
文件名称:PoI帮助文档
文件大小:1.24MB
文件格式:ZIP
更新时间:2016-08-09 16:39:29
PoI 1.创建工作簿 (WORKBOOK)    HSSFWorkbook wb = new HSSFWorkbook();    FileOutputStream fileOut = new FileOutputStream("workbook.xls");    wb.write(fileOut);    fileOut.close();2.创建工作表(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();3.创建单元格(CELL)    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();4.创建指定单元格式的单元格    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();5. 单元格的不同格式    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();6.单元格的不通对齐方式    public static void main(String[] args)            throws IOException    {        HSSFWorkbook wb = new HSSFWorkbook();        HSSFSheet sheet = wb.createSheet("new sheet");        HSSFRow row = sheet.createRow((short) 2);        createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER);        createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);        createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL);        createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL);        createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY);        createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT);        createCell(wb, row, (short) 6, HSSFCellStyle.ALIGN_RIGHT);        // Write the output to a file        FileOutputStream fileOut = new FileOutputStream("workbook.xls");        wb.write(fileOut);        fileOut.close();    }    /**
【文件预览】:
PoI帮助文档
----POI帮助文档.doc(54KB)
----POI整理.doc(2.27MB)

网友评论

  • 很不多,讲的很详细