尝试在C#中保存Excel文件时出现错误'来自HRESULT的异常:0x800A03EC' - ASP.net 2.0应用程序 [英] Error 'Exception from HRESULT: 0x800A03EC' when trying to save an excel file in C# - ASP.net 2.0 application

查看:115
本文介绍了尝试在C#中保存Excel文件时出现错误'来自HRESULT的异常:0x800A03EC' - ASP.net 2.0应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



嗨专家,

在我开发的
的内部网站中,我正在用C#.Net 2005创建一个excel文件-ASP.NET
2.0应用程序。在我在Windows XP上运行的本地计算机上,
应用程序运行良好,但是当我尝试在
windows 2008服务器机器上运行该应用程序时,它会引发异常。

'来自HRESULT的异常:0x800A03EC'

我的客户端正在使用他从以下链接下载的Windows 2008服务器试用版

http://www.microsoft .com / downloads / details.aspx?FamilyId = 13C7300E-935C-415A-A79C-538E933D5424& displaylang = en

什么
在windows中运行2008服务器机器是我的应用程序的已发布版本
。我在bin文件夹中包含所有必需的dll和其他应用程序
依赖文件,包括Interop.Excel.dll和
Interop.Microsoft.Office.C ore.dll。

Windows 2008服务器计算机已安装MS Office 2003版本。我也在这台机器上配置了DCOM。

这是我的代码































Courier New; font-size:11px">

< td style ="background-color:rgb(247,247,247)">((Excel.Worksheet)xlApp.ActiveSheet).Cells [1,1] = " SINO" ;
string fileName = "" ,strSaveFileAs = "" ; //保存Excel文件的文件名
物品掌握itemInfo;
Excel.Application xlApp = new Excel.Application(); //初始化Xl app
Excel.Workbook xlWorkBook = xlApp.Workbooks.Add( true );
object < font style ="font-size:11px"> worksheet = xlWorkBook.ActiveSheet; //设置工作表
object objMissing = System .Reflection.Missing.Value;
if < font style ="font-size:11px">(arList.Count> 0)
{
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[1,2] = " ItemGroupName" ;
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[1,3 ] = " ItemCode" ;
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[1,4] = " ItemName" ;
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[1,5 ] = " QTY" ;
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[1,6] = " Rate" ;
int SINo = 0; //显示序列号Excel中。
for int iRows = 1; iRows< = arList.Count; iRows ++)
{
itemInfo = new ItemMaster();
itemInfo =(ItemMaster)arList [中];
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[iRows + 1,1] = (中+ 1)的ToString();
//这里GroupId实际上包含组名
((Excel.Worksheet)xlApp.ActiveSheet).Cells [iRows + 1,2 ] = itemInfo.GroupID.ToString();
((Excel.Worksheet)xlApp.ActiveSheet).Cells [iRows + 1,3] = itemInfo.ItemCode.ToString();
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[iRows + 1,4] = itemInfo.ItemName.ToString();
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[iRows + 1,5] = "" ;
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[iRows + 1 ,6] = itemInfo.Rate.ToString();
((Excel.Worksheet)xlApp.ActiveSheet)。细胞[iRows + 1,7] = "" ;
((Excel.Worksheet)工作表).Columns.AutoFit(); // format
xlApp.ScreenUpdating = true ;
SINo ++;
}
/ * xls的FileName格式为:QuoteNo_CustomerName_Date * /
strSaveFileAs = txtCode.Text + " _" + ddlCustomer.SelectedItem.ToString()+ < font style ="color:blue">" _" + txtDate.Text;
string < font style ="font-size:11px"> filePath = Server.MapPath( " ..// Sales // Quote /" );
fileName = filePath + " QuoteFile" + " .xls" ;
if < font style ="font-size:11px">(File.Exists(fileName))
File.Delete(fileName);
//将文件保存在位置'fileName'中
xlWorkBook.SaveAs(( object )(fileName),objMissing,objMissing,objMissing,objMissing,objMissing,Excel.XlSaveAsAccessMode.xlNoChange,objMissing,objMissing,objMissing,objMissing,objMissing);

解决方案

我在Server 2008上的保存时遇到同样的错误如果我登录到服务器并从DOS窗口运行该作业,它将起作用,但如果一个网站开始我的工作,它会得到HRESULT:0x800A03EC错误。它适用于来自网站的Server 2003。我也需要回答这个问题。感谢。



Hi Experts,

In one the intranet sites which I have developed, i'm creating an excel file from C#.Net 2005-ASP.NET 2.0 application. In my local machine which runs on Windows XP the application works perfectly, but when I try to run the application in windows 2008 server machine it throws  an exception.

'Exception from HRESULT: 0x800A03EC'

My client is using the trial version of Windows 2008 server which he downloaded from the following link

http://www.microsoft.com/downloads/details.aspx?FamilyId=13C7300E-935C-415A-A79C-538E933D5424&displaylang=en

What is running in the windows 2008 server machine is the published version of my application. I have all the required dlls and other application dependency files in the bin folder including Interop.Excel.dll and Interop.Microsoft.Office.Core.dll.

The windows 2008 server machine has MS Office 2003 version installed. I have also configured DCOM in this machine.

Here is my code

 
            string fileName = "", strSaveFileAs = "";//To Save the File Name of the Excel File 
            ItemMaster itemInfo;         
            Excel.Application xlApp = new Excel.Application();//initialise Xl app 
            Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(true); 
            object worksheet = xlWorkBook.ActiveSheet;// set work sheet 
            object objMissing = System.Reflection.Missing.Value;                       
            if (arList.Count > 0) 
            { 
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1,1] = "SINO"
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 2] = "ItemGroupName"
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 3] = "ItemCode"
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 4] = "ItemName"
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 5] = "QTY"
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 6] = "Rate";               
  
                int SINo = 0;// To Show Serial No in excel.                 
                for (int iRows = 1; iRows <= arList.Count; iRows++) 
                { 
                    itemInfo = new ItemMaster(); 
                    itemInfo = (ItemMaster)arList[SINo];                     
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 1] = (SINo + 1).ToString(); 
                    //Here GroupId actually contains group name                     
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 2] = itemInfo.GroupID.ToString(); 
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 3] = itemInfo.ItemCode.ToString(); 
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 4] = itemInfo.ItemName.ToString(); 
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 5] = ""
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 6] = itemInfo.Rate.ToString(); 
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 7] = ""
                    ((Excel.Worksheet)worksheet).Columns.AutoFit();  //format                   
                    xlApp.ScreenUpdating = true
                    SINo++; 
                } 
                /* FileName format of xls is: QuoteNo_CustomerName_Date*/ 
                strSaveFileAs = txtCode.Text + "_" + ddlCustomer.SelectedItem.ToString() + "_" +  txtDate.Text;                 
                string filePath = Server.MapPath("..//Sales//Quote/");                 
                fileName = filePath + "QuoteFile" + ".xls"
                if (File.Exists(fileName)) 
                    File.Delete(fileName); 
                  //Save file in the Location 'fileName' 
                xlWorkBook.SaveAs((object)(fileName), objMissing, objMissing, objMissing, objMissing, objMissing, Excel.XlSaveAsAccessMode.xlNoChange, objMissing, objMissing, objMissing, objMissing, objMissing); 

解决方案

I am getting the same error on a save as on Server 2008. If I log in to the server and run the job from a DOS window it will work, but if a website kicks off my job it gets the HRESULT: 0x800A03EC error. It works in Server 2003 from a website. I need an answer to this as well. Thanks.


这篇关于尝试在C#中保存Excel文件时出现错误'来自HRESULT的异常:0x800A03EC' - ASP.net 2.0应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆