Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Removing Trailing spaces from Excel using asp.net

 
Thread Tools Search this Thread
Old 01-13-2005, 12:28 AM   #1
Default Removing Trailing spaces from Excel using asp.net




Hi All,
I have an Excel issue which I am unable to solve for the past couple of
days.
I have a printable version of a report , which uses the basic
Response.ContentType="application/vnd.ms-excel"; to give the report in
excel.
Now one of the fields is numeric, but Excel adds a trailing space to
every number, hence that column does not give a sum. Is there any way to
remove these trailing spaces via .net?
Thanks,
Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Ben
  Reply With Quote
Old 01-13-2005, 06:44 AM   #2
jongalloway
 
Posts: n/a
Default Re: Removing Trailing spaces from Excel using asp.net
The best way to do this is to tell Excel the cell is a numeric value by
adding the format attribute x:num to the TD tag:
<td x:num> 42 </td>

- Jon
http://weblogs.asp.net/jgalloway



jongalloway
  Reply With Quote
Old 01-14-2005, 11:58 PM   #3
Ben
 
Posts: n/a
Default Re: Removing Trailing spaces from Excel using asp.net


To give you a more clear pciture of my problem....
I have an aspx page with a repeater and the datasourse is a datatable,
since i have a simeple html output and an excel output, i only specify
the application type, depending on which option the user wants to see.So
my question is...how to do i specify in my code to format the cells of
the worksheet?
Thanks,
Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Ben
  Reply With Quote
Old 01-15-2005, 12:32 AM   #4
jongalloway
 
Posts: n/a
Default Re: Removing Trailing spaces from Excel using asp.net
Here's an example:

<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr bgcolor="#ffcc99">
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Salary</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="#ffcccc">
<td><%# DataBinder.Eval(Container.DataItem, "au_id") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "au_fname") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "au_lname") %></td>
<td x:num><%# DataBinder.Eval(Container.DataItem, "salary")
%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

Note that the salary field td tag includes x:num.
- Jon
http://weblogs.asp.net/jgalloway



jongalloway
  Reply With Quote
Old 01-15-2005, 01:33 AM   #5
Ben
 
Posts: n/a
Default Re: Removing Trailing spaces from Excel using asp.net


Tried adding x:num formatting to the table....doe snot remove the
trailing spaces. Also if i see the format cells, it says general and not
numeric.Any idea?
Thanks,
Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Ben
  Reply With Quote
Old 01-16-2005, 06:56 PM   #6
jongalloway
 
Posts: n/a
Default Re: Removing Trailing spaces from Excel using asp.net
If you're mostly concerned about trimming spaces, you can just use the
string.Trim() method:

<%# Convert.ToString(DataBinder.Eval(Container.DataIte m,
"salary")).Trim() %>

For the x:num formatting to work, it needs to be applied to every table
cell (<td>), not to the entire table. Also, I think your HTML tag on
the ASPX page needs to include the excel namespace:
<html xmlns="urn:schemas-microsoft-comffice:excel"
xmlns="http://www.w3.org/TR/REC-html40">

Sorry I left that out before - I can't find my sample code that does
this.

- Jon
http://weblogs.asp.net/jgalloway



jongalloway
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46