ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using multiple mso-number-format's when exporting using HttpResponse (https://www.excelbanter.com/excel-programming/355591-using-multiple-mso-number-formats-when-exporting-using-httpresponse.html)

Mark Iverson

using multiple mso-number-format's when exporting using HttpResponse
 
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






All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com