apache-poi

How to access .xlsx file stored on Sharepoint (with authentication) for Apache POI?

半世苍凉 提交于 2021-01-24 10:57:32
问题 I have a .xlsx file stored on sharepoint, which requires login in order to get/see the excel file. I need that file in order to do some ApachePOI operations on it How to download that file? I have tried doing it via InputStream but I don't know how to authenticate and I get 403 error which is obvious, as I don't provide password/login (don't know how) InputStream inputStream = new URL("https://example.sharepoint.com/something/something1/file.xlsx").openStream(); Files.copy(inputStream, Paths

How to access .xlsx file stored on Sharepoint (with authentication) for Apache POI?

我的梦境 提交于 2021-01-24 10:57:26
问题 I have a .xlsx file stored on sharepoint, which requires login in order to get/see the excel file. I need that file in order to do some ApachePOI operations on it How to download that file? I have tried doing it via InputStream but I don't know how to authenticate and I get 403 error which is obvious, as I don't provide password/login (don't know how) InputStream inputStream = new URL("https://example.sharepoint.com/something/something1/file.xlsx").openStream(); Files.copy(inputStream, Paths

How can I sum the values associated with a reoccurring key in a hashmap

泪湿孤枕 提交于 2021-01-20 07:23:33
问题 I want to add the values of the same keys in a hashmap. For example: ABC --> 123 DEF --> 456 ABC --> 123 XXX --> 111 XXX --> 222 should become: ABC --> 246 DEF --> 456 XXX --> 333 Here's the code I have so far: public class Reading { @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { //Create hashmap to store the the string and int in the excel sheet HashMap<String, Integer> hm = new HashMap<String, Integer>(); String key = null; int value = Integer.MIN

Java POI FormulaEvaluator giving unexpected floating point value

拜拜、爱过 提交于 2021-01-15 08:02:27
问题 I am using Java POI library to read an Excel file and then display it in HTML table. The Excel file is very simple with 1 row and 3 columns: A1 cell= 21.7 B1 cell= 20.0 C1 cell is a formula cell with the formula =(A1-B1)/B1 and it has a custom format of "Percentage" with 0 decimal places. Excel displays its value as 9%. This is because 1.7/20 on a calculator gives result as 0.085; when it is converted to "Percentage" format it becomes 8.5% and because format says include 0 decimal places, it

Apache Poi: Can custom properties on a worksheet level be accessed?

痞子三分冷 提交于 2021-01-07 01:24:03
问题 Can custom properties on worksheet level (in VBA accessed as Worksheet.CustomProperties) also be accessed via POI? 回答1: Jason - I've been struggling with the same issue and found a way to make it work, but it's far from optimal. Here it is anyway and hopefully you or someone else can come up with a better method. package temp.temp; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util

Apache Poi: Can custom properties on a worksheet level be accessed?

做~自己de王妃 提交于 2021-01-07 01:23:03
问题 Can custom properties on worksheet level (in VBA accessed as Worksheet.CustomProperties) also be accessed via POI? 回答1: Jason - I've been struggling with the same issue and found a way to make it work, but it's far from optimal. Here it is anyway and hopefully you or someone else can come up with a better method. package temp.temp; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util

Why does SXSSF workbook (Apache POI) create larger xlsx sizes than Excel?

余生颓废 提交于 2020-12-29 12:32:39
问题 I developed a Java class to use the SXSSF workbook to overcome the Java Heap error which is always caused by the XSSF workbook when writing very large spreadsheets. See http://poi.apache.org/spreadsheet/how-to.html#sxssf for the solution. In short, I use workbook = new SXSSFWorkbook(SXSSFWorkbook.DEFAULT_WINDOW_SIZE); instead of workbook = new XSSFWorkbook(); This solution works like magic and I am now able to write very large xlsx spreadsheets with a much lower memory footprint. However,

Why does SXSSF workbook (Apache POI) create larger xlsx sizes than Excel?

假如想象 提交于 2020-12-29 12:31:18
问题 I developed a Java class to use the SXSSF workbook to overcome the Java Heap error which is always caused by the XSSF workbook when writing very large spreadsheets. See http://poi.apache.org/spreadsheet/how-to.html#sxssf for the solution. In short, I use workbook = new SXSSFWorkbook(SXSSFWorkbook.DEFAULT_WINDOW_SIZE); instead of workbook = new XSSFWorkbook(); This solution works like magic and I am now able to write very large xlsx spreadsheets with a much lower memory footprint. However,

How to set a cell format to Text

拟墨画扇 提交于 2020-12-29 09:25:08
问题 I am using Apache-POI 3.14. I have a need to lock-down a cell to a "Text" format. The data in my cell might be all digits, but it is still considered a string. When I write the cell, I do it like this: cell.setCellValue("001"); cell.setCellType(Cell.CELL_TYPE_STRING); When I open the output workbook in Excel, the cell contains the correct value ("001") and it displays with a small green triangle in the corner. Hovering over the exclamation point displays the hover text The number in this cell

Set Date format using Apache POI

夙愿已清 提交于 2020-12-29 09:06:35
问题 I want to set date in date format in excel file with Apache POI. The value will set in such a manner so that in Address Bar it will show in mm/dd/YYYY and in cell it will show in dd-mmm (Date in numeric and Month in String like 01-Jan). Will you please help me in this situation? 回答1: You can apply a HSSFCellStyle to the cell you need to fill. Here some code snippets from my past work, it's not intact but shows the basic idea: HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell(