[英]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. 有没有人有任何vb.net或vba代码将格式化excel值或一系列单元格以逗号为100s,1000s,10000s等..并且只有2位小数。
ie 10,256.45 即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 : 如果您不需要特定的自定义格式,则可以使用Excel样式 :
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";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.