apache-poi

How to format Excel Cell as Date in Apache POI as with the Format Painter operation in Excel

a 夏天 提交于 2019-12-08 07:59:44
问题 I am pretty new to Apache POI, I wonder how to do that Format Painter operation to format a cell into Date format, each time when I try to copy the date format of cell, in POI, it can only give me Numeric, I wonder how can I keep the date format? // Get source cell type and style CellType type_from = cell_from.getCellTypeEnum(); CellStyle style_from = cell_from.getCellStyle(); // Get source cell data format short df = style_from.getDataFormat(); // Change dest cell cell type, set format on it

How to create new rows in apache poi 3.6?

☆樱花仙子☆ 提交于 2019-12-08 07:54:13
问题 I am using Apache POI 3.6 and java in our application. I have data in row numbers 9 to 30. Now, I want to include new rows after the row number 25. After doing like this, the old data in 26 to 30 was destroyed.... I want to add that new rows without destroy the old row's data... We can manually, create new rows by just right click the mouse on the row Header like row number 25 and select insert then it will include the 26 row without deleting anything about the old values. How I do it

Apache POI seeing columns in empty spreadsheet?

霸气de小男生 提交于 2019-12-08 07:08:54
问题 I have an empty spreadsheet, but when I'm accessing it with Apache POI (version 3.10), it says it has 1024 columns and 20 physical columns. I really deleted all the cells, only some formatting remains, but no content. And if I delete some columns with LibreOffice Calc (version 4.1.3.2), the number of columns only increases ! What's going on? Is there a reliable way to get the real number of columns (or cells in a row)? import java.net.URL; import org.apache.poi.ss.usermodel.*; public class

Slow XSSFWorkbook and WorkbookFactory when reading xlsx files

若如初见. 提交于 2019-12-08 07:04:17
问题 I've seen developers have had this problem since a few years ago. I have studied many forums and the official POI documents. Nonetheless I haven't found an answer yet. So the problem is.. I have tried the following two snippets: Workbook wb = WorkbookFactory.create(new File("spreadsheet.xlsx")); and File file = new File("C:\\spreadsheet.xlsx"); OPCPackage opcPackage = OPCPackage.open(file.getAbsolutePath()); XSSFWorkbook workbook = new XSSFWorkbook(opcPackage); and either of the approaches

How to modify the cell value of a table in an pptx file with apache-poi 3.9?

久未见 提交于 2019-12-08 06:58:31
问题 I'm trying to modifify the cell value of a table within a pptx file. Saving the file, the modification is not applied. Here is the used code: FileInputStream is = new FileInputStream("C:/Report_Template.pptx"); XMLSlideShow ppt = new XMLSlideShow(is); is.close(); ppt.getPageSize(); for(XSLFSlide slide : ppt.getSlides()) { for(XSLFShape shape : slide){ shape.getAnchor(); if (shape instanceof XSLFTable){ XSLFTable t = (XSLFTable) shape; List<XSLFTableRow> r = t.getRows(); for (int i = 1; i < r

Writing a List instance to Excel file - Apache POI

别来无恙 提交于 2019-12-08 06:31:25
I have a List of String objects that are pipe delimited. something like this: String1|String2|String3 String4|String5|String6 ... Using Apache POI as excel library, is it possible to iterate over entire List writing out the string object as each row in the excel file? i.e. something like: for (String inst : <List instance>) <sheetInstance>.write(inst) i.e. output the string directly to the excel as a row entry rather than setting each cell value with a string i.e. setting row 1, cell 1 = String1 setting row 1, cell 2 = String2 setting row 1, cell 3 = String3 setting row 2, cell 1 = String4 ...

Java how to user JFileChooser to save a excel file created by Apache POI

空扰寡人 提交于 2019-12-08 06:13:19
问题 I want to save a spreadsheet file to a user custom file folder, people suggest to use JFileChooser , but I actually don't know how to achieve it. I have my current example code here: import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook;

How to make verticaltext cellstyle with Apache POI?

佐手、 提交于 2019-12-08 05:40:17
问题 Recently, I met a question: I need to export an excel(xlsx) with java, which must contain this kind of cell style: I made a excel file with this vertical text, and exported as a xml file. Then I found that the style has an attribute named 'VerticalText': By experience, I chose Apache POI. But I couldn't find any way to generate the cell style with POI. I could only find rotate method, which could't meet the requirement. So I read more code of POI, and found that the cellstyles are build from

HH:MM:SS xls reading using Apache POI

安稳与你 提交于 2019-12-08 05:23:21
问题 Please help me how to read an xls which file using Apache POI having cell value in the format HH:MM:SS . I am able to read cell value if time stamp in xls cell less than or equal 24 hours. (e.g. 23:30:30 ). Now my requirement is to read the same cell value even greater than 24 hours (e.g. 55:34:34 ) and store it in the database. 回答1: Dates and times in Excel are stored as floating point numbers. Dates are days since 1900 (a date of 1 is 01/01/1900), and times are fractions of a day (so 0.5 is

Adding Custom colours to Excel sheet using Apache POI

邮差的信 提交于 2019-12-08 05:14:19
问题 Can anyone explain how to add Custom colours either using (rgb values or hex values ) to an excelsheet sheet(either in foreground or background) using Cellstyle in Apche poi to a Excelsheet(XSSF Workbook)? 回答1: Setting custom colors depends on the kind of Excel file (Office Open XML format *.xlsx vs. BIFF format *.xls ). And it might be different using different versions of apache poi because of deprecation. Using Office Open XML format *.xlsx we can simply set new colors using constructor of