[英]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並將其應用於工作表中的每個表一樣。 有關更多信息,請查看下面的照片:
您可以使用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.