Tag: apache poi

使用java POI插入表时,打开的办公室编写器崩溃了

我正在尝试使用开放式办公室以.docx格式使用apache-poi插入表。但是每次打开文件时文件都会崩溃 XWPFDocument document= new XWPFDocument(); FileOutputStream out = new FileOutputStream(new File(“C://create_table.docx”)); //create table XWPFTable table = document.createTable(); //create first row XWPFTableRow tableRowOne = table.getRow(0); tableRowOne.getCell(0).setText(“col one, row one”); tableRowOne.addNewTableCell().setText(“col two, row one”); tableRowOne.addNewTableCell().setText(“col three, row one”); //create second row XWPFTableRow tableRowTwo = table.createRow(); tableRowTwo.getCell(0).setText(“col one, row two”); tableRowTwo.getCell(1).setText(“col two, row two”); tableRowTwo.getCell(2).setText(“col three, row two”); […]

Apache Poi:获取DOC文档中的页数

如何使用Apache Poi获取DOC文档中的页数? 我尝试使用以下代码: HWPFDocument wordDoc = new HWPFDocument(new FileInputStream(lowerFilePath)); Integer pageCount = wordDoc.getSummaryInformation().getPageCount(); 但得到例外(Apache Poi版本:3.13) java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.toByteArray(Ljava/io/InputStream;I)[B at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:95) at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:174)

在java中使用apache事件模型解析excel文件时,如何检查字符串中的数字包含日期和指数

我正在解析一个excel文件,其中包含许多日期,如13-4-2021和一些数字,这3,7%,2,65%格式。所以我正在解析那个excel文件,我得到一个字符串中的数据写他们在一个文本文件中。所以我的问题是我得到了一个像44299这样的整数的日期,而它实际上是在excel工作表中的04/13/2021格式。另一个案例是我有一些像百分比一样的数字3,7%,2,65%即将到来,如3.6999999999999998E-2。所以我可以将数字转换成日期使用 SimpleDateFormat(“MM/dd/yyyy”).format(javaDate) 这是我正在使用的代码 private static class SheetHandler extends DefaultHandler { private SharedStringsTable sst; private String lastContents; private boolean nextIsString; private int rowNumber; private SheetHandler(SharedStringsTable sst) { this.sst = sst; } public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { try { // row => row if(name.equals(“row”)) { if (attributes.getValue(“r”) != null) […]

在java中读取.docx文件

我试图在java中读取一个文件,以下是代码: public void readFile(String fileName){ try { BufferedReader reader= new BufferedReader(new FileReader(fileName)); String line=null; while((line=reader.readLine()) != null ){ System.out.println(line); } }catch (Exception ex){} } 在txt文件的情况下工作正常。 但是在docx文件的情况下,它正在打印奇怪的字符。 我怎样才能在Java中读取.docx文件。

无法使用ApachePOI打开Excel – 获取exception

在尝试使用ApachePOI打开excel时,我得到了 org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can’t open the specified file: ‘C:\Users\mdwaipay\AppData\Local\Temp\poifiles\poi-ooxml-1570030023.tmp’ 我检查了。 没有创建此类文件夹。 我正在使用Apache POI版本3.6。 有帮助吗? 类似的代码在不同的工作区中运行良好。 在这里失去了思想。 码: public Xls_Reader(String path) { this.path=path; try { fis = new FileInputStream(path); workbook = new XSSFWorkbook(fis); sheet = workbook.getSheetAt(0); fis.close(); } catch (Exception e) { e.printStackTrace(); } }

使用Apache POI XSLF在指定位置的单张幻灯片中附加3张图像

我需要使用Apache POI XSLF在单张幻灯片中粘贴3张图片。 但是,我只能在幻灯片中添加一张图片。 此外,我找不到任何方法来指定图片的大小和方向。 试过以下代码 XMLSlideShow ppt = new XMLSlideShow(); XSLFSlide slide = ppt.createSlide(); XSLFGroupShape group1 = slide.createGroup(); byte buf[] = new byte[1024]; for (int i = 1; i <= 2; i++) { byte[] pictureData = IOUtils.toByteArray(new FileInputStream( "C:\\Users\\Ashok\\Pictures\\" + i + ".png")); int elementIndex = ppt.addPicture(pictureData, XSLFPictureData.PICTURE_TYPE_PNG); XSLFPictureShape picture = slide.createPicture(elementIndex); List allPictures […]

如何从excel表中选择复选框值

我正在处理一个与阅读excel相关的任务,其中包含单选按钮和使用Java的复选框,我已经尝试了很多但是无法继续进行此操作,当我尝试读取包含Checkbox的单元格的数据时它返回了空值。 有人可以帮忙解决这个问题。

在XSSFRichTextString中忽略新行

:编辑开始: 如果有人偶然发现这个问题,那么这里有一个小问题。 获取newLines后,我想设置行高以匹配内容。 为此,我只需将行高设置为cellValue中newLines的数量。 但是,当使用poi创建电子表格时,如果在cellValue之前或之后应用cellStyle似乎很重要。 在我的情况下,它只有在我添加cellValue 之前应用cellStyle 才有效。 哦,记住rowHeight被定义为角色的1/256(!?!?!)所以将rowHeight设置为 (short)(numberOfNewLines*256) :编辑结束: 我有这段代码生成Excel电子表格。 使用一些单元格的内容创建 cell.setCellValue(new XSSFRichTextString(header)); cell.setCellStyle(cs); 但是,如果我设置 header = “Estimated\nDuration”; 然后新行不会在生成的电子表格中呈现。 它只是“EstimatedDuration”。 我正在使用Apache POI v3.9。 有什么建议?

使用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’) […]