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 7621297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:09:45+00:00 2026-05-31T04:09:45+00:00

I have a function that takes a url to an Excel file, and then

  • 0

I have a function that takes a url to an Excel file, and then exports it as a pdf:

public static void ExportFromExcel(string url)
{
    // Create COM Objects
    Application excelApplication = new Application();
    Workbook excelWorkbook = 
        excelApplication.Workbooks.Open(HttpContext.Current.Server.MapPath(url));

    try
    {
        // Call Excel's native export function
        excelWorkbook.ExportAsFixedFormat(
            XlFixedFormatType.xlTypePDF, 
            HttpContext.Current.Server.MapPath(url.Replace(".xlsx", ".pdf")));
    }
    catch (Exception ex)
    {

    }
    finally
    {
        // Close the workbook, quit Excel, and clean up regardless of the results
        excelWorkbook.Close();    // HANGS AND FAILS HERE
        excelApplication.Quit();

        excelApplication = null;
        excelWorkbook = null;
    }
}

What I’m doing is creating an Excel file, and then immediately creating a pdf from that file:

using (FileStream fs = File.Create(HttpContext.Current.Server.MapPath(filePath)))
{
    byte[] data = pck.GetAsByteArray();
    fs.Write(data, 0, data.Length);
}

Pdf.ExportFromExcel(filePath);

It will create the Excel file just fine, and it will also create the pdf. But the page hangs for a long time, and then gives me the error at excelWorkbook.Close(); in my pdf code:

The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

The files actually get created though. But if I go to the file directory, there is a temporary Excel file as well (my Excel filename with the ~$ in front of it).

If I try and delete my Excel file, I get an error saying the file is being used by another process, and I can’t delete my Excel file until I kill the EXCEL.EXE in the Task Manager.

So for some reason, my Excel file won’t close after it finishes creating the pdf. Am I doing something wrong in my code?

  • 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-31T04:09:46+00:00Added an answer on May 31, 2026 at 4:09 am

    Using Interop on the server (including ASP.NET/IIS!) is NOT supported by MS – see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

    Since Windows Vista MS introduced several security-related measures which prevent a Windows Service (like ASP.NET on IIS) from doing “desktop-like” things (accessing printers, accessing network shares etc.)… which means you would have to circumvent several security measures to get it to work (NOT recommended!).

    To deal with Excel files without any need for Office etc. in a server-scenario there are several options (free and commercial) out there:

    I can recommend Aspose.Cells and Flexcel – both come with PDF export functionality… didn’t try SpreadsheetGear but hear+read lots of good things about it…

    Free options (though for the newer xlsx format only, not sure whether they support PDF export!) are for example OpenXML 2 from MS and EPPlus.

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

Sidebar

Related Questions

I have a function that takes pointer to pointer to struct. struct ABC; void
I have a function that takes a string-like argument. I want to decide if
I have a function that takes 2 parameters : 1 = XML file, 2
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a function that takes a struct, and I'm trying to store its
I have a function that takes a const D3DVECTOR3 *pos , but I have
I have a function that takes variadic arguments, that I obtain from func_get_args() .
I have a function that takes longitude and latitude and converts it to x
I have a Python function that takes a numeric argument that must be an
I have created a function that takes a SQL command and produces output that

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.