问题描述
我已经开发了一个ASP.Net项目,我想在其中生成一些excel报告.
当我在本地系统上运行该程序时,查看那些excel文件没有问题,但是将该软件放在服务器上(Windows Server 2003 r2)后,我无法查看报告,并且出现以下错误:
Microsoft Office Excel无法打开或保存更多文档,因为没有足够的可用内存或磁盘空间.
•要使更多的内存可用,请关闭不再需要的工作簿或程序.
•要释放磁盘空间,请从要保存到的磁盘中删除不再需要的文件.
我的代码在这里:
Hi,
I have developed an ASP.Net project in which I want to produce some excel reports.
When I run this program on my local system, there is no problem in viewing those excel files, but after putting that software on server (Windows Server 2003 r2) I can not view the reports and I get the following error:
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.
my code is here:
Microsoft.Office.Interop.Excel.Application oXL;
Microsoft.Office.Interop.Excel.Workbook oWB;
Microsoft.Office.Interop.Excel.Worksheet oSheet;
Microsoft.Office.Interop.Excel.Range oRange;
oXL = new Microsoft.Office.Interop.Excel.Application();
//oXL.Visible = false;
//Get a new workbook
oWB = (Microsoft.Office.Interop.Excel.Workbook)(oXL.Workbooks.Add(System.Reflection.Missing.Value));
oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.ActiveSheet;
#endregion
#region Styles
Microsoft.Office.Interop.Excel.Style style_Header = null;//Reports_Header_Style_Func(oWB);
Microsoft.Office.Interop.Excel.Style style_Titles = null; //Reports_Columns_Title_Style_Func(oWB);
#endregion
#region Columns_Titles
string[,] _Titles = new string[1, 10];
_Titles[0, 0] = "Product";
_Titles[0, 1] = "Product(U)";
_Titles[0, 2] = "Manufact";
_Titles[0, 3] = "Price(U)";
_Titles[0, 4] = "Daily Usd";
_Titles[0, 5] = "Daily Rec";
_Titles[0, 6] = "Daily Ret";
_Titles[0, 7] = "Stock";
#endregion
#region Report_Building
#region Header
oRange = oSheet.get_Range("A1", "H1");
oRange.Cells[1, 1] = "Materials Used In Well: " + _wellName + " In Date: " + _fDate.ToString();
oRange.Merge(System.Reflection.Missing.Value);
oRange.Style = style_Header;
#endregion
#region Titles
oRange = oSheet.get_Range("A2", "H2");
oRange.Value2 = _Titles;
oRange.Style = style_Titles;
#endregion
int i = 3;
foreach (var item in Bll_obj_Material.Get_Materials_By_WellObjCodeandfDate(_wellObjCode, _fDate))
{
oSheet.Cells[i, 1] = item.Product.Product1;
oSheet.Cells[i, 2] = item.ProductUnit.ProductUnit1;
oSheet.Cells[i, 3] = item.ProductManufacture;
oSheet.Cells[i, 4] = item.PriceUnit.PriceUnit1;
oSheet.Cells[i, 5] = item.DailyUsed;
oSheet.Cells[i, 6] = item.DailyRec;
oSheet.Cells[i, 7] = item.DailyReturn;
oSheet.Cells[i, 8] = (item.StartAmount + item.DailyRec) - (item.DailyReturn + item.DailyUsed);
i++;
}
oSheet.Columns.AutoFit();
int max_row = i - 1;
string max_index = "H" + max_row.ToString();
oRange = oSheet.get_Range("A1", max_index);
oRange.Borders.Weight = 2;
oRange = oSheet.get_Range("A2", max_index);
oRange.Font.Size = 8;
oRange = oSheet.get_Range("A1", "H1");
oRange.Font.Size = 9;
#endregion
#region Save_and_Open_Report
string _fileName = "Material_Report_of_" + _wellName + "(" + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ")" + ".xls";
string _savePath = Server.MapPath("~") + "\\ExcelReports\\" + _fileName;
oWB.SaveCopyAs(_savePath);
string _openPath = Request.ApplicationPath;
_openPath = _openPath + "/ExcelReports/" + _fileName;
HyperLink_TEMP.NavigateUrl = _openPath;
HyperLink_TEMP.Visible = true;
HyperLink_TEMP.Text = "Download Generated Report";
#endregion
Thanks a lot in advance!
推荐答案
这篇关于查看Excel文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!