Tag: apache poi

如何在读取excel文件时识别单元格为空白或空或空

我读了一个excel文件来传递一些数据字段的input。 但是当我运行程序时,一些单元格值返回为空,有些是空白的。实际上,当我打开Excel文件时,单元格中没有可用的值。 我怎样才能手动确定一个Excel单元格为空或空白。 对于一些场景,我需要将空白值传递给字段。 如果单元格为空,则无法将值传递给字段。 引导我伸出手。 码: public static void readAllData() throws IOException{ Object result = null; String sheetName = "Testsheet"; String filePathxlsx = "C:/Users/MSTEMP/Documents/Files/Testxssf.xlsx"; try { FileInputStream in = new FileInputStream(filePathxlsx); File file = new File(filePathxlsx); if(file.isFile() && file.exists()){ XSSFWorkbook xworkbook = new XSSFWorkbook(in); XSSFSheet xsheet=xworkbook.getSheet(sheetName); int totalRows = xsheet.getLastRowNum(); for(int row =1; row<totalRows;row++){ […]

评估公式并从单元格中删除公式

我想评估公式,并从保持其值的单元格中删除公式。 这怎么可以使用Apache POI完成? 以下是我评估所有公式的代码。 FormulaEvaluator evaluator = template.getCreationHelper().createFormulaEvaluator(); int sheetCount = template.getNumberOfSheets(); for(int sheetIndex = 0; sheetIndex < sheetCount; sheetIndex ++) { sheet = dfaTemplate.getSheetAt(sheetIndex); for (Row r : sheet) { for (Cell c : r) { if (c.getCellType() == Cell.CELL_TYPE_FORMULA) { evaluator.evaluateFormulaCell(c); } } } }

每次只读一行/只有特定的列和创build对象

我使用Apache poi导入我在桌面区域中的.xlsx文件。 通过下面的代码,我可以阅读我想要的孔表。 但是我想每次只读一行,每行只读特定的列(例如,我只想从第一行开始将列A,F和G保存为对象,然后对于第二行,第三行等) 我该怎么做? public class main { public static void main( String[] args ) throws Exception { InputStream ExcelFileToRead = new FileInputStream("C:/User/Desktop/test.xlsx"); XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead); XSSFSheet sheet=wb.getSheetAt(0); XSSFRow row; XSSFCell cell; Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { row=(XSSFRow) rows.next(); Iterator cells = row.cellIterator(); while (cells.hasNext()) { cell=(XSSFCell) cells.next(); if (cell.getCellType() […]

如何获取特定列中使用的行数

我使用getLastRowNum()和getPhysicalNumberOfCells()分别使用的行数和列数,但它没有给出正确的行索引。 int lastRowNum = sheetAt.getLastRowNum(); int lastColNum = sheetAt.getRow(0).getPhysicalNumberOfCells(); 任何其他选项找出相同的?

Excel格式的Java

我正在使用Apache POI JAR在Java中编写excel。 对于下面的代码(从其他网站引用),它使用poi-contrib.jar中的HSSFCellUtil.java类。 这个jar并不是最新版本的poi-3.14.jar。 我在HSSFCellUtil.DATA_FORMAT得到编译时错误。 任何人都可以build议我Excel格式的替代。 HSSFCellUtil.setCellStyleProperty(cell, workbook, HSSFCellUtil.DATA_FORMAT, format.getFormat("($#,##0.00);($#,##0.00)"));

从maven项目资源文件夹(src / main / resources)加载excel(.xlsx / .xls)文件

在这里,我正试图从一个maven项目的资源文件夹(src / main / resources)加载一个excel文件。 文件夹结构 MyWebApp |______src/main/java | |____Test.java | |______src/main/resources | |______test | |___hello.properties | |___template.xlsx |______target |___MyWebApp |____WEB_INF |___classes |__test |__hello.properties |__template.xlsx 我的方法 //loading excel file String resource = "/test/template.xlsx"; System.out.println(this.getClass().getResource(resource) == null); // prints true //loading properties file String resource = "/test/hello.properties"; System.out.println(this.getClass().getResource(resource) == null); //prints false //I have also tried […]

如何从Excel文件单元格使用POI获取数值和string值,我正在获取数值错误,string值很容易获取

目前我正在使用String data= sheet1.getRow(row).getCell(column).getStringCellValue(); 它适用于string值,但显示错误的数值。 所以我不得不在excel中添加像“34567”这样的数字值。 有没有其他的方法来获取数字和string?

如何使用string列表编写Excel文件

我想写一个excel文件。 所有的写作细节都包含一个列表。 并将其设置为该方法的input参数。 请告诉我这样做的最好方法。 public static void writeExcelFile(List<String> combineLists){ XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Employee Data"); | | } input列表:

在Scala或Java中使用Excel语法格式化数字

有谁知道一个基于JVM的格式化库,可以处理Excel风格的数字格式? Apache POI具有DataFormatter但其API适用于处理Excel文档。 我的用例是使用Excel格式规范简单地格式化数字。

JXLS忽略模板样式,我如何强制它保持模板文件中的列宽?

我正在使用JXLS生成使用自定义模板的Excel文件。 该模板只是标准的网格出口模板,除了我已经改变了模板文件中的一些列的宽度。 我的代码大部分只是示例代码的副本。 private void exportAsXLS(List<CalExportItem> exportItems, OutputStream os1) { try (InputStream is = CalDataExporter.class.getClassLoader().getResourceAsStream(TEMPLATE_FILEPATH)) { xlsExporter.registerGridTemplate(is); xlsExporter.gridExport(Arrays.asList(HEADERS), exportItems, FIELDS, os1); } catch (Exception e) { LOGGER.error("Exception exporting as XLS", e); } } 我基本上只是复制了“SimpleExporter”示例 public class CalXlsExportHelper { private static final Logger LOGGER = LoggerFactory.getLogger(CalXlsExportHelper.class); private byte[] templateBytes; public void registerGridTemplate(InputStream inputStream) throws IOException { […]