Removing Trailing spaces from Excel using asp.net

B

Ben

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
 
B

Ben

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
 
J

jongalloway

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
 
B

Ben

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
 
J

jongalloway

If you're mostly concerned about trimming spaces, you can just use the
string.Trim() method:

<%# Convert.ToString(DataBinder.Eval(Container.DataItem,
"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:x="urn:schemas-microsoft-com:eek:ffice: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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top