Insert picture in word document

First, I would like to point out the example provided by apache poi – Link, i.e. the correct way to do it would be doc.createParagraph().createRun().addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200)); However, there is still an existing bug which renders the .docx file unreadable after executing the above statement. It might be resolved soon, in which … Read more

How can I access password protected Excel workbook in Java using POI api

POI should be able to open both protected xls files (using org.apache.poi.hssf.record.crypt) and protected xlsx files (using org.apache.poi.poifs.crypt). Have you tried these? If you’re using HSSF (for a xls file), you need to set the password before opening the file. You do this with a call to: org.apache.poi.hssf.record.crypto.Biff8EncryptionKey.setCurrentUserPassword(password); After that, HSSF should be able to … Read more

Using com.bea.xml.stream package on android

Check FAQ #18: This error indicates that the class XMLEventFactory does not provide functionality which POI is depending upon. There can be a number of different reasons for this: Outdated xml-apis.jar, stax-apis.jar or xercesImpl.jar: These libraries were required with Java 5 and lower, but are not actually required with spec-compliant Java 6 implementations, so try … Read more

Make column read-only using apache poi

You have to protect the whole sheet and unlock the cells which should be editable: String file = “c:\\poitest.xlsx”; FileOutputStream outputStream = new FileOutputStream(file); Workbook wb = new XSSFWorkbook(); CellStyle unlockedCellStyle = wb.createCellStyle(); unlockedCellStyle.setLocked(false); Sheet sheet = wb.createSheet(); sheet.protectSheet(“password”); Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue(“TEST”); cell.setCellStyle(unlockedCellStyle); wb.write(outputStream); outputStream.close();

How to avoid java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.copy(Ljava/io/InputStream;Ljava/io/OutputStream;) in Apache POI

I got this error today: “java.lang.NoSuchMethodError:org.apache.poi.util.POILogger.log(I[Ljava/lang/Object;)V]” It looks different from your error, but quite similar. FYI, I’m using maven to manage jars. After some experiment, I found out the root case is the poi.jar and poi-ooxml.jar’s version are not consistent. This configuration will get an error: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.12</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.13</version> … Read more