开发者

Number Formatting in excel Vb.Net

开发者 https://www.devze.com 2022-12-26 18:32 出处:网络
Can someone give me some code to set the cell of an excel spreadsheet to a number format that use a max of 2 decimal places. Or would it work better it I change the data I am putting into the cell to

Can someone give me some code to set the cell of an excel spreadsheet to a number format that use a max of 2 decimal places. Or would it work better it I change the data I am putting into the cell to a proper format? Here is a sample of data that is going in. Right now i开发者_StackOverflowts going in as a string... col("ADJ").ToString() where col is a DataTable oject.


I'm not sure about VB, but in C# it would be:

worksheet.Cells["C3"].NumberFormat = "0.00"

or

worksheet.Cells["A:Z"].NumberFormat = "0.00"

or

Range.NumberFormat = "0.00"


Here's one way:

Selection.NumberFormat = """R"" #,##0.00;""R"" -#,##0.00"

Another way:

worksheet.Cells(x,y).NumberFormat = """R"" #,##0.00;""R"" -#,##0.00"

NOTE: this may vary with different versions of Excel.


In vb.Net:

worksheet.cellRange("X").NumberFormat="#,##0.00"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号