我目前正在尝试编写一个从 fileA 获取值并与 file1 结合的加载项。但是,由于以前的所有者使用 VBA 编写的代码,fileA 需要 fileB,fileB 需要 fileC。我只需要 fileA 中的某个工作表,但是当调用 open 到 fileA 时,它也会打开 fileB 和 fileC。
有没有一种方法可以打开 fileA 或复制 fileA 而无需打开其他文件,即忽略依赖性?我尝试在线搜索它,但给出的大多数问题和解决方案都是针对没有依赖性的文件。
我将 Visual Studio 2017 与 Excel 2013 和 2016 VSTO 加载项项目结合使用。
感谢任何帮助。
注意:我不允许编辑 VBA 代码,我不需要更新 fileA 中的值。
最佳答案
尝试在禁用 AutomationSecurity
的情况下打开文件:
Excel.Application app = new Excel.Application();
app.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
Workbook wb = app.Workbooks.Open(path);
关于C#Excel : Programmatically open and copy workbook while ignoring dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54179037/