user1848942
user1848942

Reputation: 355

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.

Upvotes: 2

Views: 2270

Answers (4)

user1848942
user1848942

Reputation: 355

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

Thanks for trying to help!

Upvotes: 1

Adam Bilinski
Adam Bilinski

Reputation: 1198

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);

Upvotes: 1

Soner Gönül
Soner Gönül

Reputation: 98760

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);

Upvotes: 1

GeorgesD
GeorgesD

Reputation: 1082

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.

Upvotes: 2

Related Questions