开发者

StringWriter problem

I use the following code: (returns an excel obviously)

   Cont开发者_如何学编程rollerContext.HttpContext.Response.ContentType = "application/ms-excel";
   ControllerContext.HttpContext.Response.Write(sw.ToString());
   ControllerContext.HttpContext.Response.End();
   return View();

where sw is a StringWriter in which i create my excel structure(a table). So, sw.ToString() is a table and some tds contains values like 0001234. When i open the excel file i see in those tds 1234, with no zeroes. What must i do to see those zeroes?


What is the file format you're generating? Since you're talking of TDs, I assume that you're working with HTML.

Try to generate XMLSS instead. It allows you to specify most formatting and it's just a plain XML file, so that generating it is not so much of a hassle. (You can get the basic structure by saving a document as "XML Spreadsheet 2003" format)


Haven´t tried this myself, but in Excel if you put a ' before the number, it treats it as a string. Maybe it works...


You can add a css style to the TDs:

As a text:

<style type="text/css">
.number-txt { mso-number-format:\@ }
</style>

<td class="number-txt">0001234<td>

As a number:

<style type="text/css">
.number { mso-number-format:0000000 }
</style>

<td class="number">0001234<td>


Well, one solution would be to write a &nbsp in every td then the value and it looks great.

tw.RenderBeginTag(HtmlTextWriterTag.Td); tw.Write("  ");
tw.Write(value); tw.RenderEndTag();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜