如何解决此错误“来自HRESULT的异常:0x800A03EC"? [英] how to solve this error "Exception from HRESULT: 0x800A03EC"?
本文介绍了如何解决此错误“来自HRESULT的异常:0x800A03EC"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在执行代码时使用以下代码创建excel文件,错误出现在代码中间(我单独提到)
I am using the Following Code to create the excel file while i execute the code the error has come the line at middle of the code(I mention seperately)
[STAThread]
protected void Generate_Click(object sender, EventArgs e)
{
int io = 0;
System.Data.DataTable workTable = new System.Data.DataTable();
workTable.TableName = "VendorList";
workTable.Columns.Add("CURRENCY_CODE");
workTable.Columns.Add("REMARKS");
workTable.Columns.Add("VENDOR_NAME");
System.Data.DataRow workRow;
objDAOUploadEnquiry.ActionType = SRCMAction.FETCH.ToString();
objBLLUploadEnquiry.SelectCommonMasterUom(objDAOUploadEnquiry);
object dropDownValues = "";
for (int y = 0; y <= 9; y++)
{
workRow = workTable.NewRow();
//workRow[0] = "Cust" + y.ToString();// y;
//workRow[1] = "Cust" + y.ToString();
if (io == 0)
{
for (int kl = 0; kl < objDAOUploadEnquiry.UploadEnquriyList.Rows.Count; kl++)
{
dropDownValues += objDAOUploadEnquiry.UploadEnquriyList.Rows[kl]["TEXT_VALUE"].ToString() + ",";
}
io = 1;
}
workTable.Rows.Add(workRow);
}
string data = null;
int i = 0;
int j = 0;
int rowsCount = workTable.Rows.Count + 1;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
object pwd = "pwd";
Excel.Application xl = null;
Excel._Workbook wb = null;
Excel._Worksheet sheet = null;
object Missing = System.Reflection.Missing.Value;
try
{
xlApp = new Excel.ApplicationClass();
xl = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
wb = (Excel._Workbook)(xl.Workbooks.Add(Missing));
wb.Sheets.Add(Missing, Missing, Missing, Missing);
sheet = (Excel._Worksheet)(wb.Sheets[1]);
xlWorkSheet.Name = "IncludeVendorList";
Excel.Range m_range = sheet.get_Range("A1", "A10");
//sheet.get_Range("A1", "A11").Font.Color = System .Drawing .Color .Red ;
Excel.Range _nValidationRange = xlApp.get_Range("C2", "C10");
<code>I got an error on the Following Line While i execute this code </code>
_nValidationRange.Validation.Add(Excel.XlDVType.xlValidateList, Excel.XlDVAlertStyle.xlValidAlertStop, Excel.XlFormatConditionOperator.xlBetween, dropDownValues, Type.Missing);
xlWorkBook.SaveAs(("G:\\dhinakr.xls"), Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Save();
xlApp.Quit();
xlApp.Application.Quit();
string filepath = "G:\\dhinakr.xls";
FileInfo myfile = new FileInfo(filepath);
if (myfile.Exists)
{
Response.ClearContent();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
Response.AddHeader("Content-Length", myfile.Length.ToString());
Response.TransmitFile(myfile.FullName);
Response.End();
}
}
catch (COMException Ex)
{
GC.Collect();
throw new Exception(Ex.Message);
}
}
推荐答案
这是COM错误,因此您可能引用了错误的Excel版本,或者您的代码中还有其他问题,因为它与您拥有的Excel版本有关,或者总的来说与之有关.
It''s a COM error, so either you have a reference to the wrong version of Excel, or you have some other issue in your code as it relates to the version of Excel you have, or in general.
这篇关于如何解决此错误“来自HRESULT的异常:0x800A03EC"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文