Excel interop adding slashes in my number formatti

2019-09-01 19:11发布

I'm trying to set a number format (South African Rand currency, no decimals) to a range like so:

range.NumberFormat = "_ R * # ##0_;";

where range is of type Microsoft.Office.Interop.Excel.Range

however when I open the spreadsheet and check the formatting string by choosing custom format the string now looks like this:

_ \R * #\ ##0_;

and these added slashes means that only the first thousand separator (a space) is present and the rest are left off.

I've also tried this:

range.NumberFormat = @"_ R * # ##0_;";

I tried MSDN but this paricular doc reads like gibberish to me: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.numberformat.aspx

but it does the same thing. Anyone know how to prevent this from happening?

1条回答
劳资没心,怎么记你
2楼-- · 2019-09-01 19:50

Setting NumberFormatLocal property seems to have solved it for me:

range.NumberFormatLocal = "_ R * # ##0_;";

No idea why though... and happy to accept a more complete answer that explains why there is a problem and why this fixes it.

查看更多
登录 后发表回答