Tag: apache poi

如何将excel中的值存储到java中的某些集合

我有一个excel文件,如下所示, **Method Name** **Status Code** **user** **password** getLoggedinUserDetails 400 anto test createRequisition 400 mayank hexgen excelMDM 400 xxxxx hexgen createOrder 400 yyyyy hexgen confirmOrder 400 zzzzz hexgen 我想在一些collection保存上述细节,以便我可以details by providing username and get the details like Method Name, Status code,and password.访问details by providing username and get the details like Method Name, Status code,and password. 我试过这样的东西,只能存储method […]

与POI相关的代码块运行缓慢

我有下面的代码块包含循环: Row row = null; Cell cell = null; String dataVal = null; String[] temp = null; for (int j = 0; j < this.myDataValues.size(); j++) { row = sheet.createRow(rownum++); temp = this.finalRowValues.get(j); for (int i = 0; i < 4; i++) { cell = row.createCell(i); dataVal = temp[i]; if (NumberUtils.isNumber(dataVal)) { double d = […]

如何使用apache poi检查xlsx文件是否受密码保护

如何检查xlsx文件是否受密码保护。 我们可以检查xls文件如下 FileInputStream fin = new FileInputStream(new File(“C:/Book1.xls”)); POIFSFileSystem poifs = new POIFSFileSystem(fin); EncryptionInfo info = new EncryptionInfo(poifs); Decryptor d = Decryptor.getInstance(info); try { if (!d.verifyPassword(Decryptor.DEFAULT_PASSWORD)) { throw new RuntimeException(“Unable to process: document is encrypted”); } InputStream dataStream = d.getDataStream(poifs); HSSFWorkbook wb = new HSSFWorkbook(dataStream); // parse dataStream } catch (GeneralSecurityException ex) { throw new […]

将MS文档打开到JFrame中

我得到的是将Microsoft(Word,Excel等)打开到JFrame中。 有人可以告诉我一些这个库吗?Apache POI API( http://poi.apache.org )可以帮我解决这个问题吗?也许是JACOB库( http://danadler.com/jacob/ )?

使用POI api向ms字添加页脚

我搜索了很多并获得了一些结果,其中有一些示例代码,但没有人工作。 所有要么得到空指针exception,要么生成文档然后在打开文件(.docx)时给出错误并显示消息文本/ xml声明可能只在innput的最开始发生。 我想可能是我正在添加一些内容,然后添加页脚是一个问题所以我粘贴我的页脚代码在这一次我现在得到了 索引超出范围的exception 这是我的完整代码 String fileName =”Book.docx”; String folderPath=SystemProperties.get(SystemProperties.TMP_DIR)+File.separator+”liferay” + File.separator + “document_preview”; String filePath=folderPath+File.separator+fileName; File file=new File(filePath); XWPFDocument document = new XWPFDocument(); XWPFParagraph paragraphOne = document.createParagraph(); paragraphOne.setAlignment(ParagraphAlignment.CENTER); XWPFRun paragraphOneRunOne = paragraphOne.createRun(); paragraphOneRunOne.setText(“Training Report”); paragraphOneRunOne.addBreak(); XWPFTable table = document.createTable(); XWPFTableRow tableRowOne = table.getRow(0); tableRowOne.getCell(0).setText(“No”); tableRowOne.createCell().setText(“Name”); XWPFHeaderFooterPolicy headerFooterPolicy = document.getHeaderFooterPolicy(); if (headerFooterPolicy == null) […]

读取xlsx文件时出现apache POIexception

我正在使用apache POI通过添加以下依赖项来读取xlsx文件 org.apache.poi poi-ooxml 3.8 org.apache.xmlbeans xmlbeans 2.5.0 即使部署在tomcat中,我也会在使用jetty插件运行时遇到exception。 org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62) at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403) at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155) …… Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ……….. Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument at org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source) at org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:121) at org.apache.poi.xssf.model.StylesTable.(StylesTable.java:92) … 186 more 我删除了xmlbeans依赖,因为maven将自动下载poi依赖项,仍然是相同的exception。任何帮助?

在Apache POI中打开EXISTING xls

我有一个现有的文件(C:\ wb.xls),我想打开并进行更改。 如何在Apachie POI中打开现有文件? 我找到的所有文档都必须与创建新文件一起使用。 如果您知道,如何在xls文件的顶部插入新行或如何自动格式化列宽?

使用apache poi的PatternSyntaxException

我在两个不同的项目中使用Apache POI 第一个项目是一个独立的Java应用程序。 这里一切都很好。 第二个项目是一个Android项目。 我可以很好地访问xlsx的工作簿,但是在评估公式时,它会因exception而崩溃 java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR \P{IsL} at java.util.regex.Pattern.compileImpl(Native Method) at java.util.regex.Pattern.compile(Pattern.java:411) at java.util.regex.Pattern.(Pattern.java:394) at java.util.regex.Pattern.compile(Pattern.java:381) at org.apache.poi.ss.formula.functions.TextFunction$5.(TextFunction.java:124) at org.apache.poi.ss.formula.functions.TextFunction.(TextFunction.java:123) 这是有问题的代码行: final Pattern nonAlphabeticPattern = Pattern.compile(“\\P{IsL}”); 为什么Android不接受这个? 正如我所说:它在独立的Java应用程序上运行良好….

JAVA:将数据(从数据库)导出到Excel并将其发送到客户端

正如标题所示,我需要将一些数据(我从数据库中获取)放入Excel工作表,然后将其发送到客户端,以便用户可以保存,打开或取消操作。 我见过一些关于此的文章,最接近的一篇文章是: 如何让用户下载我的文件? (Java,MVC,Excel,POI) 。 参考Stevens提供的链接,我尝试了以下代码: public String execute(){ setContentDisposition(“attachment; filename=\”” + ename + “\””); try{ ServletContext servletContext = ServletActionContext.getServletContext(); String filePath = servletContext.getRealPath(“/WEB-INF/template/excel/mytemplate.xls”); File file = new File(filePath); Workbook wb = WorkbookFactory.create(new FileInputStream(file)); Sheet sheet = wb.getSheetAt(0); ByteArrayOutputStream baos = new ByteArrayOutputStream(); wb.write(baos); InputStream excelStream; excelStream = new ByteArrayInputStream(baos.toByteArray()); }catch(Exception e){ System.out.println(e.getMessage()); } return […]

使用带有openjdk的stix-fonts的例外?

我尝试创建SXSSFWorkbook 。 exception堆栈跟踪: java.lang.ArrayIndexOutOfBoundsException: 0 at sun.font.CompositeFont.getSlotFont(CompositeFont.java:351) at sun.font.CompositeGlyphMapper.initMapper(CompositeGlyphMapper.java:81) at sun.font.CompositeGlyphMapper.(CompositeGlyphMapper.java:62) at sun.font.CompositeFont.getMapper(CompositeFont.java:409) at sun.font.CompositeFont.canDisplay(CompositeFont.java:435) at java.awt.Font.canDisplayUpTo(Font.java:2063) at java.awt.font.TextLayout.singleFont(TextLayout.java:470) at java.awt.font.TextLayout.(TextLayout.java:531) at FontTest.main(FontTest.java:15) gradle文件: compile ‘org.apache.poi:poi:3.14’ compile ‘org.apache.poi:poi-ooxml:3.14’ 环境 : openjdk版本“1.8.0_141” RedHat 7.4 wildfly 10.0.0