Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .



C#
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);

     }
Posted
Updated 14-May-16 0:37am
v4
Comments
Karthik_Mahalingam 14-May-16 3:33am    
which column
did u debug?
what is the inner exception ?
Siddharth Rai 14-May-16 5:45am    
just after the instance.dob??instance.dob;

instance.dob = {01/01/1899 12:00:00 AM}


Karthik_Mahalingam 14-May-16 5:49am    
is the value null at 506 index of the collection?
Siddharth Rai 14-May-16 6:10am    
on 506 instance.dob = {20/02/2019 12:00:00 AM}
on 507 instance.dob ={01/01/1899 12:00:00 AM}

Note- i have been set the dob column as custom date type on excel template

Exception from HRESULT: 0x800A03EC
there is no inner exception


----
thanking you
instance.dob !=null ?instance.dob.Value.ToString("dd/MM/yyyy"):"";

via above line i got problem fixed but i still i am unaware what was the problem .
Karthik_Mahalingam 14-May-16 6:11am    
hmm yes check my solution.

 
Share this answer
 
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
C#
_worksheet.Cells[rowCounter, 4] = GetExcelValidDate (instance.dob);

For Date Column:
C#
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
C#
private static string GetExcelValidDate(DateTime? date)
       {
           string temp = null;
           if (date.HasValue)
               temp = date.Value.ToString("MM/dd/YYYY");
           return temp;
       }
 
Share this answer
 
v2
Bug unrelated to your error message.
C#
_worksheet.Cells[rowCounter, 8] = instance.centreName ?? instance.centreName;
_worksheet.Cells[rowCounter, 8] = instance.leagueName ?? instance.leagueName;

You store 2 values in column 8.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900