我正在修改用vb.net编写的现有应用程序。有一个导出选项,它将信息导出到excel工作表。导出之前,单元格格式定义如下。
.Cells(cRow, 17).NumberFormat = "$#,##0.00_);($#,##0.00)"
这个很好用。但根据新的要求,货币符号是动态的。因此,一旦我设置了货币(例如:马来西亚里吉特-MYR),
.Cells(cRow, 17).NumberFormat = "MYR#,##0.00_);(MYR#,##0.00)"
这会产生一个错误“无法设置Range类的NumberFormat属性”。可能有很多种货币,我试着用一个变量来设置货币。
Dim strCurrency As String = ""
strCurrency = "SGD"
.Cells(cRow, 17).NumberFormat = ""+strCurrency +"#,##0.00_);("+strCurrency +"#,##0.00)"
所有人都给了我同样的错误。有人请让我知道如何设置自定义货币符号。谢谢
发布于 2015-05-17 23:40:48
如果我没有弄错,EXCEL数字格式中的任何字符都必须用引号括起来,因此:
Dim strCurrency As String = ""
strCurrency = "SGD"
.Cells(cRow, 17).NumberFormat = """"+strCurrency +"""#,##0.00_);("""+strCurrency +"""#,##0.00)"
发布于 2015-05-18 04:07:58
使用这个
.Cells(cRow, 17).NumberFormat = strCurrency & "#,##0.00_);(" & strCurrency & "#,##0.00)"
没有必要使用被接受的答案中所示的这么多引号。
解释
你的绳子
"MYR#,##0.00_);(MYR#,##0.00)"
也可以写成
"MYR" & "#,##0.00_);(" & "MYR" & "#,##0.00)"
现在,只需将"MYR"
替换为变量
发布于 2015-05-18 00:12:37
将货币符号括在引号内:
Dim strCurrency = Chr(34) & "SGD" & Chr(34)
.Cells(cRow, 17).NumberFormat = String.Format("{0}#,##0.00_);({0}#,##0.00)", strCurrency)
Chr(34)
= "
https://stackoverflow.com/questions/30297272
复制