jQuery in Action, 2nd edition*
The moose likes HTML, CSS and JavaScript and the fly likes Import from and export to Excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Import from and export to Excel" Watch "Import from and export to Excel" New topic
Author

Import from and export to Excel

Adithya Rayaprolu
Ranch Hand

Joined: Jun 19, 2001
Posts: 137
Hi,
We have a table in our page. When user right clicks on the table, a context menu is shown and in that we have two menu items: Export to Excel and Import from Excel. We need the table to be imported from and exported to Excel. Everything should be done at client side. How to do this? I have no idea how the .xls file format would be. How to launch the Excel window when he selects 'Export to Excel'?. When he selects 'Import from Excel', we need to show a browse folder dialog and then he selects the .xls file. How to convert this into the html table?
Thanks a lot in advance.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
it has to be done sever side since javascript has no control over redaing and writing to files. ASP can read excel files and write to them. There may be some active X thing.
<input type="file"> will allow you to browse.
The only hting i think you might be able to do is do it with frames and have the top frame be the info and the bottom frame being the excel sheet.
Adithya Rayaprolu
Ranch Hand

Joined: Jun 19, 2001
Posts: 137
Hi eric,
Thanks for the info. For testing purpose, we created an html table in a text file and named it as test.xls, I wrote a function which has only one line
window.open('test.xls','','resizable=yes,height=475,width=800');
When I call this function from the context menu item, its perfectly showing the excel speadsheet.
I have one more question. In Javascript, we cannot do file reading or writing. So, we have to send the table data to server and let server convert the data into an xls file, and when we receive it, we can show it in excel. How do we send the whole table data to the server?
And in Import from Excel, we will get the file name from the dialog. How do we send the file contents to server, so it can send us the xls file data to a simple html table?
Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
look here: http://www.asp101.com/samples/xl.asp
see if this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Import from and export to Excel