简体   繁体   中英

insufficient memory to create an excel workbook

My original code:

    Excel.Application xlErrorApp;
    Excel.Workbook xlErrorWorkBook;
    Excel.Worksheet xlErrorWorkSheet;
    object misValue = System.Reflection.Missing.Value;
    xlErrorApp = new Excel.Application();
    xlErrorWorkBook = xlErrorApp.Workbooks.Add(); // -> error
    xlErrorWorkSheet = (Excel.Worksheet)xlErrorWorkBook.Worksheets.get_Item(1);

A get error in line 6.

Error Message:

Application Microsoft Excel can not open or save documents due to insufficient memory or disk space.

Which library are you using ?

I already said it but actually Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

I recommend you to look for a free library like Open Office XML or a not free library like Aspose.

how about this:

Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Open(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing);

Workbooks.Add() method from MSDN ;

Parameters
Template
Type: System.Object

Optional Object. Determines how the new workbook is created. If this argument is a string specifying the name of an existing Microsoft Excel file, the new workbook is created with the specified file as a template. If this argument is a constant, the new workbook contains a single sheet of the specified type. Can be one of the following XlWBATemplate constants: xlWBATChart, xlWBATExcel4IntlMacroSheet, xlWBATExcel4MacroSheet, or xlWBATWorksheet. If this argument is omitted, Microsoft Excel creates a new workbook with a number of blank sheets (the number of sheets is set by the SheetsInNewWorkbook property).

If you try to create new workbook, try like this;

Workbook newWorkbook = this.Application.Workbooks.Add(missing);

I'm sorry I could not find the link earlier. I used EPPlus supports. http://epplus.codeplex.com

Thanks for trying to help!

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