Opening excel file prompts a message box "content recovery of the workbook"

Dinesh Haraveer picture Dinesh Haraveer · Mar 28, 2013 · Viewed 22.3k times · Source

While I'm trying to open excel file a message box is prompting like "We found a problem with some content in file name. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.". What actually done is i have a excel template designed and copying the file to another file and created temp file I'm inserting data to temp file using OPEN XML and data is getting from the database.

i have tried the solutions provided in the net but those fixes are not resolving my issue.My excel is 2010

enter image description here

enter image description here

Anyone solution provided is much appreciated.

Answer

Boric picture Boric · Jan 7, 2014

I had this problem. It was caused by the way I was storing numbers and strings in cells.

Numbers can be stored simply using cell.CellValue = new CellValue("5"), but for non-numeric text, you need to insert the string in the SharedStringTable element and get the index of that string. Then change the data type of the cell to SharedString, and set the value of the cell to the index of the string in the SharedStringTable.

// Here is the text I want to add.
string text = "Non-numeric text.";

// Find the SharedStringTable element and append my text to it.
var sharedStringTable = document.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First().SharedStringTable;
var item = sharedStringTable.AppendChild(new SharedStringItem(new Text(text)));

// Set the data type of the cell to SharedString.
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);

// Set the value of the cell to the index of the SharedStringItem.
cell.CellValue = new CellValue(item.ElementsBefore().Count().ToString());

This is explained in the documentation here: http://msdn.microsoft.com/en-us/library/office/cc861607.aspx