Reputation: 355
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
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
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
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
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