apache-poi

Change a value in embedded xlsx with apache poi

谁都会走 提交于 2019-12-24 13:45:24
问题 I tried to change a value of a xlsx-file which is embedded in a docx-file with apache poi. Sadly, I havent found a proper solution to this problem. After running my programm, the new created docx-file with the embedded xlsx-table hasnt changed. Here is what I have tried so far: FileInputStream fis = new FileInputStream("old.docx"); XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis)); System.out.println(xdoc.getAllEmbedds().get(0)); File file2 = new File("new.docx"); for (PackagePart

How to set column names

£可爱£侵袭症+ 提交于 2019-12-24 13:35:43
问题 I'm using Apache POI for my app and I want to set columns names instead of "A, B, C..." I use the following code but it adds just data in first row: public void createHeaderRow(HSSFSheet sheet, List<String> headerRowList) { HSSFRow headerRow = sheet.createRow(0); for(int i=0;i<headerRowList.size();i++){ HSSFCell cell = headerRow.createCell((short) i); cell.setCellValue(headerRowList.get(i).toString()); } } So any ideas? 回答1: Bad news: AFAIK excel cannot do anything different than A, B, C. The

POI - Importing new fonts to the POI

给你一囗甜甜゛ 提交于 2019-12-24 13:33:38
问题 How can i import a new font to POI API with extensions ttf & otf , without install these fonts into the environment ? Is there a jar that i should update it with the path of the new font ? 回答1: Normally You cannot add fonts... You can think your (office) files just like HTML. Font lives outside the document. You just set the font name, family, etc. Update: However, someone has already tried to do that. Using embedded files, you could add font files. Link: http://apache-poi.1045710.n5.nabble

Get Row and Col for embedded Object with POI

一笑奈何 提交于 2019-12-24 13:09:09
问题 i'm currently working with Excel files (*.xlsm) and Apache POI , and i have been cracking my head over a task. I receive some excel files that have PDFs embedded in it and i want to extract them and rename them based on the row and column they are in. This seems weird as i know the embedded objects are represented as images ,they can occupy more than one cell and technically they are not "In" the cell. The following code snippet lets me extract the embedded PDFs but they are named OleObject[1

Java Heap Space error from command line

拈花ヽ惹草 提交于 2019-12-24 12:34:18
问题 I have tried to create a small utility which reads excel and sends email. I am using ApachePOI library for that. When I executed the code from eclipse, initially I got java.lang.OutOfMemoryError: GC overhead limit exceeded error. Then I added -Xms1024m in the VM Arguments of eclipse and program worked fine in eclipse. Then I exported the set of java programs and libraries into RunnableJar and bundled the dependent libraries. Now from command line when i execute the command java -Xms1024m -jar

ExcelReader workbook.setMissingCellPolicy(Row.CREATE_NULL_AS_BLANK) is not working

隐身守侯 提交于 2019-12-24 11:35:59
问题 I am trying to read excel file(xls) file using apache poi. In that, during read row if a cell is missing (cellIterator) is skipping that cell and putting the next value to different header. A B C 1 2 3 4 blank 6 In above case it is putting 6 in 'B' column at blank cell and i need B as blank String. `package com.howtodoinjava.demo.poi; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List;

Exporting .xlsx files from an HttpServletResponse in JSF - corruption errors

左心房为你撑大大i 提交于 2019-12-24 11:34:52
问题 I've been banging my head against the wall on this problem for a while now, and I've done my fair share of looking through existing StackOverflow questions that are similar to my predicament, but haven't found a solution that works for me yet. I've got existing code that takes an HttpServletResponse and exports it as an .xls attachment for the user to download. This code is presented here: import java.io.IOException; import javax.faces.context.FacesContext; import javax.servlet.http

How to write unit test for class that writes data into word document with apache-poi java?

只愿长相守 提交于 2019-12-24 11:18:29
问题 I created a word-document with apache-poi (poi-ooxml version 3.15) and now I want to write unit tests for my classes. What is the best way to do that? We're using mockito(2.15.0) in our project. This is one of the classes I'm trying to write test for: @Component public class ProffesionalSumaryService { public void populateDocumentWithProfileSkills(XWPFDocument document, ExportProfileDTO profileData){ XWPFTable antet = document.createTable(); antet.getCTTbl().getTblPr().getTblBorders()

Get Cell color in excel with poi

守給你的承諾、 提交于 2019-12-24 10:49:29
问题 I read all questions on so but no answer was working. If i change the cell color in excel i still get 0 and 64. I am using excel 2007 and poi 3.11. Thanks for help. try{ File file = new File("C:\\Test\\poi.xlsx"); FileInputStream fis = new FileInputStream(file); XSSFWorkbook wb = new XSSFWorkbook(fis); XSSFSheet sh = wb.getSheet("Tabelle1"); XSSFCellStyle cs = sh.getRow(0).getCell(0).getCellStyle(); System.out.println("Color: "+cs.getFillForegroundColor()); // 0 System.out.println("Color: "

How do I edit pattern in DataFormatter?

让人想犯罪 __ 提交于 2019-12-24 10:47:06
问题 I want to read data in Excel with Java, and data of cell in Excel got 2 types is NUMERIC and STRING . So when I want to read the data as a NUMERIC , it only displays numbers 101125340004 , not like this 1.01E+11 because it is a telephone attribute. My code is working, but for some values (1%) still display floating-point number but they are actually integers, and I don't know why. Data in sheet of Excel 365 DataFormatter fmt = new DataFormatter(); if (cellType.toString().equals("NUMERIC"))