导出 Excel:避免去除前导零 [英] Export Excel : Avoid stripping the leading zeros

查看:52
本文介绍了导出 Excel:避免去除前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C#.Net 中将数据导出到 Excel 表格.我有一个列,其中包含00123450098"之类的数据.导出的数据没有第一个零.我想按原样显示数据.

I am Export a data to Excel Sheet in C#.Net. There i am having column which has the data like "00123450098". The data is exported without the first zero's. I want to show the data as it is.

这是我的导出 excel 代码.

Here is my export excel code.

 string style = @"<style> .text { mso-number-format:@; } </style> ";
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.AddHeader(
        "content-disposition", string.Format("attachment; filename={0}", fileName));
    HttpContext.Current.Response.ContentType = "application/ms-excel";
    HtmlForm frm = new HtmlForm();
    ...................
    ...................
     table.RenderControl(htw);
            HttpContext.Current.Response.Write(style);
            //render the htmlwriter into the response
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();

推荐答案

在 Excel 文件中,Numbers 单元格总是去掉前导零,您可以通过单引号设置前导零的数字.即

In Excel file, Numbers cell always strips the leading zeros, you can set numbers with leading zeros by following a single quote. i.e.

00123450098 到 '00123450098

00123450098 to '00123450098

但是,该单元格的格式将更改为文本.如果您生成的 excel 文件有任何公式,其中包含该单元格引用作为数字,那么它将无法按预期工作.

but then, the format for that cell will changes to text. If your generated excel file, have any formula, which is include that cell reference as number then it will not work as expected.

这篇关于导出 Excel:避免去除前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆