Open Excel Workbook with vba code - error to notif

2019-09-16 11:19发布

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?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-09-16 11:51

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-09-16 11:51

Another alternative to using the intreop library is http://code.google.com/p/excellibrary/ which doesn't require you to have excel or the excel.dll installed and registered to your machine or server that you are putting it on.

查看更多
登录 后发表回答