“来自HRESULT的异常:0x800a03ec” C# [英] "Exception from HRESULT: 0x800a03ec" C#

查看:101
本文介绍了“来自HRESULT的异常:0x800a03ec” C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过2000条记录,当我在.xls文件中打印报告时

然后在打印第507行的某些列后发生以下异常错误



用户代码未处理System.Runtime.InteropServices.COMException 
消息=HRESULT异常:0x800A03EC
Source =
ErrorCode = -2146827284





我尝试过:



我正试图写一份excel报告。







< pre lang =C#> private void WriteLeagueMemberDataReportReport(工作表_worksheet,IList memberDetailList)
{
int rowCounter = 2 ;
foreach (LeagueMemberDataDetail实例 in memberDetailList)
{
_worksheet。 Cells [rowCounter, 1 ] = instance.memberRecNo;
_worksheet.Cells [rowCounter, 2 ] = instance.firstName;
_worksheet.Cells [rowCounter, 3 ] = instance.lastName;
_worksheet.Cells [rowCounter, 4 ] = instance.dob ?? instance.dob;
_worksheet.Cells [rowCounter, 5 ] = instance.emailId ?? instance.emailId;
_worksheet.Cells [rowCounter, 6 ] = instance.bsbNo ?? instance.bsbNo;
_worksheet.Cells [rowCounter, 7 ] = instance.accountNo ?? instance.accountNo;
_worksheet.Cells [rowCounter, 8 ] = instance.centreName ?? instance.centreName;
_worksheet.Cells [rowCounter, 8 ] = instance.leagueName ?? instance.leagueName;
_worksheet.Cells [rowCounter, 9 ] = instance.tbaPaymentMethod ?? instance.tbaPaymentMethod;
rowCounter ++;
}
// _worksheet.Protect(abc @ 123 $,true,true, false,true,true,true,true,true,true,false,false,false,
// false,false,false);

}

解决方案

, true,true,false,true,true,true,true,true,true,false,false,false,
// false,false,false);

}


参见 0x800A03EC - Google搜索 [ ^ ]。


您收到错误,因为第4列在Excel中是日期类型列

Excel单元格 Mininum 日期值 01/01/1900

所以当你尝试要插入一个小于 1900 的日期值,它将抛出异常



您可以验证日期值如下

 _ worksheet.Cells [rowCounter, 4 ] = GetExcelValidDate (instance.dob); 



对于日期列:

  private  静态 DateTime? GetExcelValidDate(DateTime?date)
{
DateTime? temp = null ;
if (date.HasValue)
temp = date.Value.Year < 1900 ?温度:日期;
return temp;
}



将其转换为文本栏

  private   static   string  GetExcelValidDate(DateTime?date)
{
string temp = null ;
if (date.HasValue)
temp = date.Value.ToString( MM / dd / YYYY);
return temp;
}


I have more then 2000 record and when i am printing the report in .xls file
then after printing the some column of row 507 the following exception error occurs

System.Runtime.InteropServices.COMException was unhandled by user code
  Message="Exception from HRESULT: 0x800A03EC"
  Source=""
  ErrorCode=-2146827284



What I have tried:

I am trying to wirte a excel report .



private void WriteLeagueMemberDataReportReport(Worksheet _worksheet, IList memberDetailList)
     {
        int rowCounter = 2;
         foreach (LeagueMemberDataDetail instance in memberDetailList)
         {
             _worksheet.Cells[rowCounter, 1] = instance.memberRecNo;
             _worksheet.Cells[rowCounter, 2] = instance.firstName;
             _worksheet.Cells[rowCounter, 3] = instance.lastName;
             _worksheet.Cells[rowCounter, 4] = instance.dob??instance.dob;
             _worksheet.Cells[rowCounter, 5] = instance.emailId ?? instance.emailId;
             _worksheet.Cells[rowCounter, 6] = instance.bsbNo ?? instance.bsbNo;
             _worksheet.Cells[rowCounter, 7] = instance.accountNo ?? instance.accountNo;
             _worksheet.Cells[rowCounter, 8] = instance.centreName ?? instance.centreName;
             _worksheet.Cells[rowCounter, 8] = instance.leagueName ?? instance.leagueName;
             _worksheet.Cells[rowCounter, 9] = instance.tbaPaymentMethod ?? instance.tbaPaymentMethod;
              rowCounter++;
         }
      //  _worksheet.Protect("abc@123$", true, true, false, true, true, true, true, true, true, false, false, false,
                      //     false, false, false);

     }

解决方案

", true, true, false, true, true, true, true, true, true, false, false, false, // false, false, false); }


See 0x800A03EC - Google Search[^].


You are getting the error because 4th Column in the Excel is a Date type Column
Excel Cells Mininum Date Value is 01/01/1900
So when you are trying to insert a date value which is less than 1900, it will throw an exception

You can validate the date value as below

_worksheet.Cells[rowCounter, 4] = GetExcelValidDate (instance.dob);


For Date Column:

private static DateTime? GetExcelValidDate(DateTime? date)
      {
          DateTime? temp = null;
          if (date.HasValue)
              temp = date.Value.Year < 1900 ? temp : date;
          return temp;
      }


To convert it as text column

private static string GetExcelValidDate(DateTime? date)
       {
           string temp = null;
           if (date.HasValue)
               temp = date.Value.ToString("MM/dd/YYYY");
           return temp;
       }


这篇关于“来自HRESULT的异常:0x800a03ec” C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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