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

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.

Related

Can I autorefresh an Excel file using java or any API?

I have an Excel file store locally which contains some sheets in it, one sheet containing raw data and other sheets contain performance pivots/graphs generated based on raw data.
The raw data sheet of an excel file is generated from my java program. I am storing the program generated raw data into the excel file stored locally.
Is there any way to refresh this excel file so that the related pivots/graphs on another sheets in same excel file gets refreshed to the new/updated raw data sheet.
You can do it in either side, in Excel or in Java... does it matter exactly when the Excel file gets refreshed?
If you can write VBA, you can have your Java program output the data into a data file, and when the Excel is next opened, the macro inside will copy the data and perform any necessary calculations.
If you want to do it via Java, you can use Apache POI:
https://poi.apache.org/
If Apache POI doesn't work for you, Excel exposes itself as an ActiveX object, you can use JNI or 3rd party Java-to-COM bridges to make changes to the Excel file.

Adding data in Excel file without closing it

I am currently using Apache POI to enter data into Excel file. The only problem is I can not keep the file open if I have to append data to the same file. Are there any specific sample codes which would allow me to do so?
My basic requirement is to fetch Runtime data from a place (this I am able to do) and add it to the Excel sheet while the file is still open.
Any suggestions?
I don't think that this is possible without a C# addon or some kind of macro. You could write a simple C# addon for Excel that connects to your java programm and recieves the realtime data. The addon will write it to the spreadsheat then.

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.

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.

Saving different csv files as different sheets in a single excel workbook

Related to this question, how to save many different csv files into one excel workbook with one sheet per csv ? I would like to know how to do this programmatically in Java.
You'll need some form of library for accessing Excel from Java. A Google search turned this one up:
http://j-integra.intrinsyc.com/support/com/doc/excel_example.html
An alternative is to use the XML Excel format that came into being with Office 2003. You'll end up with a XML file, but you can open it in Excel and see the different sheets.
http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-officeml.html
If you want open source, the POI library can be used to generated Excel files.
A nice CSV parser is Open CSV
That should set the stage for what you are trying to do (basically use the CSV parser to get data, then write the data to an XLS file.
Take a look at the Aspose products, I've used them before when working with Excel and they saved me a huge amount of headache and time. Excel has several quirks that can make importing and exporting spreadsheets painful.
Aspose.Cells

Categories