Here's the problem:
Run a java client as a batch job on a unix box which will connect to Oracle and fetch some data.
Update an excel sheet (on a Windows machine) with the data fetched.
Create a chart/graph from the data in excel sheet.
Send the excel (with data & graph) in an email.
All the above steps must be performed without any manual intervention.
Could there be a better option to excel based solution? The main intent is to have a history of data fetched and have a chart created from that data.
I know there are many open source libraries available for creating charts like JFreeChart, but is there anything in the JDK that allows you to create charts? Could JavaFX be used for this problem?
In short, is it possible to do this with just jdk (without using any open source libraries)?
Any help/suggestion will be appreciated.
You could try google docs spread sheet api to workaround MS-Excel
I think all that is pretty doable from Google docs, and yet, you still have the option of downloading the spread sheet.
From the link:
Spreadsheets Data API
The Spreadsheets Data API lets you access worksheet data within your own application or website. You can view and modify data, create and delete worksheets, issue structured queries, and more.
Spreadsheets Gadgets & Visualization API
Spreadsheets Gadgets take advantage of the Google Visualization API to embed graphical comparisons of of structured data within a spreadsheet.
Sounds like what you need.
Pretty straightforward, just use Hibernate or even jdbc.
You should be able to update the Excel sheet with Apache POI. You could also try Java Excel Designer or http://www.moyosoft.com/jec/
At least one of the above should be able to create charts.
Just use Java Mail
You could wrap the above in ANT tasks as appropriate.
Related
Is there any way to update excel content in background when the sheet is in open state.
I am using Apache POI Spreadsheet API (java based API) to read and write content in excel sheet.
By using user API, I am saving data to excel sheet, but I didn't find any API to update excel data in background(without closing excel file, content should be updated).
If we try to update excel when it's open it'll show error like file is accessed by other resource.
Please help me to find an API to achieve this by using Apache POI or any other API.
(I observed by using VB script we can achieve this. but first preference is Java, if there is no other API available then VB Script).
Excel puts a lock on the file and thus actively prevents other applications from changing the file, so I don't think this is possible with any library.
I has a excel file with 4 excel sheets in it. Now i want to read or write to required excel sheets using java without using any third party lib.
I know i can read and write data using FileInputStream and FileOutputStream respecitvely. But i can handle the work sheets??
No, you can'not, There is numerous way in Java for reading/writing files, but there is no built-in support for MS Office/Excel spreadsheets. http://poi.apache.org/ - is a key to victory.
If your goal is to interface with data from an excel sheet from your Java application, I'd suggest to use the solutions suggested by other posters, it will save you a lot of work.
If, however, you want to be able to read excel files from Java (or any other programming language for that matter) 'just because you can' then you could take a look at this file and read the instructions on this web-page. I would warn you that it would take considerably more time to implement your own API if you base it only on the file-specs that are publicly available. You might want to check out the work done by the people from the Apache POI project to get an idea of how to approach it. Or (even better) contribute to the project. Here you can find out how to go about doing that
I am having a database in .dbf (FoxPro) format.
How to retrieve data from FoxPro using Java?
If the data can be migrated to MySQL, How to do the conversion?
Taking the data to intermediate formats seems flawed as there are limitation with memo fields and CSV or Excel files.
If you are interested in a more direct approach you could consider something like "VFP2MySQL Data Upload program" or "Stru2MySQL_2", both written by Visual FoxPro developers. Search for them on this download page:
http://leafe.com/dls/vfp
DB-Convert (http://dbconvert.com/convert-foxpro-to-mysql-sync.php) is a commercial product that you might find helpful.
Rick Schummer, VFP MVP
You can use XBaseJ to access (and even modify write) data from FoxPro databases directly from Java with simple API.
This would allow you to have the two applications (the old FoxPro and the new Java one) side by side by constantly synchronizing the data until the new application is ready to replace the old one (e.g. many times the customers still hang on and trust more their old application for a while).
Do you have a copy of FoxPro? You can save the database as an HTML file, if you want. Then, from HTML, you can save to any format you want. I recently did this to save a FoxPro table as an Excel spreadsheet (not that I'd suggest using that for your Java code).
If you plan on using Java, once you have access to the data, why not use one of Java's native storage types?
I worked on the same project once long back where the project had be done with FoxPro and then we migrated that project to Java with MySQL.
We had the data in Excel sheets or .txt files, so we created tables as exact replica of the FoxPro data and transferred the data from the Excel/CSV /txt to MySQL using the Import data feature.
Once we did this, I think further you can take care from MySQL Data.
But remember work will take some time, and we need to be patient.
I suppose doing a CSV export of your FoxPro data and then writing a little Java programme that takes the CSV as input is your best bet. Writing a programme that both connects to FoxPro and MySQL in Java is needlessly complicated, you are doing a one time migration.
By the way PHP could do an excellent job at inserting the data into MySQL too. The main thing is that you get your data in the MySQL schema, so you can use it with your new application (which I assume is in Java.)
Two steps: DBF => CSV and the CSV => MySQL.
To convert DBF(Foxpro tables) to CSV the below link helps a lot
http://1stopit.blogspot.com/2009/06/dbf-to-mysql-conversion-on-windows.html
CSV => MySQL
MySQL itself supports CSV import option (or) to read csv file this link helps
http://www.csvreader.com/java_csv.php
I read the CSV file using Java CsvReader and inserted the records through program. For that i used PreparedSatement with Batch the below link gives samples for that
http://www.codeweblog.com/switch-to-jdbc-oracle-many-data-insert/
I think every business person would like to have excel UI, however they are forced into using web applications that sometimes look like really bad excel.
Are there any frameworks that help build excel ui without VB? I dont mean framework like POI or JExcel that allows you to generate excel reports.
I've seen many applications built using Excel. All of them were clumsy, error prone, and next to impossible to keep up-to-date.
If the end user needs an application to work like Excel for some grid calculations, then give them a tool to do so, or let them use Excel for that portion.
However using Excel / VBA exclusively to develop big Enterprise worthy applications is heading down the wrong road. It might work well for a while, but it won't be long before issues expose the weak points.
Since you ended talking about reports... yes, by all means have your application export to CSV, HTML, PDF, Excel etc. That way the user that wants to use Excel to generate pretty pie charts, and reformat/search/scan/crop the data can do so with the tool they feel comfortable with.
A combination of the two can work quite well... Excel is not great for inputting data, this is where an app (desktop or web) works better, but excel is great for dynamic reports and analyzing data.
The best approach for dynamic reports I've seen is to write add-ins that add new functions to excel (e.g. to pull in real time data). in the java space you could try XLLoop - this allows you to expose POJO functions in excel (full disclosure: I work on this project).
Obba is an Excel Add-In which allows to instantiate Java objects and work with them directly in Excel (without VBA or any other glue code).
The nice part is that it is fully transparent what the Excel Sheet (UI) does to your Java classes.
I am not sure what you mean by UI here, but if it is for the data presentation (as not data input) you could e.g use SQL Server Reporting Services and export the results to excel format. Alternatively you can parse your data into excel xml format and allow the user to open it as excel file (that is a bit painful though if your data is more complex than a simple table)
EDIT
I went through a pain of presenting and processing data with the use of excel when creating a web system that was replacing old paper work based one - that was a requirement for a transition time.
It is a real pain, all the data validation, ensuring that what is submitted back has not been modified structurewise etc.
My conclusion would be:
use the web system for inputing data
if required provide the excel format for reporting
if really, really required you could implement parsing excel into the web system for inputing data, but then add some human validation as it is humanly impossible to predict all the possible errors one can create in excel
You can look into embedding Excel as an ActiveX control into your application. It will allow you to manipulate the control from your language of choice.
This may point you in the right direction: http://j-integra.intrinsyc.com/support/kb/Article.aspx?id=30421
For java,this one is pretty good.
http://www.jxcell.net
The interop library is slow and needs MS Office installed.
Many times you don't want to install MS Office on servers.
I'd like to use Apache POI, but I'm on .NET.
I need only to extract the text portion of the files, not creating nor "storing information" in Office files.
I need to tell you that I've got a very large document library, and I can't convert it to newer XML files.
I don't want to write a parser for the binaries files.
A library like Apache POI does this for us. Unfortunately, it is only for the Java platform. Maybe I should consider writing this application in Java.
I am still not finding an open source alternative to POI in .NET, I think I'll write my own application in Java.
For all MS Office versions:
You could use the third-party components like TX Text Controls for Word and TMS Flexcel Studio for Excel
For the new Office (2007):
You could do some basic stuff using .net functionality from system.io.packaging. See how at http://msdn.microsoft.com/en-us/library/bb332058.aspx
For the old Office (before 2007):
The old Office formats are now documented: http://www.microsoft.com/interop/docs/officebinaryformats.mspx. If you want to do something really easy you might consider trying it. But be aware that these formats are VERY complex.
Check out the Aspose components. They are designed to mimic the Interop functionality without requiring a full Office install on a server.
As the new docx formats are inherently XML based files, you can create and manipulate them programmatically with standard XML DOM techniques, once you know the structure.
The files are basically zip archives with an alternate file extension. Use the System.IO.Packaging namespace to get access to the internal elements of the file, then open them into a XmlDocument to perform the manipulation.
There are examples available for doing this, and the Office Open XML project on SourceForge may be worth looking at for inspiration.
As for the older binary formats, these were proprietary to MS, and the only way you're likely to get at the content from within is through the Office object model (requires an Office install), or a third party file converter/parser.
Unfortunately there's nothing first party and native to the .NET platform to work with these files.
What do you need to do with those file? If you just want to stream them to the user, then the basic file streams are fine. If you want to create new files (perhaps based on a template) to send to the user that the user can open in Office, there are a variety or work-arounds.
If you're actually keeping data in Office documents for use by your web site, you're doing it wrong. Office documents, even Excel spreadsheets and access databases, are not really an appropriate choice for use with an interactive web site.
If the document is in word 2007 format, you can use the system.io.packaging library to interact with it programatically.
RWendi
In Java world, there is also JExcelApi. It is very clearly written, from what I was able to see, much cleaner then POI. So maybe even a port of that code to .NET is not out of the question, depending of course you have enough of time on your hands.
OpenOffice.
You can program against it and have it do a lot for you, without spending the money on a license for the server, or have the vulnerability associated with it on your server.
Microsoft Excel workbooks can be read using an ODBC driver (or is it an OLE DB driver? can't remember) that makes the workbook look like a database table. But I don't know whether that driver is available without the Office Suite itself.
You can use OpenOffice. It has a command-line conversion tool:
Conversion Howto
In short, you define a macro in OpenOffice and you call that macro with a command-line
argument to OpenOffice. In that argument the name of the local file (the Office file) is
encoded.
It's not a great sollution, but it should be workable.