Click to See Complete Forum and Search --> : Exporting html table to excel


gobi
06-07-2006, 02:15 AM
I have a JSP page which contains a html table that I would like to export to excel just by clicking a link. I can do this by specifying:

contentType="application/vnd.ms-excel"

This automatically opens excel and imports the html table directly into it. This is fine for the most part. What my problem is, one of the columns has IDs that has zeros in front (eg. 00001). In the html table, it is displaying fine. But in the excel table it strips the zeros so now my id is 1 when in fact I still want to display it as 00001. Any ideas on how to do modify my html table so that excel won't format the ID? TIA.

Waylander
06-07-2006, 08:59 PM
Html is all text, where as excel is a number program.

Your problem is with excel not your markup, I have no idea how you could force a text type onto a html element... as it is already text...

What you need to do is manipulate the excel spreadsheet at some time. Im not sure if you can do it programatically but you need to set the Cell Format of the column to be the excel text type, because in terms of numbers 000001 is equal to 1.

Some ideas, try do it first with code? I have no experience with this....
Maybe make a template excel file with the right settings and see if it comes out right when you put it in? There are macros to you could try putting the formatting in there if the other ideas dont work.

Waylander.

drspin
06-15-2006, 07:41 AM
Hi goby,

I've been playing around with "excel css" - this may help;
in your html markup generation, try to place this in the <td>
<td style = "mso-number-format:00000;">....etc

The number of 0 is your leading zeroes, hope that helps :)