查看Excel文件时出现问题 [英] A problem in viewing Excel file
问题描述
我已经开发了一个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!
推荐答案
在这里,您将寻求解决的解决方案
Microsoft.Office.Interop.Excel中的问题 [
第3步:右键单击Microsoft Excel应用程序>属性>授予Asp.net权限
第4步:选择身份表>选择交互式用户>选择确定
Here you go for the solved solution
Problem in Microsoft.Office.Interop.Excel[^]
Update
----------------------------
It''s a permission error....apply the below steps(Copied from above link), that''s all
Step 1 : Go to run typedcomcnfg
Step 2 : Click >Component services >Computes >My Computer>Dcom config> and select micro soft Excel Application>
Step 3 : Right Click on Microsoft Excel Application>Properties>Give Asp.net Permissions
Step 4 : Select Identity table >Select interactive user >select ok
如果您检查服务器是否有足够的内存和磁盘空间,那么最好的猜测是它是一个权限问题.您可以尝试使用 ^ ]
If you have checked that the server has enough memory and disk space, then the best guess is that it is a permissions issue. There is a discussion of this problem with various solutions you can try here[^]
Microst不建议使用Interop.Excel进行服务器编程.
请改用OpenXML.
[edit]不要大喊大叫.使用所有大写字母被认为是在互联网上大喊大叫,并且粗鲁(使用所有小写字母被认为是幼稚的).如果要认真对待,请使用大写字母. -OriginalGriff [/edit]
Microst doesn''t reccommend to use Interop.Excel for server programming.
Use OpenXML instead.
[edit]DON''T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously. - OriginalGriff[/edit]
这篇关于查看Excel文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!