问题描述
ExcelApplication.Workbooks.Count
即使我有打开的文档,也显示count = 0.
ExcelApplication.Workbooks.Count
is showing count = 0 even when I have a document open.
ExcelApplication.Workbooks.Count
显示count = 1.但是,当打开的文档为保护视图时,ExcelApplication.Workbooks.Count
显示为0.
ExcelApplication.Workbooks.Count
shows count = 1 when the document opened is not in protected view. But when the opened document is PROTECTED VIEW the ExcelApplication.Workbooks.Count
shows 0.
在受保护的视图为excel的情况下,为什么工作簿计数为0?
推荐答案
因为:
如果您需要处理受保护的工作簿:
If you need to get a handle on a protected workbook:
using (var protectedWorkbook = ExcelApplication.ProtectedViewWindows(1).Workbook)
{
// do stuff
}
可靠的解决方案将解决多个ProtectedViewWindows
的可能故障情况.上面的代码假定只有一个.
A robust solution would account for the possible fault condition of multiple ProtectedViewWindows
. The above code assumes there is one and only one.
这篇关于为什么即使我打开了Excel工作簿,ExcelApplication.Workbooks.Count仍显示为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!