【问题标题】:Export data table to excel sheet with number format将数据表导出为数字格式的excel表
【发布时间】:2015-02-24 15:35:59
【问题描述】:

我需要导出一个数据集:

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 表中。
就像当 value = -200000 将是 (200,000) 时带有红色并且 value 300000 将是 300,000 并将其应用于工作表中的每个表。 欲了解更多信息,请查看以下照片:

Screenshot http://postimg.org/image/lj55lz6ib/

【问题讨论】:

  • 您现在如何导出到 Excel?
  • 你可以使用像 ClosedXML 或 EPPlus 这样的框架
  • @T.Glatzer 如何使用它可以给我一个例子.. ??

标签: c# excel datatable export-to-excel


【解决方案1】:

你可以使用 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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 2022-08-11
  • 1970-01-01
  • 2011-08-27
  • 1970-01-01
相关资源
最近更新 更多