简体   繁体   English

使用vba代码打开Excel工作簿 - 错误通知VSTO

[英]Open Excel Workbook with vba code - error to notify VSTO

I am trying to open an Excel file from my C# code. 我试图从我的C#代码打开一个Excel文件。

workBook = workBooks.Open(fileName,               //filename
                          0,                      //updatelinks
                          true,                   //readonly
                          5,                      //format
                          "",                     //password
                          "",                     //WriteResPassword
                          true,                   //IgnoreReadOnlyRecommended
                          XlPlatform.xlWindows,   //Origin
                          "\t",                   //Delimiter
                          false,                  //Editable
                          false,                  //Notify
                          0,                      //Converter
                          true,                   //AddToMru
                          1,                      //Local
                          0);                     //CorruptLoad

I see that the code hangs at workBooks.Open if the excel has some error within it. 如果excel中有一些错误,我看到代码在workBooks.Open挂起。 I have kept the display property to true and that is when I noticed that there is an error in the excel. 我保持display属性为true,那时我注意到excel中有错误。 On further investigation I got to know that the error is caused due to some vba code in the excel which is failing. 在进一步调查时,我知道错误是由于excel中的一些vba代码失败引起的。 My requirement is how do I get my C# code to be notified about this, so that it can ignore the error within the file or ignore the file itself? 我的要求是如何让我的C#代码得到通知,以便它可以忽略文件中的错误或忽略文件本身?

What do you try to achive? 你尝试做什么? Maybe just using the Microsoft Open XML SDK would be enough? 也许只使用Microsoft Open XML SDK就足够了?
You can read, create and edit Excel files with it. 您可以使用它来阅读,创建和编辑Excel文件。

另一种使用intreop库的替代方法是http://code.google.com/p/excellibrary/ ,它不要求您安装excel或安装excel.dll并将其注册到您正在装入它的计​​算机或服务器上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM