Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
There is plenty of disk space and memory on the servers.
What's really strange is that it works OK when I specify a template with the Add method:
.Workbooks.Add(Server.MapPath("~") & "\ReportTemplate.xls")
So that's a workaround anyway...
Below is a small sample I'm using to try and debug this problem.
In a new web project, add a reference to Microsoft Excel 12.0 Object Library, add a button named
btnGenerateReport, a label named lblStatus, and a Hyperlink named
lnkExcelReport to Default.aspx and paste the following procedure into the code-behind file:
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnGenerateReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerateReport.Click
Dim xlApp As Excel.Application = New Excel.Application
xlApp.SheetsInNewWorkbook = 1
xlApp.Application.DisplayAlerts = False
xlApp.Application.AskToUpdateLinks = False
xlApp.Visible = False
''''Dim xlBook As Excel.Workbook = xlApp.Workbooks.Add(Server.MapPath("~") & "\ReportTemplate.xls") ' WORKS OKAY
Dim xlBook As Excel.Workbook = xlApp.Workbooks.Add() ' THROWS EXCEPTION
Dim xlSheet As Excel.Worksheet = xlBook.Sheets(1)
xlSheet.Range("A1").Value = "Hello World!"
If xlSheet IsNot Nothing Then
xlSheet = Nothing
End If
If xlBook IsNot Nothing Then
xlBook.SaveAs(Server.MapPath("~") & "\Reports\Test.xls")
xlBook.Close(False)
xlBook = Nothing
End If
If xlApp IsNot Nothing Then
xlApp.Quit()
xlApp = Nothing
End If
lnkExcelReport.NavigateUrl = Request.ApplicationPath & "/Reports/Test.xls"
lnkExcelReport.Text = "Test.xls"
End Sub
End Class
Is anyone able to reproduce this or know of a solution?
Additionally, must also create a subfolder in the web project named Reports and give the IIS_WPG group or ASP.NET worker process Modify permission. This is where the Excel reports are generated.
I can confirm I get the same type of error, although it works when I debug through Visual Studio.
I am pretty certain that this has to do with permissions as when this is run through the debugger the process is running through the user that is logged in rather than the ASP.NET user. Might have something to do with the default template being located somewhere
on the user's "Documents and Settings" folder but the ASP.NET user not having such a folder. Have spent a couple of late nights on this but have not been able to figure it so far. Don't know how much effort I will be putting behind it given the simple workaround
and the deadlines I need to meet, however it would be nice to get 'closure' on it.
I came across this error myself and after much head scratching and swearing seem to have discovered a solution. It is basically as you say in that it all seems to come down to the user that the website is running as.
To fix it I went into IIS and ensured that ASP.Net Impersonation was enabled, and that the specific user to imersonate was the logged in user rather than the ASP.NET user - and it all worked fine.
I came accross this exception too. I don't know why, although i fix it.
Updating web.config into <identity impersonate="true"/> can make Workbooks.Add() work, but i can't do it.
I searched another solution:
<div align=left>//create template.xlsx in your app root, and authorize aspnet or network service to access it. </div> <div align=left>Dim xlBook
As Excel.Workbook = xlApp.Workbooks.Add(Server.MapPath("~/template.xlsx"))</div> <div align=left> </div> <div align=left>Hope it can help you.</div> <div align=left> </div>
<div align=left>Dim xlBook
As Excel.Workbook = xlApp.Workbooks.Add(Server.MapPath("~/template.xlsx"))</div> <div align=left> </div> <div align=left>i got no errors and no output !!! no generated Excel file.</div> <div align=left> </div> <div align=left>the
process is completed successfully but no use ??!!!</div>
---------------------------------------------
Daoud Z Dajani
Web & MultiMedia Developer
Email:daoud@dajani.info
website:http://daoud.dajani.info
I have done every thing as you suggested but the excel exported with empty sheet. My server configuration is Windows 2003 with SP2 and i have MS Office 2007 running on it.
This issue may occur if you install Microsoft Windows 2000 Service Pack 3 (SP3) on a computer that is running Microsoft Windows 2000 Server, and both of the following conditions are true:
The server is running Terminal Services in Application Server mode.
Microsoft Office 2000 is installed on the server.
To resolve this issue, obtain and install the latest service pack for Microsoft...
To resolve this issue, obtain and install the latest service pack for Microsoft Windows 2000. For additional information about how to obtain the latest service pack, click the following article number to view the article in the Microsoft Knowledge
Base:
Pleae click on as answer . if you feel i get some thing from this post
gsbell
Member
43 Points
14 Posts
Excel 2007/ASP.NET Exception using .Workbooks.Add()
Apr 13, 2007 07:28 PM|LINK
Hi,
I am receiving the following exception when using the xlApp.Workbooks.Add() method with ASP.NET and Office 2007.
Server Error in '/ExcelTest' Application.
<div class="MsoNormal" style="text-align: center; line-height: normal;" align="center"></div>
Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
There is plenty of disk space and memory on the servers.
What's really strange is that it works OK when I specify a template with the Add method:
.Workbooks.Add(Server.MapPath("~") & "\ReportTemplate.xls")
So that's a workaround anyway...
Below is a small sample I'm using to try and debug this problem.
In a new web project, add a reference to Microsoft Excel 12.0 Object Library, add a button named btnGenerateReport, a label named lblStatus, and a Hyperlink named lnkExcelReport to Default.aspx and paste the following procedure into the code-behind file:
Thanks,
Gordon Bell
Excel Automation Exception Office
gsbell
Member
43 Points
14 Posts
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Apr 17, 2007 05:28 PM|LINK
Additionally, must also create a subfolder in the web project named Reports and give the IIS_WPG group or ASP.NET worker process Modify permission. This is where the Excel reports are generated.
ksideris
Member
2 Points
1 Post
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Apr 23, 2007 08:57 PM|LINK
I can confirm I get the same type of error, although it works when I debug through Visual Studio.
I am pretty certain that this has to do with permissions as when this is run through the debugger the process is running through the user that is logged in rather than the ASP.NET user. Might have something to do with the default template being located somewhere on the user's "Documents and Settings" folder but the ASP.NET user not having such a folder. Have spent a couple of late nights on this but have not been able to figure it so far. Don't know how much effort I will be putting behind it given the simple workaround and the deadlines I need to meet, however it would be nice to get 'closure' on it.
themanc
Member
2 Points
1 Post
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
May 24, 2007 04:01 PM|LINK
I came across this error myself and after much head scratching and swearing seem to have discovered a solution. It is basically as you say in that it all seems to come down to the user that the website is running as.
To fix it I went into IIS and ensured that ASP.Net Impersonation was enabled, and that the specific user to imersonate was the logged in user rather than the ASP.NET user - and it all worked fine.
Absolutely ridiculous error message mind you.
vittal
Member
2 Points
17 Posts
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Jan 03, 2008 01:25 PM|LINK
hi
i Solved the Problem by setting permission in dcomcnfg
step1 :Go to run type dcomcnfg
Step2: Click >Component services >Computes >My Computer>Dcom config> and select micro soft Excel Application>
Step3: Right Click on microsoft Excel Application>Properties>Give Asp.net Permissions
Step 4: Select Identity table >Select interactive user >select ok
that will work fine
thanks & regards
vittal
Gnaguix
Member
2 Points
1 Post
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Mar 28, 2008 09:46 AM|LINK
hi gsbell
I came accross this exception too. I don't know why, although i fix it.
Updating web.config into <identity impersonate="true"/> can make Workbooks.Add() work, but i can't do it.
I searched another solution:
<div align=left>//create template.xlsx in your app root, and authorize aspnet or network service to access it. </div> <div align=left>Dim xlBook As Excel.Workbook = xlApp.Workbooks.Add(Server.MapPath("~/template.xlsx"))</div> <div align=left> </div> <div align=left>Hope it can help you.</div> <div align=left> </div>daouddajani
Member
2 Points
11 Posts
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Apr 13, 2008 10:23 AM|LINK
after using this code:
<div align=left>Dim xlBook As Excel.Workbook = xlApp.Workbooks.Add(Server.MapPath("~/template.xlsx"))</div> <div align=left> </div> <div align=left>i got no errors and no output !!! no generated Excel file.</div> <div align=left> </div> <div align=left>the process is completed successfully but no use ??!!!</div>Daoud Z Dajani
Web & MultiMedia Developer
Email:daoud@dajani.info
website:http://daoud.dajani.info
gsbell
Member
43 Points
14 Posts
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Apr 14, 2008 02:27 PM|LINK
Do you have a "template.xlsx" in the root of your web application? Your new workbook won't be on disk until a successful .SaveAs command.
Also, is your server using Excel 2007? If not, you'll have to create a template.xls (Excel 97-2003 format) file instead.
ComputerSurg...
Member
126 Points
41 Posts
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Dec 24, 2009 12:32 PM|LINK
Hi,
I have done every thing as you suggested but the excel exported with empty sheet. My server configuration is Windows 2003 with SP2 and i have MS Office 2007 running on it.
export to excel
▌µùthùkûµâ₧á∩▐ .
abdulwakeel
Participant
1288 Points
305 Posts
Re: Excel 2007/ASP.NET Exception using .Workbooks.Add()
Apr 08, 2010 06:24 AM|LINK
This issue may occur if you install Microsoft Windows 2000 Service Pack 3 (SP3) on a computer that is running Microsoft Windows 2000 Server, and both of the following conditions are true:
To resolve this issue, obtain and install the latest service pack for Microsoft...
To resolve this issue, obtain and install the latest service pack for Microsoft Windows 2000. For additional information about how to obtain the latest service pack, click the following article number to view the article in the Microsoft Knowledge Base: