简体   繁体   中英

C# can't open excel file

When trying to run these lines:

var app = new Excel.Application();
Excel.Workbook workbook = app.Workbooks.Open(pathToFile, Type.Missing, true, Type.Missing, Type.Missing,
                                                   Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                   Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

I've got these problems:

1) I'm getting a message of "file conversion is in progress". Why do I need to convert something if all I want to do is just read a column from one of the work sheets.

2) I'm getting this error message: 在此处输入图片说明

why do I need to care which version created the excel?

3) In the very end I get an exception: "Too many different cell formats".

So is there something wrong with the way I'm using the open workbook method or is there another way to read a specific column from an excel file which contains several sheets and I only need to read data from a single specific sheet?

It might not be obvious to you but calling

new Excel.Application()

opens an instance of Excel (you may check it on the Task Manager). So if your version of Excel is not compatible with the file you are opening you get this error.

Since you are trying to open the Excel document with your Excel application, you DO care of what versions they are.

I think OpenXML SDK could help you with it.

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