Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

excel

openxml

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.

like image 209
Dinesh Haraveer Avatar asked Mar 28 '13 06:03

Dinesh Haraveer


People also ask

Where are Excel recovery files stored?

To do this, click “File” on the ribbon, go to the “Info” section, and choose “Manage Workbook”. Choose “Recover Unsaved Workbooks” to display and recover unsaved Excel files. Excel saves unsaved files to the folder C:\Users\\AppData\Local\Microsoft\Office\UnsavedFiles. You can also access the files from this folder.


1 Answers

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

like image 159
Boric Avatar answered Oct 01 '22 10:10

Boric