繁体   English   中英

用数字格式将数据表导出到Excel工作表

[英]Export data table to excel sheet with number format

我需要导出数据集:

DataSet ds = new DataSet("tabless");
ds.Tables.Add(table01);
ds.Tables.Add(table02);
ds.Tables.Add(table03);

它包含3个数据表,每个数据表是:

table01.Columns.Add("Branch",typeof(string));
table01.Columns.Add("Today", typeof(double));
table01.Columns.Add("MTD",typeof(double));
table01.Columns.Add("LM",typeof(double));
table01.Columns.Add("Differ",typeof(double),"LM-MTD");
table01.Columns.Add("YTD",typeof(double)); 

所以我需要将它们导出到具有数字格式和逗号分隔符的Excel工作表中。
就像值= -200000将是(200,000)为红色,值300000将为300,000并将其应用于工作表中的每个表一样。 有关更多信息,请查看下面的照片:

截图http://postimg.org/image/lj55lz6ib/

您可以使用NumberingFormat

        //Create a NumberingFormat 
        NumberingFormat numForm2decim = new NumberingFormat();
        numForm2decim.NumberFormatId = 1u;
        numForm2decim.FormatCode = StringValue.FromString("0.00");  

        //Use it in a CellFormat
        CellFormat cellformatNumber2Decim = new CellFormat();            
        cellformatNumber2Decim.NumberFormatId = numForm2decim.NumberFormatId;
        cellformatNumber2Decim.ApplyNumberFormat = true;

        //And apply the cellFormat to your Cell throw the StyleIndex Property

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM