c# - 为什么即使我打开了 Excel 工作簿,Excel Application.Workbooks.Count 仍显示为零

标签 c# excel office-interop excel-interop office-addins

ExcelApplication.Workbooks.Count 显示 count = 0 即使我打开了一个文档。

ExcelApplication.Workbooks.Count 当打开的文档不在 protected View 中时显示计数 = 1。但是,当打开的文档是 PROTECTED VIEW 时,ExcelApplication.Workbooks.Count 显示 0。

为什么在 protected View excel 中工作簿计数为 0?

最佳答案

Because :

A workbook displayed in a Protected View window is not a member of the Workbooks collection.

如果您需要处理 protected 工作簿:

using (var protectedWorkbook = ExcelApplication.ProtectedViewWindows(1).Workbook)
{
    // do stuff 
}

一个可靠的解决方案将考虑多个 ProtectedViewWindows 的可能故障情况。上面的代码假设只有一个。

关于c# - 为什么即使我打开了 Excel 工作簿,Excel Application.Workbooks.Count 仍显示为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58458188/

相关文章:

c# - 如何从c#代码中调用java中的方法?

c# - 更改 Treeview WPF 中特定元素的颜色

vba - 如何在 VBA 中自动中断和重新启动代码执行?错误处理

excel - 有没有关于如何在Excel中通过VBA驱动Office "Equation Editor"的文档?

sharepoint - 将凭据传递给 Word Interop 以在 SharePoint 中打开文档

c# - Documents.Close 使 Word 可见

c# - Bloomberglp.Blpapi.RequestQueueOverflowException : Queue Size: 128

c# - 错误 CS1002 : ; Expected -- I have a semicolon. :(

python - 调整 Excel 单元格大小以适合图像

excel - 有没有办法告诉 PowerPoint 在创建图表时不要打开 Excel?