In my java application I am connecting to Microsoft Excel with Jacob libraries. Everything is fine but I do not know how I can catch com events when any changes in Excel page occurs by using Jacob libraries. For example, In my project I connect database takes table values and copy these values into cells of an excel page. Whenever a cell value is changed, the table value is also changed. That's I want synchronization between java and Microsoft Excel application by Jacob.
Don't use Java to achieve that. See this question: Excel OnChange event, with emphasis on this answer. You should access your database using com directly from Excel. That's easy using ADO. This ADO tutorial from w3schools looks also fine.
If the task is too complex to perform directly from Excel you may think of putting a small marker somewhere (e.g. in the database) that the data changed and process this marker from other app, possibly java app. The difficulty is that the credentials to access the database must be hardcoded in the Excel sheet. But you can create a separate database user with narrow database permissions.
Seeing your comment I also tried using Change event of Excel to detect changes done by other users. My experience on Excel 2003 shows that this works only locally. That is the event is fired only for the user that made the change. If many users have the worksheet open they don't receive Change event caused by changes from other users. So your approach is unfeasible. You may test it with Excel 2010, but my impression is that the events in general work only locally. Couldn't find anything on the net about it. Only this general article: Track changes in a shared workbook.
Related
I am going to make a business application for my father to make GST(Goods and Services Tax) filing easier. I have the design ready and I am going to use JavaFX.
The user will enter the data in tableview and that data needs to be stored for future reference.
The tableview needs to be converted to an excel file (gonna use Apache POI). The excel file will be sent to a C.A who will file GST on my father's behalf.
The application will need to import/export data into/from the tableview and edit the data as necessary.
I have 2 options :
Store/retrieve data from MySQL to tableview, update it according to the user's will and later export the data into excel files for sending it to C.A.
Store/retrieve data from excel files to tableview, update it according to the user's will and send the excel file to C.A.
I am planning to expand the application into a complete Business software that can manage entire business.
What should I use?
Which one will be more efficient and why?
I hope I am able to convey my question (I ain't good at writing).
In my own opinion it is more efficient and have more posibilities to explotes the data using MySQL, because reading and writing an Excel file will take a lot of time and it is slower.
I'll answer my own question, since I have got the answer.
I'm going with SQLite for now as using csv or excel files is gonna consume a lot of resources (I tried it).
I am going to sync the .db file in drive using scripts from the application itself. MySQL is definitely better choice but I want to database to be used by 2 computers at a time (not in network) so I will have to pay for online database.
I will store the .db file and drive and will retrieve it whenever the application runs. In this way its going to be safe.
I have to build and app that extracts stock exchange data from an excel sheet then save it
in a database. The problem is that the excel sheet obtains new data via a Bloomberg plug in.
To refresh the page, the user has to open the spread sheet and hit the refresh button on the plug in in excel. After a second the data is added to the sheet.
i have seen guides about getting or putting data to an excel sheet via java but am not sure how to open the sheet, trigger the update and get the data.
Maybe you can retrieve the data directly with Excel, by using Web Queries.
So basically, this feature allows you to get data from the web. You specify the URL, then you select which data on the page you want to import.
You can write these queries in VB as well (ask if you want more details on how to do it with VB).
http://office.microsoft.com/
It is not clear what you are trying to achieve. I understand that you only use the spreadsheet to get the data and save it to a database.
There are a few alternatives I can think of:
[dirty] create a scheduled task in Windows that opens the spreadsheet every x minutes / hours. In your workbook, create a Workbook_Open event that uses Application.OnTime to execute a macro to do what you need to do with the data after a few minutes (the time it takes for the data to update). This is error-prone and will probably fail from time to time.
[better] use something similar except that you get the data programmatically with the VBA Addin, populate the sheet from VBA and/or do what you need to do with the data. No need for Application.OnTime in that case. You can even automatically save/close the spreadsheet.
[better] Have your java code get the data and send it to your database. If users need the data in Excel, you can have Excel query the database when required.
Note: with a typical Bloomberg Terminal/Anywhere license, it is not permitted to save data on a different machine so the database would need to be located on the local PC. Other licenses have different terms.
I think you should look into using Bloomberg's API v3 to retrieve the data. You have access to any field which you see in FLDS on the Bloomberg terminal.
I need to make a data file to hold two empty tables with many fields
I have been successful at making a MySQL 5.5 Table with its DOS style IDE OK.
And MySQL registers with NetBeans very well.
Can I make a script to build this from with in my program
or can this be done directly in Java and get a Java file to read file parameters as its executed to create the data base file name.
I have no idea what direction to take to do this and what's possible.
I'm writing in Java and Delphi and Delphi has no MySQL support.
Has any one done anything similar before and how did they do it
The database is to hold 70 meduim size pictures, How slow will updates be when accessing pictures and should I use JPEG or BMP storage for wireless Java apps?
Can Java manage JPEG files and display them?
Lots of questions in one post. Let me try to address each point individually.
Yes, you can write Java code to create your MySQL database for you. On the other hand, tools such Liquibase can do this for you—you just need to learn its XML configuration syntax.
Lots of people have successfully written Java and Delphi code to access MySQL databases. If I recall correctly, at the very least Delphi supports MySQL access through ODBC, if not, through 3rd-party custom components.
Java can store & retrieve JPEG images to/from a database just like any other language, though, in practice, I wouldn't do it that way. Rather, I'd store the images themselves in the file system and just store their locations in the database. RDBMSes weren't really built with handling large binary BLOBs in mind.
How would you like to display the images? If on screen via a desktop client, then, yes, Java's Swing components can easily and readily display JPEG, even GIF & PNG images. If via a Web browser or remote client, then it's really just a matter of serving the images over HTTP to the browser/client app.
I am developing an internal system that is intended to work very much like Google Docs. The main piece I am implementing mimics their web-based Spreadsheet implementation. For multiple reasons I am not able to use Google Docs or ZK, which has a very robust Spreadsheet API. I chose POI 3.7 as a starting point for my Excel spreadsheet processing.
Currently when a user uploads an Excel spreadsheet, I take the file byte[] and store it in our db as a blob. When a user wants to view the spreadsheet, I pull out the byte[], build the Workbook, and push it to the client UI for editing. The pushing to the UI isn't my concern. When a user makes edits to the spreadsheet, I push the edits to the server and store them on a stack and only apply the updates when the user presses the "save" button. On save, I pull the workbook back out of the database, make the changes and push the Workbook back to the db. That way, I don't keep it in memory. It's no surprise that all of this is pretty fast except for when multiple users start doing this, obviously exploding Workbooks eats memory as described in other posts here.
A user will only update one tab at a time, why should I need to open the entire workbook? When a user initially uploads an excel spreadsheet, can I pull out each Sheet, convert each to a byte[] and save each as an indiviaual "worksheet" db record? The POI Sheet has a protected, "#write(Stream)" method but I would not like to get into the business of re-compiling POI. I also would not like to explode every cell as a new db entry. Would you guys do this differently in the first place?
Backend is java/spring/jdbc. For internal reasons, these are the technologies I'm stuck using.
Storing big binary blobs in the database is in itself not a good thing if performance is important. You would be much better off storing the workbooks on the disk.
I can only give you half an answer to your question and that is that you can read xslx (not xsl) files one sheet at a time using (http://poi.apache.org/apidocs/index.html?org/apache/poi/xssf/eventusermodel/XSSFReader.html) and that you can use a SAXParser to avoid holding each full sheet in memory. I don't think there is any way of saving it without creating a sheet object.
Warning Hack: One quick hack could be to use reflection to call the protected method. There is of course no guarantee that this will work in future versions of POI.
With Excel files, some things are stored at the sheet level, but other bits are stored at the workbook level. As your user edits a sheet, while most of their changes will be on the sheet part, some bits will need to touch the workbook level entities, and for that you'll need the whole file.
You might want to take a look at how SharePoint does its collaborative editing, which allows several people using Excel to work on the same file much like google docs. All the SharePoint protocol documents are publicly available, and there was an event on the docs very recently for which videos and presentations should be online soon, keep an eye on the office interop blog for when they do. In the SharePoint docs you should find the details on how Microsoft chunks up an Excel file for collaborative editing, and there's something to be said for you doing the same!
I would consider looking into saving the sheets as separate XML's in the database. If you store additional (meta)data about sheets belonging together in the database it shouldn't be too much hassle keeping them together. The reason behind using XML is that from Excel 2003 up spreadsheets can be saved as xml and therefor can easily be created by code as well.
If at one point you seem to be hitting too many walls with Apache POI, you could look into the OpenOffice API as well.
I have an excel file that pulls in data via data connection from bunch of CSV files. The CSV files are generated every now so often by a JAVA program.
Is it possible to refresh the data too via. JAVA program? I see JXCELAPI and JOI are there, but briefly looking at their documentation doesn't indicate my use case is even possible.
In short, I need API that could achieve this effect: clicking on menu Data->Refresh All.
Thanks,
_Madhu
You could try XLLoop. This lets your spreadsheet talk directly to a java server (or a number of other languages) via function calls.
So you can have your spreadsheet call eg GetMyData("somedata") and it will load the data directly from your server whenever you re-calc (ie. Shift-F9).
BTW, I work on the project so let me know if you have any questions.
This tutorial sounds like it might help: Accessing Excel from Java
You could also try Obba which is another solution to access a Java library via Excel cell functions (UDFs)...
However, what you describe could also be done by a very small vb/vba macro which checks/polls for modification of these CVS files. I don't know if this is suitable in your situation, but there is an event listener for that: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed.aspx#Y0