apache-poi

Java Apache POI newline characters are ignored when writing to XWPFTable cell

Deadly 提交于 2019-12-04 23:55:37
Hoping someone might have some experience with this. I'm using Apache POI 3.8b4 to output a table in Word 2007 format. When I do something similar to the following: XWPFTableRow row = table.getRow(0); String text = "A\nB\nC\nD"; row.getCell(i).setText(text); all of my line breaks are ignored in the output in the table cell looks like A B C D Does anyone have any idea how to get it to properly display as A B C D Edit: The solution was the following: XWPFParagraph para = row.getCell(i).getParagraphs().get(0); for(String text : myStrings){ XWPFRun run = para.createRun(); run.setText(text.trim());

Merge and align center cell using apache poi

梦想与她 提交于 2019-12-04 23:49:10
I want to export data to excel using Apache poi . Now the problem that I am facing is that I am unable to merge rows and align them in the center. Code for export data is: List<LinkedHashMap<String,Object>> lstReportHeader = null; HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); //Set Header Font HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(headerFont.BOLDWEIGHT_BOLD); headerFont.setFontHeightInPoints((short) 12); //Set Header Style CellStyle headerStyle = wb.createCellStyle(); headerStyle.setFillBackgroundColor(IndexedColors.BLACK.getIndex());

Display percentage values in Excel using POI API

 ̄綄美尐妖づ 提交于 2019-12-04 23:37:31
I need to display a value in an excel cell formatted like a percentage, e.g. like 12.3% . By default the value is displayed as Text, but I need to display it as a number. What is the appropriate method to achieve this? You need to: Set your data as number (floating-point), not as text. Specify cell format as percentage. Something like: cell.setCellValue(0.123); // set value as number CellStyle style = workbook.createCellStyle(); style.setDataFormat(workbook.createDataFormat().getFormat("0.000%")); cell.setCellStyle(style); Take a look at user defined formats section of POI quick guide for more

How to create a working OSGI bundle for Apache POI 3.8?

时光毁灭记忆、已成空白 提交于 2019-12-04 23:36:14
问题 My goal is to create an Excel 2007 document (XLSX) in an Eclipse RCP Environment (Excel 2003 is simple). I don't want to place the POI jars inside a /lib folder , instead I want to use a working POI OSGI bundle from my target definition. All my attempts so far have failed to create a working OSGI bundle of POI 3.8. What I did so far: I merged all relevant JAR files with the Ant zip task: poi-3.8-beta3-20110606.jar poi-ooxml-3.8-beta3-20110606.jar poi-ooxml-schemas-3.8-beta3-20110606.jar poi

Is it possible to parse MS Word using Apache POI and convert it into XML?

牧云@^-^@ 提交于 2019-12-04 23:23:36
问题 Is it possible to convert a MS Word to XML file using Apache POI ? If it is, can you point me to any tutorials for doing that? 回答1: I'd say you have two options, both powered by Apache POI One is to use Apache Tika. Tika is a text and metadata extraction toolkit, and is able to extract fairly rich text from Word documents by making appropriate calls to POI. The result is that Tika will give you XHTML style XML for the contents of your word document. The other option is to use a class that was

Setting background custom color not working for XSSF in Apache POI

那年仲夏 提交于 2019-12-04 22:54:54
I wrote code which should create an Excel file (xlsx or xls) and set a custom background color to cell. When creating the xls file the background color works fine, but in case of xlsx the background color is not set to the right color. What is wrong in my code? public class PoiWriteExcelFile { static Workbook workbook; static Sheet worksheet; public static void main(String[] args) { try { String type = "xlsx"; //xls FileOutputStream fileOut = new FileOutputStream("D:\\poi-test." + type); switch (type) { case "xls": workbook = new HSSFWorkbook(); break; case "xlsx": workbook = new XSSFWorkbook(

Java - POI - Add a picture to the header

只愿长相守 提交于 2019-12-04 22:33:21
I have been trying to add a picture to a new docx file using Java POI to the header. 1) I have added a header, and added a text to it (using XWPFHeaderFooterPolicy). 2) I have create an image (using CustomXWPFDocument). 3) But I could not insert the image inside the header area. I have tried to do so through adding the picture into the same paragraph of the header, but it did not work. Here is the function that should add the picture to the header. It takes a CustomXWPFDocument object that has been already created: private void addLogo(CustomXWPFDocument doc) throws InvalidFormatException,

POI 4 XPages installation (site.xml)

核能气质少年 提交于 2019-12-04 21:15:55
I find this website ( http://poi4xpages.openntf.org/ ) for install POI 4 in domino designer. I download the zip file and follow the installation guide from https://my.webgate.biz/poi/documentation.nsf/viewdoc.xsp?docid=installguide In step 2: Import the update site from the ZIP file into the eclipse update site. I try to import the site.xml file but I get an error. The error is like this: Object variable not set(#91) dlgimportsite: click (line 9) I open site.xml and check line 9, the code is like this <category-def name="Apache POI Integration" label="Apache POI Integration"/> I don't know why

How to integrate Liferay DXP with Apache POI?

人盡茶涼 提交于 2019-12-04 20:27:09
I'm trying to integrate Apache POI in Liferay DXP(OSGi) , but unable to resolve dependencies with POI 3.17 version in gradle project. I've created standalone project with below JAR's : poi-3.17.jar poi-ooxml-3.17.jar poi-ooxml-schemas-3.17.jar xmlbeans-2.6.0.jar commons-collections4-4.1.jar Also, I've added below gradle dependencies added in build.gradle compile group: 'org.apache.poi', name: 'poi', version: '3.17' compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17' compile group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17' compile group: 'org.apache.xmlbeans',

How to use Tika's XWPFWordExtractorDecorator class?

回眸只為那壹抹淺笑 提交于 2019-12-04 19:29:01
Someone told me that Tika's XWPFWordExtractorDecorator class is used to convert docx into html. But I am not sure how to use this class to get the HTML from docx. Any other library for doing the same job is also appreciated/ You shouldn't use it directly Instead, call Tika in the usual way, and it'll call the appropriate code for you If you want XHTML from parsing a file, the code looks something like // Either of these will work, the latter is recommended //InputStream input = new FileInputStream("test.docx"); InputStream input = TikaInputStream.get(new File("test.docx")); // AutoDetect is