apache-poi

Dynamic file download without saving file in the server

穿精又带淫゛_ 提交于 2019-12-05 05:29:20
问题 I am using Apache POI libraries to do some operation on multiple excel files. I'm trying to download the excel report without storing it somewhere in the server. I am using Struts 2 which needs the file fed into a InputStream while POI Workbook needs a OutputStream to write the data into. Any help would be great 回答1: Since you already know you need a Stream result: I am using Struts 2 which needs the file fed into a InputStream // With Getter private InputStream inputStream; and you already

Apache POI autoSizeColumn() not working right [duplicate]

☆樱花仙子☆ 提交于 2019-12-05 05:12:41
This question already has an answer here: Apache POI autoSizeColumn Resizes Incorrectly 8 answers I am creating a program that writes information to an excel file using the apache poi. After I enter all of my data into the file I call the autoSizeColumn method on every column of the file. But it resizes the columns to the width of the last cell entered which is sometime not as big as the other cells in the column. I know I'm using it right and unfortunately I don't have Internet right now to post any code but I will update when I can. Ok I hope I am using the code tags right but here it is :

How to parse UTF-8 characters in Excel files using POI

↘锁芯ラ 提交于 2019-12-05 05:08:50
I have been using POI to parse XLS and XLSX files successfully. However, I am unable to correctly extract special characters, such as UTF-8 encoded characters like Chinese or Japanese, from an Excel spreadsheet. I have figured out how to extract data from a UTF-8 encoded csv or tab delimited file, but no luck with the Excel file. Can anyone help? ( Edit: Code snippet from comments ) HSSFSheet sheet = workbook.getSheet(worksheet); HSSFEvaluationWorkbook ewb = HSSFEvaluationWorkbook.create(workbook); while (rowCtr <= lastRow && !rowBreakOut) { Row row = sheet.getRow(rowCtr);//rows.next(); for

Why can't I link one workbook to another in Apache POI?

余生颓废 提交于 2019-12-05 01:32:57
I have one workbook that has some data in it. I am taking that workbook and creating another workbook with a line chart in it based off of the data in the other workbook. The code runs fine, but whenever I open up the graph file, I get the warning We can't update some of the links in your workbook right now . If I click the Edit Links... button in the warning menu, it shows that the data workbook cannot be found. If I click on Change Source... , and select the proper workbook, it then works fine. Why is this? Can POI not retain the link between the two files? My code: To create the data

apache poi cellIterator skips blank cells but not in first row

拥有回忆 提交于 2019-12-05 01:12:01
I am creating a java program to read an excel sheet and create a comma separated file. When I run my sample excel file, with blank columns, The first row works perfectly, but the rest of the rows skip the blank cells. I have read about the code changes required to insert blank cells into the rows, but my question is why does the first row work ???? public ArrayList OpenAndReadExcel(){ FileInputStream file = null; HSSFWorkbook workBook = null; ArrayList <String> rows = new ArrayList(); //open the file try { file = new FileInputStream(new File("Fruity.xls")); } catch (FileNotFoundException e) {

How can I get an Input Stream from HSSFWorkbook Object

二次信任 提交于 2019-12-05 01:05:46
I want my web application users to download some data as an Excel file. I have the next function to send an Input Stream in the response object. public static void sendFile(InputStream is, HttpServletResponse response) throws IOException { BufferedInputStream in = null; try { int count; byte[] buffer = new byte[BUFFER_SIZE]; in = new BufferedInputStream(is); ServletOutputStream out = response.getOutputStream(); while(-1 != (count = in.read(buffer))) out.write(buffer, 0, count); out.flush(); } catch (IOException ioe) { System.err.println("IOException in Download::sendFile"); ioe.printStackTrace

Excel Formula Not Updating Cell

孤者浪人 提交于 2019-12-05 00:57:57
I am using apache POI to change cells in an excel sheet. After I change the values, the cells with formulas corresponding to cells that have been changed are not updating. When I go into excel and click on the cell with the formula, and then click in the function bar, the formula updates. I have calculation options set to automatically update. Quick example. Row : [A2 + A3] [1] [2] A1 here would equal 3 When I change it using POI: [A2+A3] [2] [5] A1 still equals 3 until I click on that cell. Refreshing the workbook or sheet also does not work. Is this a problem with excel or POI? Can anyone

How to add Data validation to entire column of an excel sheet using apache poi in java?

試著忘記壹切 提交于 2019-12-05 00:48:11
问题 I have a requirement Where I need to add data validation to an entire column rather than a specific cell. I went through the documentation of Apache poi and found the example below HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Data Validation"); CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0); DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint( new String[]{"10", "20", "30"}); DataValidation dataValidation = new

Java POI cannot find symbol WorkbookFactory

怎甘沉沦 提交于 2019-12-05 00:26:08
im doing a conversion of the HSSF model to XSSF. Im getting lil errors here and there. I donwloaded the latest POI and dropped all the jar files in and did the apache includes in my java class.....getting this error: import org.apache.poi.ss.usermodel.Workbook; Workbook wb = WorkbookFactory.create(); 275: cannot find symbol [javac] symbol : variable WorkbookFactory [javac] location: class mil.usmc.logcom.chassis.util.HSSFUtils [javac] Workbook wb = WorkbookFactory.create(); There is no zero-arg method for WorkbookFactory.create() . For example: InputStream inp = new FileInputStream("workbook