apache-poi

How can I add embedded equations to docx files by using Apache POI?

天大地大妈咪最大 提交于 2020-01-11 07:47:55
问题 I want to create a docx file programatically via Apache POI. I want to add some mathematical equations in some lines. How can I do this in a way that when the user open the docx file it see that equations as docx equation form. I mean I don't want simply give a background colour to that run, I want when the user does double click on my equation MS-Word open it in equation forms. Thanks in advance 回答1: This is not really complicated: import java.io.FileOutputStream; import org.apache.poi.xwpf

How to read excel(.xlsx) in java using poi?

假装没事ソ 提交于 2020-01-11 02:29:10
问题 I am trying to read excel in java.I have following code. import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Iterator; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class Test { public static void main(String[] args)

Write Double value in numeric cell with specific format in Apache Poi 3.7

夙愿已清 提交于 2020-01-10 18:42:28
问题 I need to write a Double value in a numeric cell using a specific format, i mean, the generated xls must have numeric cells containing Double values like, for example: 8,1. I am trying something like: DecimalFormat dFormat = new DecimalFormat("##.#"); dFormat.format(doubleValue); But, since format method returns a String, no matter whether I create cells as numeric or not, they always behave as text cells. I was thinking about two options: Forcing cells to behave as numeric cells. Forgetting

How to speed up autosizing columns in apache POI?

烈酒焚心 提交于 2020-01-10 07:55:23
问题 I use the following code in order to autosize columns in my spreadsheet: for (int i = 0; i < columns.size(); i++) { sheet.autoSizeColumn(i, true); sheet.setColumnWidth(i, sheet.getColumnWidth(i) + 600); } The problem is it takes more than 10 minutes to autosize each column in case of large spreadsheets with more than 3000 rows. It goes very fast for small documents though. Is there anything which could help autosizing to work faster? 回答1: Solution which worked for me: It was possible to avoid

Open EXISTING xls in Apache POI

女生的网名这么多〃 提交于 2020-01-10 04:49:04
问题 I have an existing file (C:\wb.xls) that I want to open and make changes to. How in Apachie POI do you open an existing file? All the documentation that I find has to go with creating a new file. And if you know, how do you insert a new row at the top of the xls file or how to autoformat column widths? 回答1: Use one among the following XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(xlFileAddress)); OR Workbook wb = WorkbookFactory.create(new File(xlFileAddress)); OR Workbook wb =

Low memory writing/reading with Apache POI

蓝咒 提交于 2020-01-10 03:06:49
问题 I'm trying to write a pretty large XLSX file (4M+ cells) and I'm having some memory issues. I can't use SXSSF since I also need to read the existing cells in the template. Is there anything I can do to reduce the memory footprint? Perhaps combine streaming reading and streaming writing? 回答1: To handle large data with low memory, the best and I think the only option is SXSSF api-s. If you need to read some data of the existing cells, I assume you do not need the entire 4M+ at the same time. In

Right to Left (RTL) text in XWPFDocument (Apache POI)

爱⌒轻易说出口 提交于 2020-01-09 11:57:09
问题 I could not find a way to make a RTL paragraph in Docx using XWPFDocument (Apache POI) in my Java program. Here's my code that generates the XWPFDocument. XWPFParagraph title = document.createParagraph(); title.setAlignment(ParagraphAlignment.CENTER); title.setVerticalAlignment(TextAlignment.CENTER); title.setWordWrap(true); XWPFRun titleRun = title.createRun(); titleRun.setText(reportDesign.getName()); XWPFTable s = document.createTable(resultList.size()+1, columnList.size()); // declare a

Convert ppt to png with apache poi

梦想的初衷 提交于 2020-01-07 09:05:26
问题 When I convert ppt to png using follow code: public static void main(String[] args) throws FileNotFoundException, IOException { final String PPT_TEMPLATE = "data/test.pptx"; float scale = 1; XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(PPT_TEMPLATE)); Dimension pgsize = ppt.getPageSize(); int width = (int) (pgsize.width * scale); int height = (int) (pgsize.height * scale); XSLFSlide slide = ppt.getSlides()[5]; BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE

Convert ppt to png with apache poi

时间秒杀一切 提交于 2020-01-07 09:05:08
问题 When I convert ppt to png using follow code: public static void main(String[] args) throws FileNotFoundException, IOException { final String PPT_TEMPLATE = "data/test.pptx"; float scale = 1; XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(PPT_TEMPLATE)); Dimension pgsize = ppt.getPageSize(); int width = (int) (pgsize.width * scale); int height = (int) (pgsize.height * scale); XSLFSlide slide = ppt.getSlides()[5]; BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE

Apache POI error when not in IDE

女生的网名这么多〃 提交于 2020-01-07 08:46:08
问题 We are using Apache POI to create a very simple spreadsheet. Everything works in the development environment. When released, the project is exported as a runnable JAR; this jar and all required libraries are placed on a central server. The various PCs all reference these same files. On most PCs (Linux and Win7), everything works. On a minority of Win7 machines, however, we receive the error: DOMSource cannot be processed: check that saxon9-dom.jar is on the classpath. I have tried adding the