apache-poi

ResultSet to Excel (*.xlsx) Table Using Apache POI

[亡魂溺海] 提交于 2019-12-05 23:38:21
问题 I am trying to write ResultSet to Excel (*.xlsx) Table using Apache Poi. Invalid Table Object Error in Office Excel However, even though it writes the Excel file without any error, when I try to open it in Office Excel 2013, it shows an error and removes the table object to give only plain data view. Here is the rough Sample Code using this example: public static void writeExcel(ResultSet rs, int sqliteRowCount, String dir) { System.out.println("Writing Excel(*.xlsx) File..."); XSSFWorkbook

How to set image size is dynamically in poi word run.addPicture()?

[亡魂溺海] 提交于 2019-12-05 22:50:12
XWPFDocument doc= new XWPFDocument(); InputStream a = someMethod(underConditions(inputimage)); paragraph.createRun().addPicture(a, Document.PICTURE_TYPE_PNG, "", Units.toEMU(20), Units.toEMU(20)); a.close(); doc.write(new FileOutputStream("CreateWordHeaderFooter.docx")); doc.close(); This is simple code for add a image in poi word. But InputStream a is different under different conditions. If inputimage is small Units.toEMU(20), Units.toEMU(20) is to big, and if inputimage is big Units.toEMU(20), Units.toEMU(20) is too small. In this conditions images are distorted. So my question is how to

Remove template row in JXLS when input list is empty

99封情书 提交于 2019-12-05 21:54:12
I'm using JXLS to populate a template excel spreadsheet. Sometimes, one input - a list - is empty. When this happens, the template fields which use this list are shown in the populated spreadsheet in full JXLS regalia - eg, " ${someList.someValue} ". The fields in question are all in a single row (expanded to list.size() rows by JXLS). I want to clear the whole row when there are no records in the list. Is there a way to do so in JXLS? Alternatively, can anyone suggest a complementary way to use JExcel or POI to do so? You can use <jx:if> tags in your excel template. For example if you have a

Java write Excel files with POI event model

喜你入骨 提交于 2019-12-05 21:34:32
Is it possible to create and write to a (new) excel file using the event driven API from POI? I've found examples on how to read with that API, but not how to write. thanks, Jeff Here is one possibility, not very well written, though: http://www.docjar.org/html/api/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java.html I'm using a modified version of that, which does not require temporary files and is overall more efficient Yes. Absolutely. Look at POI-XSSF and POI-HSSF http://poi.apache.org/spreadsheet/how-to.html#user_api You could use the SXSSF from Apache POI https://poi.apache.org

How to read docx file content in java api using poi jar

前提是你 提交于 2019-12-05 21:30:46
I have done reading doc file now i'm trying to read docx file content. when i searched for sample code i found many, nothing worked. check the code for reference... import java.io.*; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.Document; import com.itextpdf.text.Paragraph; public class createPdfForDocx { public static void main(String[] args) { InputStream fs = null; Document document = new Document(); XWPFWordExtractor extractor = null ; try { fs = new FileInputStream

Java Apache-poi, memory leak with excel files

为君一笑 提交于 2019-12-05 21:28:52
I need to read (15000) excel files for my thesis. I'm using apache poi to open and later to analyze them but after around 5000 files I'm getting the following exception and stacktrace: Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded at org.apache.xmlbeans.impl.store.Cur$CurLoadContext.attr(Cur.java:3044) at org.apache.xmlbeans.impl.store.Cur$CurLoadContext.attr(Cur.java:3065) at org.apache.xmlbeans.impl.store.Locale$SaxHandler.startElement(Locale.java:3263) at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportStartTag(Piccolo.java:1082) at org.apache.xmlbeans

In Apache POI 3.9 using autosizeColumn the image present on the same column getting stretched

最后都变了- 提交于 2019-12-05 21:20:27
I have an image and some text below the image in an excel sheet. when i am applying autoSizeColumn() to the column where text present the image is also getting streched . i am also setting the anchortype to 2 but this is not protecting the image to resize. I am posting some sample code here. public static void main(String[] args) { try{ XSSFWorkbook book = new XSSFWorkbook(); XSSFSheet sheet = book.createSheet("Test Sheet"); InputStream is = new FileInputStream("D:\\RPM_Eclipse_Workspaces\\B6.9\\00POI\\Chrysanthemum.jpg"); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = book

Detecting hidden cells in excel using apache poi

帅比萌擦擦* 提交于 2019-12-05 20:49:07
We are using apache poi 3.8 to parse excels. We need to be able to detect (and skip) hidden rows as they tend to contain junk data in our usecases. It would seem this should work: row.isFormatted() && row.getRowStyle().getHidden() But there never appears to be any row-level formatting (getRowStyle() always returns null). As a last resort we thought checking cell styles might work: for (int i = 0; i < row.getLastCellNum(); i++) { Cell cell = row.getCell(i); if (cell != null && cell.getCellStyle() != null && cell.getCellStyle().getHidden()) ... But for every row we get (custom output in the

NoClassDefFoundError org/apache/poi/ss/usermodel/Workbook

﹥>﹥吖頭↗ 提交于 2019-12-05 19:58:26
I am running a shell script which calls a java class to get some data from database and create an excel report with that data. I get the error Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook when the code hits the below line in my java class: XSSFWorkbook workbook = new XSSFWorkbook (); This is how I have defined the classpath: CLASSPATH=${CLASSPATH}:<path-to-jars>/poi-2.5.1-final-20040804.jar CLASSPATH=${CLASSPATH}:<path-to-jars>/poi-ooxml-3.11.jar I verified that the jars have been downloaded(via gradle), so trying to understand what am I

How can I add the Apache POI Library in Eclipse - for Selenium Webdriver project?

Deadly 提交于 2019-12-05 19:20:12
问题 I need to add the apache poi to my project (I need hssf, ss and xssf). I downloaded a jar file from the internet but it does not contain xssf. I went to http://poi.apache.org/ and I downloaded this: http://www.apache.org/dyn/closer.cgi/poi/release/src/poi-src-3.9-20121203.zip, I extract it..and got stucked. I tried Part 1 but that was only for JavaDoc. How should I proceed from here? 回答1: Download The latest stable release: Apache POI 3.16-FINAL distribution, open your eclipse project