“Excel found unreadable content” error

I was exporting an Excel document using OpenXml, and added a new cell to be added to the export:

Cell newCell = new Cell() { CellReference = “A” + rowIndex };
r.InsertAt(newCell, cellIndex);
newCell.CellValue = new CellValue(item[i].Description);
newCell.DataType = new EnumValue<CellValues>(CellValues.Number);
cellIndex++;

After making this change, I received the message “Excel found unreadable content in ‘My Excel file.xlsx’. Do you want to recover the contents of the workbook?

Error

The problem was that I was attempting to format the cell as a number when it was actually a string. I modified the line that set the cell DataType, and it was fine:

newCell.DataType = new EnumValue<CellValues>(CellValues.String);

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: