locked
How to skip the "this file is not in a recognizable format" dialog when opening a file with Microsoft.Office.Interop.Excel.Application.Workbooks.Open RRS feed

  • Question

  • Hello,

     

    I have search around whole day and I couldn't find the solution. So here it goes.

     

    I am using Microsoft.Office.Interop.Excel.Application.Workbooks.Open(PathOfExcel, Missing.Value, Missing.Value, Missing.Value,
                                Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                Missing.Value, Missing.Value, Missing.Value);

     

    but if the "PathOfExcel" is not a valid excel file, I get that "this file is not in a recognizable format" dialog. The process is running as a service in a server and that dialog is blocking the application.

     

    Is there a way to skip that dialog and throw an exception directly?

     

    Thanks a lot for helping me!!

     

    Jach.

    Tuesday, June 8, 2010 11:00 AM

Answers

  • I can't help you with your immediate issue, but if you aren't aware of it already, please note that automating Office applications on a server is not supported (the ability for dialog boxes to halt the current thread in error conditions is just one of the reasons for this lack of support). Even if you do find a way around your current problem, you might encounter other problems down the road.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by jachyuen Thursday, June 10, 2010 1:00 AM
    Wednesday, June 9, 2010 8:04 PM

All replies

  • I need to add to my question. Since I assume users are evil, I get this result by renaming a binary file (zip, exe, etc) to fakeExcel.xls and open that fakeExcel.xls with the interop.

     

    Please help!

     

    Thanks,

     

    Jach.

    Wednesday, June 9, 2010 9:24 AM
  • Hi,

    I got an exception instead of an error dialog when open an invalid excel file using office interop lib, I'm using Excel 10.0.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, June 9, 2010 9:32 AM
  • Hi Eric:

    Thanks for your reply.

    I am using Office 2003, which is Excel 11, right?

    I get an exception too ("file format is not valid") if I create the fakeExcel.xls out of a word doc (rename doc file to fakeExcel.xls).

    However, I would get that "this file is not in a recognizable format" dialog if I create the fakeExcel.xls from a zip file.

     

    that's what I am struggling with.

     

    Please help.

     

    Thanks,

     

    Jach.

    Wednesday, June 9, 2010 10:04 AM
  • Hi,

    I received error message "Exception from HRESULT: 0x800A03EC" when I try to open an excel file (from a .zip file), still no error dialog, my code snippet:

     

                string filePath = @"d:\test.xlsx";

                Application app = new Application();

                app.Visible = false;

                Workbook book = app.Workbooks.Open(filePath, missObj, missObj, missObj, missObj, missObj, missObj, missObj, missObj, missObj, missObj, missObj, missObj, missObj, missObj);


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, June 9, 2010 10:48 AM
  • I can't help you with your immediate issue, but if you aren't aware of it already, please note that automating Office applications on a server is not supported (the ability for dialog boxes to halt the current thread in error conditions is just one of the reasons for this lack of support). Even if you do find a way around your current problem, you might encounter other problems down the road.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by jachyuen Thursday, June 10, 2010 1:00 AM
    Wednesday, June 9, 2010 8:04 PM