Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Exporting html table to excel

Reply
Thread Tools

Exporting html table to excel

 
 
Gobi
Guest
Posts: n/a
 
      06-07-2006
I have a JSP page which contains a 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 this? TIA.
 
Reply With Quote
 
 
 
 
Adrienne Boswell
Guest
Posts: n/a
 
      06-07-2006
Gazing into my crystal ball I observed Gobi <(E-Mail Removed)> writing
in news:RXthg.252277$P01.133600@pd7tw3no:

> I have a JSP page which contains a 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 this? TIA.
>


You could try putting ' infront of the data. That _might_ help.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

 
Reply With Quote
 
 
 
 
Gobi
Guest
Posts: n/a
 
      06-07-2006
Adrienne Boswell wrote:
>
> You could try putting ' infront of the data. That _might_ help.
>


Actually, I tried putting " " + ID and excel still strips the zeros.
This is one time when excel has outsmarted itself. I looked at Options
in excel to try to turn this feature off but can't find anything.

Any other ideas, anybody?
 
Reply With Quote
 
Mark Parnell
Guest
Posts: n/a
 
      06-07-2006
Deciding to do something for the good of humanity, Gobi
<(E-Mail Removed)> declared in alt.html:

> 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.


Adrienne is on the right track. You need to somehow tell Excel to treat
the cell value as a string instead of an integer. If putting quotes
around it doesn't help though, I don't know how you'd achieve that.

--
Mark Parnell
My Usenet is improved; yours could be too:
http://blinkynet.net/comp/uip5.html
 
Reply With Quote
 
Gobi
Guest
Posts: n/a
 
      06-07-2006
Mark Parnell wrote:
> Deciding to do something for the good of humanity, Gobi
> <(E-Mail Removed)> declared in alt.html:
>
> Adrienne is on the right track. You need to somehow tell Excel to treat
> the cell value as a string instead of an integer. If putting quotes
> around it doesn't help though, I don't know how you'd achieve that.
>


Actually, I put a space in front of the data instead of quotes. I was
hoping for a solution where I don't have to modify the data. I am
thinking maybe I can somehow inform excel that this column is a string.
Perhaps something in the <tr>? Or some way to turn off
auto-formatting in excel?
 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      06-07-2006
Gobi wrote:
> I have a JSP page which contains a 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.


This is basically lying. You write some HTML and claim it is an excel
file, you then hope that whatever software the user has configured to
open Excel files is capable of recognising that its recieving HTML and
importing it automatically.

Not generally a good idea.

Your problem would be solved by sending a genuine Excel file to the
client.

 
Reply With Quote
 
Stan McCann
Guest
Posts: n/a
 
      06-07-2006
Gobi <(E-Mail Removed)> wrote in news:nRuhg.253432$WI1.8625@pd7tw2no:

> Mark Parnell wrote:
>> Deciding to do something for the good of humanity, Gobi
>> <(E-Mail Removed)> declared in alt.html:
>>
>> Adrienne is on the right track. You need to somehow tell Excel to
>> treat the cell value as a string instead of an integer. If putting
>> quotes around it doesn't help though, I don't know how you'd
>> achieve that.
>>

>
> Actually, I put a space in front of the data instead of quotes. I
> was hoping for a solution where I don't have to modify the data. I
> am thinking maybe I can somehow inform excel that this column is a
> string.
> Perhaps something in the <tr>? Or some way to turn off
> auto-formatting in excel?
>


As Mark said, Adrienne is on the right track. A space in front won't
do it, use ' and if won't be seen; it's just how you designate the
difference between a string and a number in Excel.

--
Stan McCann, "Uncle Pirate" http://stanmccann.us/
Webmaster, NMSU Alamogordo http://alamo.nmsu.edu/
Implementing http://blinkynet.net/comp/uip5.html
 
Reply With Quote
 
Moochie Moochie is offline
Junior Member
Join Date: Feb 2009
Posts: 1
 
      02-18-2009
Simple add style=""mso-number-format:\@"" to the td .

<td style="mso-number-format:\@">

This tells access to keep leading zeros.
 
Reply With Quote
 
mbalhoot mbalhoot is offline
Junior Member
Join Date: May 2011
Posts: 1
 
      05-18-2011
dear
pleas how i can export table to excel file through link useng jsp
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting to Excel using new version of Excel Doogie ASP .Net 1 11-19-2008 09:10 PM
Exporting HTML table to Excel =?Utf-8?B?c2NobWlkdGU=?= ASP .Net 5 03-22-2007 04:19 PM
Exporting datagrid to Excel Pivot Table =?Utf-8?B?VGltX2s=?= ASP .Net 0 01-26-2005 06:23 PM
exporting an excel file from database; making changes to excel file and updating the database by importing it back Luis Esteban Valencia ASP .Net 1 01-12-2005 12:28 AM
Exporting HTML Table to Excel? M P ASP General 2 07-17-2004 11:52 PM



Advertisments