using multiple mso-number-format's when exporting using HttpResponse

M

Mark Iverson

Hi,

I've got the following code to write out a grid to Excel:

private void WriteExcelDataToHttpResponse()
{
Response.Clear();
Response.Charset = "";
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stwWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htwHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(stwWriter);
this.ExcelTable.RenderControl(htwHtmlTextWriter);
string s_styleInfo = @"<style> td { mso-number-format:""" + "\\@" + @"""; }
</style>";
string s_excel = stwWriter.ToString();
Response.Write(s_styleInfo + s_excel);
Response.End();
}

This results in the following in the output file that works perfectly:

..xl24
{mso-style-parent:style0;
mso-number-format:"\@";
white-space:normal;}

Now, every "td" uses this class, like so:

<td class=xl24 width=138 style='width:104pt'>SocialSecurityNumber</td>

I've got something like this to add date to the table prior to exporting it:

row = new HtmlTableRow();
// name column
cell = new HtmlTableCell();
cell.InnerText = HttpUtility.HtmlEncode(s.Name);
row.Cells.Add(cell);
ExcelTable.Rows.Add(row);

My question is, can I specify a different mso-number-format in specific
cells in this code? If so, how? E.g. cell.something =
"mso-number-format:0";

Many thanks!

Mark
 

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

Top