简体   繁体   中英

Open Excel Workbook with vba code - error to notify VSTO

I am trying to open an Excel file from my C# code.

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. I have kept the display property to true and that is when I noticed that there is an error in the excel. On further investigation I got to know that the error is caused due to some vba code in the excel which is failing. 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?

What do you try to achive? Maybe just using the Microsoft Open XML SDK would be enough?
You can read, create and edit Excel files with it.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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