Apache-POI操作Excel的一些小技巧
2013-08-20 15:19
393 查看
Apache-POI操作Excel将合并后的单元格全部填充为相同数据的一个实例。
Apache-POI操作Excel获得单元格内容
Apache-POI读取Excel2003和2007/**
private static void fillMergedRegion(final Sheet sheet) { for (int i = 0; i < sheet.getNumMergedRegions(); i++) { int startRow = sheet.getMergedRegion(i).getFirstRow(); int endRow = sheet.getMergedRegion(i).getLastRow(); int startColumn = sheet.getMergedRegion(i).getFirstColumn(); int endColumn = sheet.getMergedRegion(i).getLastColumn(); String value = getStringValue(sheet.getRow(startRow).getCell(startColumn)); for (int row = startRow; row <= endRow; row++) { for (int column = startColumn; column <= endColumn; column++) { sheet.getRow(row).getCell(column).setCellValue(value); } } } }
Apache-POI操作Excel获得单元格内容
public static String getStringValue(Cell cell) { if (cell == null) { return StringConst.EMPTY_STRING; } // get the type of cell, and transform it if (Cell.CELL_TYPE_FORMULA == cell.getCellType()) { switch (cell.getCachedFormulaResultType()) { // if it is mumeric type case Cell.CELL_TYPE_NUMERIC: return new DataFormatter().createFormat(cell).format(cell.getNumericCellValue()); // if it is string type case Cell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return new DataFormatter().formatCellValue(cell); }
Apache-POI读取Excel2003和2007/**
/** * Read the Excel File * * @param file * Excel File * @throws IOException * Error handling */ public DVSExcelReader(File file) throws IOException { InputStream inputStream = null; try { inputStream = new FileInputStream(file); if (file.getName().endsWith(".xls")) { // Excel 2003 this.workbook = new HSSFWorkbook(inputStream); } else if (file.getName().endsWith(".xlsx")) { // Excel 2007 this.workbook = new XSSFWorkbook(inputStream); } else { throw new RuntimeException("Wrong file name defined!"); } } finally { if (inputStream != null) inputStream.close(); } }
相关文章推荐
- Apache-POI操作Excel的一些小技巧
- POI中可能会用到一些需要设置EXCEL单元格格式的操作小结
- 解决 POI 操作2007格式的Excel报错问题:java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlOptionsz
- java用org.apache.poi包操作excel
- POI 操作Excel 异常org.apache.poi.openxml4j.exceptions.invalidformatexception: package should contain a c
- apache POI 对Excel表的操作
- 操作Excel工具类之基于Apache的POI类库
- java用org.apache.poi包操作excel
- Java 使用POI操作EXCEL及测试框架搭建、测试开发的一些想法
- java用org.apache.poi包操作excel
- POI中可能会用到一些需要设置EXCEL单元格格式的操作小结
- java用org.apache.poi包操作excel
- apache POI3.2 java操作excel 设置数据有效性,实现excel单元格列表和提示
- POI中可能会用到一些需要设置EXCEL单元格格式的操作小结
- 操作Excel工具类(基于Apache的POI类库)
- poi操作Excel的一些方法
- POI中可能会用到一些需要设置EXCEL单元格格式的操作小结
- java apache POI操作Excel的一些小技巧
- java 调用 poi(apache的专门读写microsoft office API) 操作Excel
- java 学习之对Excel的操作(Apache-poi 2.10 利用ss)