我正在修改用 vb.net 编写的现有应用程序。 有一个导出选项,可将信息导出到 Excel 工作表。 导出之前,单元格格式定义如下。
.Cells(cRow, 17).NumberFormat = "$#,##0.00_);($#,##0.00)"
这工作正常。但根据新的要求,货币符号是动态的。 因此,一旦我设置了货币(例如:马来西亚瑞 git -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)"
所有人都给我同样的错误。 有人请让我知道如何设置自定义货币符号。 谢谢
最佳答案
如果我没记错的话,EXCEL 数字格式中的任何字符都必须用引号引起来,因此:
Dim strCurrency As String = ""
strCurrency = "SGD"
.Cells(cRow, 17).NumberFormat = """"+strCurrency +"""#,##0.00_);("""+strCurrency +"""#,##0.00)"
关于vb.net - 如何在vb.net中设置Excel单元格格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30297272/