Formulas are not updating in Excel, Java Apache API - java

I have two excel documents excel1.xls and excel2.xlsm. Where I read the data from excel1 and write it to excel2 using Apache API. In excel2 file, some cells have the formulas to auto update.
Problem: When the excel2 file is last opened/saved with Microsoft Excel 2007, everything works fine. But, when its last opened/saved with 2013 version, the auto update cell doesn't work anymore. All the computers at work are now moved to Office 2013, So I can't use Excel 2007 anymore.
I have already checked/set the setting Formulas - > Calculations Options -> Automatic in Excel
I also tried to use evaluateFormulaCell() and evaluateAllFormulaCells()methods in the program, doesn't update anything.
I am not sure, whether the excel has some kind of security, which is stopping to auto update?

XSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);
This method worked for me, before I only used to call this method at the end, but now I called it every time I set a single cell and it worked.

You might be able to re-save the excel files in 2007 format. This could solve it.

Related

How to stop forceformularecalculation apache poi

I am using apache poi 3.12 to generate excel using database data. For some cells I am using formulas also, all calculations are working properly and file was generated successfully. Below is my issue.
1) Opened the generated file using MS Excel application.
2) Verified the values and all are Ok.
3) As the excel file was password protected after verification I tried to close the file.
4) While closing it was showing message as "MS EXcel recalculates formulas when opening files last saved by an earlier version of excel".
I added "workbook.setForceFormulaRecalculation(false);" before writing my input stream to workbook.
From API docs it says it will not recalculate the formulas one workbook is opened if set the value to "false".
FYI, I have used unimplemented excel function "YIELD" in one cell.
Can anybody help on this.

Automatically update database when new excel sheet is added in a folder

I need to write one java program which monitors a folder containing excel sheets (.xls format) . Once a new excel sheet is added I have to update the database in db2 and move the excel sheet to other place.
Please suggest
It sounds like you need to get notified if files appear in a directory. Java 7 has good support for this, see this article about the Watch Service API. The db2 part, well it isn't clear what you mean by "update", but likely you want to parse the content of the xls file and make some database updates. Apache POI is a good starting place for reading the content of the file into a Java process.

how to upload excel into database using java?

hi
i am having one excel file which contains 15 columns and having 5000 recordes.
Now entering 5000 records manually into database is really a tough one.
instead i want to create a small java application which get input as excel file and just by clicking upload to database button it should be uploaded to DB.
any ideas? is there any jar?
please anybody guide me with example
You need a excel parser. The popular one is POI Spreadsheet. Another one is JExcelAPI.
If you're using MySQL you'll probably want to look at this: Import Excel Data into MySQL in 5 Easy Steps.
Otherwise checkout the Java Excel API or Apache POI to parse an Excel document. Then iterate over the cells and insert them into your database. See Getting Started with JDBC if you're not familiar with writing to a database. Search around online as well, there are all sorts of libraries and examples out there.
Without more details about what you're doing it's hard to make more than these general suggestions.

Why is a cell value returned as an empty string even though it has content?

I wrote a Java method that uses POI HSSF API to convert an Excel file to my data structure.
The code worked just fine for a while. But now there are suddenly problems. I suspect it might be because recently we installed Office 2007 on all the client computers, previously we had Office 2003.
The problem I ran into is: Inside the XLS file I have a column of cells that is filled with serial-numbers by the user. When the Java application gets the cell, it has a cell type STRING. And when I ask for the string value of the cell I get an empty string.
The file is originally created by the application, then the users fill it with data and load it back into the aplication. So I don't think the file format is wrong, since it's created by the same version of the API.
What could be the problem?
EDIT:
Clarification: We upgraded Office installation to 2007, but the application still uses HSSF and XLS format. Only the users open and edit the files with Office 2007. Is that a problem?
Have you checked if Excel automatically switched the cell type to NUMERIC when the user entered the value?
Excel has this annoying feature to "intelligently guess" what kind of value the user enters which then often causes a problem in POI.
HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.
read furthur
http://poi.apache.org/spreadsheet/index.html

Is it possible using apache poi to load data from an open excel file that is constantly updating?

I have this Java program that uses apache poi to load data from an excel file.
Problem I'm facing is I can't seem to load data from the excel file that is constantly updating. I only get the initial data when I run my java program.
You have to reread the data from the excel file. POI makes a copy into java objects when it reads it, so any further changes won't get reflected in your Java code without rereading the file.
If you mean that you do reread the file but don't see the updates, then it could be that someone is making changes in excel but not saving them, so POI can't see them yet.
This Answer is referred from Fetch Data From Excel have a look at this answer for more details. Maybe this question is a duplicate of the above link or vice versa.
The problem is because the excel data is not saved. I was also dealing with the same problem and got up with a different solution which worked for me. I just created a macro in excel to save the excel workbook whenever it's cell values got changed. Now I got the excel file with up-to-date saved data which can be read through java code and can be used for other purposes.

Categories