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

  • Home
  • SEARCH
  • 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 6375285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:35:45+00:00 2026-05-25T01:35:45+00:00

I am trying to open an (hundreds actually) excel file(s). I open the application

  • 0

I am trying to open an (hundreds actually) excel file(s). I open the application but want to use the Using() functionality around each of the workbooks I open. Why is this resulting in an error?

using (Excel.Workbook wbXL = appXL.Workbooks.Open(_sourceFullPath, Type.Missing, Excel.XlFileAccess.xlReadOnly))
{
    //stuff with wbXL
}

using gets the red underline and says “‘Microsoft.Office.Interop.excel.Workbook’:Type used in a using statement must be implicitly convertible to ‘System.IDisposable’.

How to make this work?

  • 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-25T01:35:46+00:00Added an answer on May 25, 2026 at 1:35 am

    Pretty much what it says – you can only use using with classes that implement IDisposable, so that under the covers the compiler knows which function to call on finalisation – yourclass.Dispose(). The Excel interop classes don’t implement this.

    So you’ve got two choices:

    1. Write your own wrapper class for Excel.Workbook that implements IDispose and either exposes the object itself to call methods on, or wraps those methods too, e.g.

      public class DisposableWorkbook : IDisposable
      {
          private Excel.Workbook _workbook = null;
      
          public DisposableWorkbook(Excel.Application appXL, String path,
                                    NotSureOfType otherArgument,
                                    Excel.XlFileAccess access)
          {
              _workbook = appXL.Workbooks.Open(path, otherArgument, access);
          }
      
          public Excel.Workbook Workbook
          {
              get { return _workbook; }
          }
      
          public void Dispose()
          {
              if (workbook != null)
              {
                  workbook.Close(Excel.XlSaveAction.xlDoNotSaveChanges,
                                 workbookToClose);
                  workbook = null;
              }
          }
      }
      
      using (DisposableWorkbook dwbXL = new DisposableWorkbook(appXL,
                _sourceFullPath, Type.Missing, Excel.XlFileAccess.xlReadOnly))
      {
           Excel.Workbook wbXL = dwbXL.Workbook;
           // stuff with wbXL
      }
      
    2. Implement using yourself, e.g.

      Excel.Workbook wbXL = null;
      try
      {
          wbxl = appXL.Workbooks.Open(_sourceFullPath, Type.Missing,
                                      Excel.XlFileAccess.xlReadOnly);
          //stuff with wbXL
      }
      finally
      {
          if (wbxl != null) wbxl.Close();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to open a Microsoft Excel file in a C# program using the
im trying to open a file using StreamReader and ive to set a Encoding,
I'm trying to open a file and create a list with each line read
I'm trying to use Excel VBA to write to a text file. I'm doing
I'm trying to open a series of Excel spreadsheets using an instance of Excel
I'm trying open a txt file and read it, but I'm getting a type
When trying to open a file using this command: $fd = fopen('majestic_files/majestic_record.txt','w'); I get
im trying to open a popup with nothing but the content using javascript in
I'm trying to open/load an XML file specified in an Excel worksheet in the
I am trying to open .pdf file in IE7 and firefox, but its not

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.