Tag: excel

使用Apache POI创建.xlsx文件时的java.lang.NoClassDefFoundError

我正在尝试使用Apache POI创建.xlsx文件。 这是我的代码: FileOutputStream outputStream1=null; XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(“data”); try { target.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { outputStream1 = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+”/file_A/”+”test_Ab”+”.xlsx”); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int i=0;i<iteration;i++) { XSSFRow row = sheet.createRow(i); Cell […]

编写XSSFWorkbook时,使用JDBC在Spring Boot应用程序中创建损坏的.xlsx文档

对于项目,我需要创建一个.xlsm excel文档,自动填写模板文件。 问题是,输出已损坏,Excel 365和Apache POI都无法读取。 我把它提炼到下面的最小例子,它可以在main方法中运行。 为了完全安全,它使用.xlsx格式。 public static void main(String[] args) { XSSFWorkbook document = new XSSFWorkbook(); XSSFSheet spreadsheet = document.createSheet(“Test”); spreadsheet.createRow(0).createCell(0).setCellValue(“Testie test”); // Output .xlsx file FileOutputStream stream; try { stream = new FileOutputStream(“test_output.xlsx”); document.write(stream); stream.flush(); stream.close(); } catch (IOException e) { System.err.println(“Error” + e.getMessage()); e.printStackTrace(); } … 创建的文件test_output.xlsx无法由Excel 365打开并且大小仅为4kb,而手动创建的文件将占用9kb,因此输出中必须缺少某些我未指定的内容? 我正在使用通过Gradle导入的Apache POI版本3.17 compile(‘org.apache.poi:poi-ooxml:3.17’) […]

如何使用Apache POI从Excel获取货币代码?

我正在使用POI来解析Excel文件和reg。 用于检测NumericCellValue货币的NumericCellValue 。 我在Excel文件中有2个字段,有2种不同的货币(100美元和100欧元),我需要获取他们的货币代码(“USD”,“EUR”)。 case Cell.CELL_TYPE_NUMERIC: { Pattern p = Pattern.compile(currencyFilter); Matcher m = p.matcher(dataFormat); if (m.find()) { BigDecimal aCurrency = currentCell.getNumericCellValue(); //I need to pass my currency code from cell field to money instance Money money = new Money(aCurrency, “USD”); } }

在应用PropertyTemplate边框时,Apache POI使用黑色而不是所需的自定义颜色填充XSSF单元格

我正在编写一个程序,该程序应该制作一个Excel电子表格,其中包含一些填充橙色的单元格,给定文本,并使用PropertyTemplate给出边框。 我已成功编写代码在HSSF中执行此操作,但我现在正在研究XSSF并且无法使其工作。 发生的事情是细胞充满了正确的橙色,文本也正确地进入细胞,但应用PropertyTemplate会使橙色细胞变黑。 有没有人知道这方面的方法? 这是我的代码。 XSSFCellStyle orangeFillStyle = wb.createCellStyle(); orangeFillStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 192, 0))); orangeFillStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); 然后有一大堆代码/算法来确定哪些单元格填充橙色以及哪些单元格放入文本。我使用代码突出显示单元格: currCell.setCellStyle(orangeFillStyle); 在工作表创建的最后是PropertyTemplate (border)代码: BorderStyle dividerStyle = BorderStyle.THIN; PropertyTemplate borderTemplate = new PropertyTemplate(); borderTemplate.drawBorders(new CellRangeAddress(0, 0, 0, 13), dividerStyle, BorderExtent.BOTTOM); borderTemplate.drawBorders(new CellRangeAddress(0, 0, 1, 13), dividerStyle, BorderExtent.TOP); borderTemplate.drawBorders(new CellRangeAddress(0, rowI, 1, 13), dividerStyle, BorderExtent.VERTICAL); borderTemplate.drawBorders(new CellRangeAddress(rowI, rowI, 0, 13), dividerStyle, […]

如何使用JXL API写入SAME excel表?

我有一个excel表(位于类路径中),其中包含要读取和执行的方案。 一旦它们被执行,我应该回写给SAME excel表,说明该场景是通过还是失败 。 如何实现这一目标? ( 注意:我能阅读excel)。

使用Apache POI 4.0运行官方示例LineChars和ScatterChart时出现问题

Apache POI 4.0的官方示例LineChart和ScatterChart存在问题。 它们编译运行没有错误,但无法打开创建的Excel文件,说明存在不可读的内容。 Excel 2010和2016提供了从工作簿中恢复数据的选项,单击“是”后,将显示此对话框 。 可能是什么问题?

使用apache poi使列只读

我正在使用apache-poi生成excel文件。 我需要将第4列设为只读,其余2列将由用户编辑。 我正在使用XSSFCellStyle实现这一点,但它不适合我。 整个代码是: Map styles = new HashMap(); XSSFCellStyle style5 = wb.createCellStyle(); XSSFFont headerFont = wb.createFont(); headerFont.setBold(true); style5.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style5.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style5.setFont(headerFont); style5.setLocked(true); // this line does not get executed. styles.put(“header”, style5);

Excel单元格样式问题

我使用下面的代码从XLSX文件中获取日期值。 对于某些xlsx文件,这是完全正常的。 但它没有给出xlsx文件中的确切日期格式。 此问题适用于某些文件。 例如; 我有这样的日期21/01/2016 (dd/mm/yyyy)但阅读后,它给出的日期为01/21/16(mm/dd/yy) 有没有其他方法可以获得cellstyle? 是xlsx文件的问题?? String dateFmt = cell.getCellStyle().getDataFormatString(); if (DateUtil.isCellDateFormatted(cell)) { double val = cell.getNumericCellValue(); Date date = DateUtil.getJavaDate(val); String dateFmt = cell.getCellStyle().getDataFormatString(); System.out.println(“dateFmt “+dateFmt); value = new CellDateFormatter(dateFmt).format(date); System.out.println(“Date “+value); }