apache-poi

Get currency applied to an Excel Cell using POI

对着背影说爱祢 提交于 2021-02-08 08:05:32
问题 I have written a Java program to read an Excel file cell-by-cell using POI API. The setting of the currency is done explicitly using the MS Excel - "Format Cell" option. However, is there any way in which I can recognize the currency that has been applied to the cell using POI? So far, I have tried using getCellStyle().getDataFormat() and it returns a unique number. However, the problem is that it is based on the cell style, and can change with a change in the cell formatting(font, size, etc.

Get currency applied to an Excel Cell using POI

谁说胖子不能爱 提交于 2021-02-08 08:04:56
问题 I have written a Java program to read an Excel file cell-by-cell using POI API. The setting of the currency is done explicitly using the MS Excel - "Format Cell" option. However, is there any way in which I can recognize the currency that has been applied to the cell using POI? So far, I have tried using getCellStyle().getDataFormat() and it returns a unique number. However, the problem is that it is based on the cell style, and can change with a change in the cell formatting(font, size, etc.

Wrap Text in Apache POI(docx)?

吃可爱长大的小学妹 提交于 2021-02-08 07:54:48
问题 I want to add an image into docx , but I just found simple apache poi code: XWPFDocument document = new XWPFDocument() XWPFParagraph paragraph = document.createParagraph() XWPFRun run = paragraph.createRun() run.addPicture(new FileInputStream(img), format, img, Units.toEMU(width), Units.toEMU(height)) FileOutputStream outputStream = new FileOutputStream(doc) document.write(outputStream) Now I want to set the picture in front of text , but I can not found any reference. 回答1: The Office Open

Wrap Text in Apache POI(docx)?

我的梦境 提交于 2021-02-08 07:54:43
问题 I want to add an image into docx , but I just found simple apache poi code: XWPFDocument document = new XWPFDocument() XWPFParagraph paragraph = document.createParagraph() XWPFRun run = paragraph.createRun() run.addPicture(new FileInputStream(img), format, img, Units.toEMU(width), Units.toEMU(height)) FileOutputStream outputStream = new FileOutputStream(doc) document.write(outputStream) Now I want to set the picture in front of text , but I can not found any reference. 回答1: The Office Open

The method setFillForegroundColor(short) in the type CellStyle is not applicable for the arguments (XSSFColor)

雨燕双飞 提交于 2021-02-08 07:52:38
问题 I am trying to get custom colours to work in Apache POI but I got into a small problem. So far I have been using IndexedColors , but as a palette, it is pretty drab. Thus using an RGB format for colour selection would help me to make my spreadsheets look much better. I have been using this question's answer, as it solves my problem theoretically. However, I am facing a very silly problem that I do not really know how to solve. The error I receive is: The method setFillForegroundColor(short)

POI read sentence from Word document

爷,独闯天下 提交于 2021-02-08 07:28:56
问题 I have written java program to read data from excel and to replace the same available in word document with Apache POI.The problem is poi reads only the word not the sentence: XWPFDocument doc = new XWPFDocument(OPCPackage.open("input.docx")); for (XWPFParagraph p : doc.getParagraphs()) { List<XWPFRun> runs = p.getRuns(); if (runs != null) { for (XWPFRun r : runs) { String text = r.getText(0); if (text != null && text.contains("needle")) { text = text.replace("needle", "haystack"); r.setText

POI read sentence from Word document

别说谁变了你拦得住时间么 提交于 2021-02-08 07:28:33
问题 I have written java program to read data from excel and to replace the same available in word document with Apache POI.The problem is poi reads only the word not the sentence: XWPFDocument doc = new XWPFDocument(OPCPackage.open("input.docx")); for (XWPFParagraph p : doc.getParagraphs()) { List<XWPFRun> runs = p.getRuns(); if (runs != null) { for (XWPFRun r : runs) { String text = r.getText(0); if (text != null && text.contains("needle")) { text = text.replace("needle", "haystack"); r.setText

POI read sentence from Word document

拟墨画扇 提交于 2021-02-08 07:27:33
问题 I have written java program to read data from excel and to replace the same available in word document with Apache POI.The problem is poi reads only the word not the sentence: XWPFDocument doc = new XWPFDocument(OPCPackage.open("input.docx")); for (XWPFParagraph p : doc.getParagraphs()) { List<XWPFRun> runs = p.getRuns(); if (runs != null) { for (XWPFRun r : runs) { String text = r.getText(0); if (text != null && text.contains("needle")) { text = text.replace("needle", "haystack"); r.setText

How to transpose sheet with POI SS/XSSF?

青春壹個敷衍的年華 提交于 2021-02-07 13:48:03
问题 I am using POI XSSF API and I would like to transpose a sheet. how can I do that? Thanks. 回答1: Transpose, as in swap A2 with B1 and A3 with C1 (so columns become rows)? If so, there's nothing built in, so you'd need to do a little bit of coding yourself. You'd likely want to grab a pair of cells, save the contents of one (value and style), copy the second to the first, then overwrite the second. See the quick guide if you're not sure on all the reading/writing parts. 回答2: I was looking for

How to transpose sheet with POI SS/XSSF?

浪子不回头ぞ 提交于 2021-02-07 13:46:27
问题 I am using POI XSSF API and I would like to transpose a sheet. how can I do that? Thanks. 回答1: Transpose, as in swap A2 with B1 and A3 with C1 (so columns become rows)? If so, there's nothing built in, so you'd need to do a little bit of coding yourself. You'd likely want to grab a pair of cells, save the contents of one (value and style), copy the second to the first, then overwrite the second. See the quick guide if you're not sure on all the reading/writing parts. 回答2: I was looking for