apache-poi

How to insert a image in word document with Apache POI?

给你一囗甜甜゛ 提交于 2020-01-02 05:39:22
问题 I have this code: public class ImageAttachmentInDocument { /** * @param args * @throws IOException * @throws InvalidFormatException */ public static void main(String[] args) throws IOException, InvalidFormatException { XWPFDocument doc = new XWPFDocument(); FileInputStream is = new FileInputStream("encabezado.jpg"); doc.addPictureData(IOUtils.toByteArray(is), doc.PICTURE_TYPE_JPEG); XWPFParagraph title = doc.createParagraph(); XWPFRun run = title.createRun(); run.setText("Fig.1 A Natural

React excel file download corrupt

白昼怎懂夜的黑 提交于 2020-01-02 05:00:34
问题 Im trying to download an Excel file in Reactjs by calling a Spring REST endpoint but I'm running into issues with a corrupt file. React call... getFile(){ axios.get('get/download') .then((response) => { var blob = new Blob([response.data], {type:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}); filesaver.saveAs(blob, "excel.xlsx"); }); } Spring controller.... @RequestMapping(value = "/download", method = RequestMethod.GET) public void downloadExcelFile(final

apache poi - XSSF read formatted cell value

拈花ヽ惹草 提交于 2020-01-02 04:05:10
问题 Is there any way I can get to the formatted value that excel shows in a row, versus the raw value I am getting returned from the stream? Or would this fall under the "formula evaluation" category, which this does not support? 回答1: If you have the Cell that you're trying to get the data out of, try the following DataFormatter formatter = new DataFormatter(); String formattedCellValue = formatter.formatCellValue(myCell); If that doesn't get exactly what you're looking for, there are a number of

How to Highlight a text for a Pargraph in MS word using POI

爱⌒轻易说出口 提交于 2020-01-01 19:22:30
问题 I am developing a compare tool for the word document, whenever there is difference in both the document i need to highlight the substring in the paragraph.When i try to highlight using run, its highlighting whole paragraph instead of the sub string. Can you please guide us, how can i achieve this for a substring. 回答1: I had the same problem. Here I post a sample method where you highlight a substring contained in a run. private int highlightSubsentence(String sentence, XWPFParagraph p, int i)

apache poi add table in word document

前提是你 提交于 2020-01-01 17:21:26
问题 I have Java code to create table and some text to word document using Apache POI but it adds table in last document. I want to write some text, then add table and write some text again. Currently it adds table first and last document add 2 test (Hi & Bye) My code : public static void main(String[] args)throws Exception { //Blank Document XWPFDocument document= new XWPFDocument(); //Write the Document in file system FileOutputStream out = new FileOutputStream( new File("create_table.docx")); /

apache poi add table in word document

别等时光非礼了梦想. 提交于 2020-01-01 17:21:06
问题 I have Java code to create table and some text to word document using Apache POI but it adds table in last document. I want to write some text, then add table and write some text again. Currently it adds table first and last document add 2 test (Hi & Bye) My code : public static void main(String[] args)throws Exception { //Blank Document XWPFDocument document= new XWPFDocument(); //Write the Document in file system FileOutputStream out = new FileOutputStream( new File("create_table.docx")); /

Apache POI: cloning worksheets containing charts

不想你离开。 提交于 2020-01-01 16:45:12
问题 According to numerous sources, for example Limitations section on official page, probably the only good way to work with excel charts from POI is using Excel file with existing chart as a template and modify source cells used by chart. And it works great. The problem is that we need to have not only one but multiple (and we don't know how many at compile time) worksheets with the same chart but different (dynamically generated) data. Using cloneSheet(sheetNumber) is a way to duplicate a

Apache POI rate formula inconsistency with long periods

久未见 提交于 2020-01-01 16:37:12
问题 In order to emulate Excel's rate function, I'm using the Apache POI rate function I grabbed from the svn: private double calculateRate(double nper, double pmt, double pv, double fv, double type, double guess) { //FROM MS http://office.microsoft.com/en-us/excel-help/rate-HP005209232.aspx int FINANCIAL_MAX_ITERATIONS = 20; //Bet accuracy with 128 double FINANCIAL_PRECISION = 0.0000001; //1.0e-8 double y, y0, y1, x0, x1 = 0, f = 0, i = 0; double rate = guess; if (Math.abs(rate) < FINANCIAL

Crash when calling autoSizeColumn on worksheet, when run under Linux (Servicemix)

会有一股神秘感。 提交于 2020-01-01 12:25:10
问题 I've written module that generates excel, and deployed it under Servicemix. In Windows environment everything is fine, but under Linux Servicemix unexpectedly crashes on following call: for (short i=0;i<=3;i++) { log.trace("AutoSize column {}", i); worksheet.autoSizeColumn(i); } I'm using POI version 4.2-FINAL, FuseESB 4.2, Java 5.0. There are, however, no hs_err*.pid files. Servicemix logs ends on first autoSizeColumn call. Did anyone met such behaviour and know, how it is caused and how to

java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorkbook$Factory

邮差的信 提交于 2020-01-01 11:50:33
问题 I use example: http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/BusinessPlan.java This is my dependencies list: <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3