Workbook not opening in MsWord and asking to repair and showing xml error after reparing

143 views Asked by At

I have exported the Dataset to excel using Closedxml.dll. I have an end date column in excel so I changed the Color of the cell if the date is expired. Now I tried to show the comment for that cell and I have tried the below code.

When I try to open the file it is showing to repair and after repairing it is showing the error as below and refer image

Replaced Part: /xl/worksheets/sheet.xml part with XML error. Load error. Line 1, column 0.

Error

I am binding the Datable for the worksheet and the using the below condition for changing the Color for Expired Date. It worked until that and if try to add the comment for that expired cell then it is showing the above. The code I tried is placed below.

  DateTime PresentDate = (DateTime.Now.Date);
  var C_Cell = WorkSheet.Cell("C" + Loop).Value == null ? "" : WorkSheet.Cell("C" + Loop).Value.ToString();
  if (C_Cell != "")
    {
     if (Convert.ToDateTime(C_Cell) <= PresentDate)
       {
          WorkSheet.Cell("C" + Loop).Style.Fill.SetBackgroundColor(XLColor.OrangeRed);
          WorkSheet.Cell("C" + Loop).Comment.AddText("Expired");
       }

    }

Can anyone help me out to solve the issue.

0

There are 0 answers