c# - Excel Interop 将斜杠添加到 NumberFormat

标签 c# excel excel-interop

我想通过 Excel Interop 设置整列的 NumberFormat:

column.NumberFormat = "# ##0";

但是,Excel 添加了一个额外的斜杠(打开文档显示 #\##0)。

我发现了以下相关问题:Excel interop adding slashes in my number formatting string

但是,使用 column.NumberFormatLocal 时,我遇到了一个异常:

Unhandled Exception: System.Runtime.InteropServices.COMException: Unable to set the NumberFormatLocal property of the Range class

有什么想法吗?

最佳答案

我可以通过使用 en-US 分隔符来解决问题:

column.NumberFormat = "#,##0"; // Note the comma

我不确定为什么。我的系统区域设置和我的应用程序的 CultureInfo 都是 de-AT。我的系统千位分隔符也是 de-AT(即空格)。

出于某种原因,Excel Interop 仍然需要 en-US 分隔符。

关于c# - Excel Interop 将斜杠添加到 NumberFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35408328/

相关文章:

C# 像在 C++ 中一样使所有内容都遵循公共(public)/私有(private)?

excel - 用于按下功能区菜单中按钮的宏

excel - 如何将我的第三个可见单元格定义为 B 列中的变量

.net - 将范围对象从 VBA 传递到 .NET 会导致 "Runtime Error 91"

c# - 列出 Visual Studio 2019 中未引用的文件?

c# - 存储和访问常见字符串文字的最佳实践

Excel - 计算两个日期之间每个月的天数

c# - 打开预先存在的 Excel 文件

c# - Microsoft.Interop 对象不会退出或 "release"

C# 自动将 ToLower 应用于方法字符串参数?