简体   繁体   中英

Formatting - add comma, 2 decimal places to cell values vb.net excel interop

Does anyone have any vb.net or vba code that will format excel values or a range of cells to have comma for 100s, 1000s,10000s etc.. and 2 decimal places only.

ie 10,256.45

With a reference to the range:

rng.NumberFormat = "#,##0.00"

The current selection is also a range, so if you want it to work with the selection, just use:

Selection.NumberFormat = "#,##0.00"

If you don't need a specific custom formatting you can use Excel styles :

allRange.Style = "Comma"; // 1234.5678 -> 1,234.56
// or
allRange.Style = "Comma [0]"; // 1234.5678 -> 1,234

如果您使用的是OfficeOpenXml excel范围,请执行此操作

rng.Style.Numberformat.Format = "##0.00";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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