Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7158835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:07:56+00:00 2026-05-28T13:07:56+00:00

I already did some search here on SO, on this , this , this

  • 0

I already did some search here on SO, on this, this, this and more, but no clue, so I’m going to have to ask you guys.

I’m trying to open an Excel file via Interop, and I have Office 2007 installed, so I’m using Microsoft.Office.Interop.Excel version 14.0.

When I try to open a valid xls file, everything runs fine.

But if I try to open an invalid file (like a bitmap, or an executable) via Interop, Excel opens it without complain or warning.

How can I detect Excel has an invalid workbook file loaded, without blocking with an alert ?

I’m trying to write a unit test of my Excel object reader. One of the cases is to try to open an invalid file.

Some code to help:
Application Creation:

    _app = new Application()
        {
            Visible = false,
            DisplayAlerts = false,     // <-- I don't want to remove this.
            AskToUpdateLinks = false,
        };

Workbook opening:

   _workbooks.Open(filename);
   _workbook = _workbooks.get_Item(1); // 1-based.
   _worksheets = _workbook.Sheets;

EDIT:
Just to add 1 more information: Excel loads the invalid file. If DisplayAlerts is set to true, it complains (open a dialog) informing the workbook seems to be corrupted, but if DisplayAlerts is set to false, it loads the file just as below:

Excel Loads Invalid File

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:07:56+00:00Added an answer on May 28, 2026 at 1:07 pm

    I just ended using another approach: Excel workbooks have a property called FileFormat. When Excel opens an invalid file, it sets the file format to one of the enumerator values of text:

        XlFileFormat.xlTextMac
        XlFileFormat.xlTextMSDOS
        XlFileFormat.xlTextPrinter
        XlFileFormat.xlTextWindows
    

    And inside this enumeration Excel has the valid files (valid for my purpose):

        XlFileFormat.xlExcel12
        XlFileFormat.xlExcel7
        XlFileFormat.xlExcel8
        XlFileFormat.xlExcel9795
    

    So I ended using a simple “or” to filter the kind of file I’d like to import:

        bool validFile = ( f == XlFileFormat.xlExcel12   ) 
                      || ( f == XlFileFormat.xlExcel7    ) 
                      || ( f == XlFileFormat.xlExcel8    ) 
                      || ( f == XlFileFormat.xlExcel9795 );
    

    And now it works. Thanks for your help guys, you set me in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this has been asked already, I've did a google search and couldn't
I did do some googling and searching on this site but did not find
I already did some research and ended up with several autocomplete boxes which have
I already did a lot of research on this topic and have implemented a
I'm trying to install WF with VS2008E. That's what I already did: Go to
There are already a couple of questions on finding cycles, but I did not
Ok, First off, I am not a mysql guru. Second, I did search, but
We are considering Microsoft DSL toolkit for creating some abstract designers. I already did
I'm starting to program. Already did some things with Java: a calculator, one document
I am relatively new to python (already did some 1h scripts like a little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.