apache-poi

Apache POI decrypt doc file cannot process encrypted file?

☆樱花仙子☆ 提交于 2019-12-11 12:49:36
问题 public static void decryptedDoc(String path,String[] password) throws FileNotFoundException, IOException{ FileOutputStream fileOut = null; for(int i=0;i<password.length;i++){ // try{ Biff8EncryptionKey.setCurrentUserPassword(password[i]); NPOIFSFileSystem fs = new NPOIFSFileSystem( new FileInputStream(path)); HWPFDocument doc=new HWPFDocument(fs.getRoot()); Biff8EncryptionKey.setCurrentUserPassword(null); String neweachpath=path.substring(0, path.length()-4)+"_decrypted"+path.substring(path

Unit testing of Jar methods in java

佐手、 提交于 2019-12-11 12:34:21
问题 I'm using Apache POI methods for writing to excel sheets in java. I have to do unit-testing for the methods which I have written. I have used many methods of Apache POI. Should I stub all the methods of the different object classes of Apache POI? Example: I have created wrapper methods for writing to cell which are using Apache POI methods. protected void writeCell(int rowNum, int colNum, String value, Sheet sheet) { if(value == null) { return; } Row row = sheet.getRow(rowNum); Cell cell =

How to merge cells horizontally using apache-poi

余生颓废 提交于 2019-12-11 12:24:12
问题 I get to do a vertically merged using this function: private static void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) { for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) { XWPFTableCell cell = table.getRow(rowIndex).getCell(col); if ( rowIndex == fromRow ) { // The first merged cell is set with RESTART merge value cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); } else { // Cells which join (merge) the first one, are set with CONTINUE

POI Excel HSSFPicture Image and ALT TEXT

橙三吉。 提交于 2019-12-11 12:13:19
问题 I am using POI Excel HSSFPicture to create an image and add it to my excel file. I would like to add ALT TEXT to my image but I cannot find a way to add description to my image. Is there a way to add ALT TEXT to an image using POI for Excel? 回答1: Your requirement is to display alt text when the Image is not visible, right? So just an alternate try to use the Cell Comments to display the alt text. 来源: https://stackoverflow.com/questions/31147214/poi-excel-hssfpicture-image-and-alt-text

exception while using excel workbook

Deadly 提交于 2019-12-11 12:06:36
问题 I am getting these exceptions in my code while i m writing some data in excel workbook using poi jars: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/UnsupportedFileFormatException at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net

How do i read and edit huge excel files using POI?

我只是一个虾纸丫 提交于 2019-12-11 11:59:48
问题 I have a requirement to do the following 1)Copy a huge excel file 1400*1400 and make a copy. 2)Read the copied file and add new columns and rows and also edit at the same time. 3)This is going to be a standalone program and not on a server. I have limitations of having low memory footprint and fast performance. I have done some reading and have found the following 1)There is no API to copy sucg a huge file 2)SXSSF can be using for writing but not for reading 3)XSSF and SAX (Event API) can be

Put brackets around filename for Excel formula

谁都会走 提交于 2019-12-11 11:58:20
问题 My project is based on Apache POI.I'm trying to use a formula on a cell. My formula is as follows. sheet7.createRow(0).createCell(0).setCellFormula("+'C:\\Users\\Desktop\\[Test.xlsx]Average_Graph'!A2"); Im using a JFileChooser, which allows users to select the file. Therefore the filepath will be changed every time the program is used. From the JFileChooser, I'm getting a filepath as follows. String filepath= "C:\\Users\\Desktop\\Sheet.xlsx"` In order to work the formula correctly, the

How to set Validation for a cell in Excel created using NPOI

回眸只為那壹抹淺笑 提交于 2019-12-11 11:39:14
问题 I have created an excell file using NPOI using following code var workbook = new HSSFWorkbook(); var sheet = workbook.CreateSheet("Candidate"); // Add header labels var rowIndex = 0; var row = sheet.CreateRow(rowIndex); row.CreateCell(0).SetCellValue("Name"); row.CreateCell(1).SetCellValue("1,2,3"); row.CreateCell(2).SetCellValue("4,5,6"); row.CreateCell(3).SetCellValue("7,8,9"); rowIndex++; // Add data rows for (int i = 1; i <= 5; i++) { row = sheet.CreateRow(rowIndex); row.CreateCell(0)

Replace a placeholder with image in word?

感情迁移 提交于 2019-12-11 11:12:22
问题 I need to replace the placeholder with image in the word document using Apache POI. I am able to insert the picture in the word document using Apache poi. But i don't know how to replace the placeholder with image. Can anyone please help in this? I know it will be easy if we do it through docx4j or some other API, i am allowed to use only the Apache poi. 回答1: It can be done but I believe you must insert raw XML to accomplish it currently. This linked question "Insert picture in word document"

How i can add an Image as my header in a word document using Apache POI

落花浮王杯 提交于 2019-12-11 11:08:47
问题 I am trying create an word document using Apache POI which will contains an image as its header and some information ,i.e paragraph as its footer.I am able to create the header footer with paragraph only.But i need to add the image to the header which i can not manage,I am posting my code here which is correctly giving the result as the header footer both with the paragraph.Somebody please help me to reach this, public class CreateWordDoc { public static void main (String[] args) throws