Adding data in Excel file without closing it - java

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.

Related

How to get file close event using java

My application saves excel file data in a database (mongodb) using java.
On user click my application will do
First create an excel file on local filesystem for instance C:\ali.xlsx and place data on excel file .
Open excel file C:\ali.xlsx using java.awt.Desktop class open method for the cross platform perspective.
When user close file C:\ali.xlsx gets its close event so that i will get file updated value and save it to the database.
Delete the file C:\ali.xlsx from the local filesystem.
My Question :
How to implement the third bullet point. In short : how to get close event of any file using java.
If anyone have another approach to implement this functionality please tell me also that's why I write the application flow .
I don't know any straightforward way, the uphill (:-)) way would be:
watch file system with WatchService, (tutorial)
in case of modification of the Excel file check if it's open in processes list and if not - follow with next step.
If I understand correctly you have an Excel sheet and you want to save this data to mongodb every time it gets updated.
There is no trigger available for what you ask. Instead you can keep reading the file at regular intervals and check the "lastModified" attribute. Or as you are deleting the file every time it means if it exists you have an update.

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.

Storing data in Excel file from an android application

My application generates data and i want to share this data, like transfer to my PC and work or send it to others as excel sheet.
Can we store data from an android application to a Excel sheet programatically ? Then how do we open and Excel file and write to it ?
In theory, libraries like Apache POI and JExcel should work on Adroid but there are some issues with them at this point.
Only option is to generate XL that can be read by Excel. Steps are:
Create an Excel file on PC with formatting that you need
Save that file as XML, Excel will insert Tags for formatting/ formulas
Write java code to generate similar XML file on Android
On Android, save this XML file on SD Card
Transfer the XML to PC and open that in Excel
Take a look at this tutorial, How to create file in SD-Card.

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