在未安装 excel 的情况下使用 VB.NET 阅读 Excel

Read Excel using VB.NET without having excel installed

我们有一个 excel 宏,它读取电子表格的内容(无写权限)。

我们需要将代码迁移到 运行 无头服务器端。

为了尽量减少迁移工作,我们考虑使用 Microsoft Interop 重写 VB.NET 中的宏。

Here 建议创建一个 VB.NET 可执行文件 ,它使用 Office Interop 而无需安装 excel。

问题:真的可以吗?我可以在未安装 excel 的情况下使用 Office Interop 执行 VB.NET 来读取电子表格吗?

以下是 MS 对服务器端自动化的说明:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Considerations for server-side Automation of Office 文章中阅读更多相关信息。

如果您只处理打开的 XML 文档,您可以考虑使用 Open XML SDK 作为可能的替代方案。否则,您可以考虑使用不需要安装 Office 的第三方库。

没有安装 MS Office 就无法使用互操作程序集(互操作来自的应用程序)。

正如评论和许多其他来源中所写,如果没有安装 MS Office,则无法使用 MS 互操作程序集。

我在原问题中提到的proposal似乎是错误的。