如何使用数字格式将数据集导出到Excel [英] how to export data set to excel using number Format
本文介绍了如何使用数字格式将数据集导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要导出数据集:
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( 今天, 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 ));
然后我将数据添加到每个表中.. 。
table01.Rows.Add(A,0,84100,2,null,9);
所以我需要将它们导出到带有数字格式和逗号分隔符的Excel工作表。
当值= -200000时将是(200,000)红色,值300000将是300,000并将其应用于工作表中的每个表。有关详细信息,请查看以下照片: http://postimg.org/image/lj55lz6ib/ [ ^ ]
解决方案
你可以使用
工作表(Sheet1)。范围(A1)。公式==文本(值,#,## 0.000;(#,## 0.000);)
为值= -200000将为(200,000)格式和颜色
和
如果值< ; 0然后
工作表(Sheet1)。范围(A1)。Interior.Color = RGB(255,y,x)
结束如果
I need to export a data set:
DataSet ds = new DataSet("tabless"); ds.Tables.Add(table01); ds.Tables.Add(table02); ds.Tables.Add(table03);
it contains 3 data table, each one of them is:
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));
then i added data to each table ...
table01.Rows.Add("A", 0, 84100, 2, null, 9);
So I need to export them to an excel sheet with number format and comma separator.
Like when value = -200000 will be (200,000) with red color and value 300000 will be 300,000 and apply this to each table in the work sheet. For more info check the below photo:http://postimg.org/image/lj55lz6ib/[^]
解决方案
you could use
Worksheets("Sheet1").Range("A1").Formula = "=Text(value, ""#,##0.000;(#,##0.000);"")"
for value = -200000 will be (200,000) format and for color
and
if value <0 then
Worksheets("Sheet1").Range("A1").Interior.Color = RGB(255, y, x)
end if
这篇关于如何使用数字格式将数据集导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文