Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML export to excel - losing leading zeros and date format 1

Status
Not open for further replies.

LadyDragon

Programmer
Jan 14, 2004
24
0
0
US
HTML export to excel - losing leading zeros and date format

Hi! I'm hoping someone can help me - I've searched the archives and haven't found this exact issue.

I have an application that I've inherited where a dataset is exporting via an html table to an excel spreadsheet. This process is dropping leading zeros and modifying hyphenated numbers to dates and I don't know how to fix this. I've tried adding '=' in front of the data in the table, but it shows the symbol. Any help you can offer would be fantastic!

I'm using Visual Studio C# and ADO.net:

This is a code snippet that is creating the html output:
Code:
StringBuilder sb_row = new StringBuilder(20000);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
	sb_row.Append("<tr>");
	for (int x = 0; x < ccnt; x++)
        {
           sb_row.Append("<td>" + ds.Tables[0].Rows[i][x].ToString() + "</td>" );
        }
        sb_row.Append("</tr>");
        _sb.Append(sb_row.ToString());
        sb_row = new StringBuilder(20000);
}
 
sometimes the presence of a space can give you what you need...
Code:
 sb_row.Append("<td>[b]&nbsp;[/b]" + ds.Tables[0].Rows[i][x].ToString() + "</td>" );

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top