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

7

17

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.

Abney answered 28/3, 2013 at 6:39 Comment(9)
This isn't a coding problem and would be impossible to fix from this end.Galloping
can you tell why it is impossible to fix?Abney
@dineshHaraveer Did you able to solve this problem? As i am also facing the same issueHexastyle
@Hexastyle i'm unable to solve this issue.i'm wait any one to provide solution.I have googled but found nothing.Abney
@dineshHaraveer The issue i have solved using proper method of building the excel file using openxml SDK. I followed this link blogs.msdn.com/b/chrisrae/archive/2011/08/18/…Hexastyle
@Hexastyle thanks for providing the solution.Abney
What was the issue in your case i will be happy to learn?Hexastyle
we made some changes in the code and also permissionsAbney
For v2.5 of OPEN XML, I ran into the same issue as the OP. In the first iteration of a for loop, I assigned 0 to the SheetId property of a DocumentFormat.OpenXml.Spreadsheet.Sheet object. Changing this to a positive integer value fixed the issue for me.Groschen
H
10

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

Holliman answered 7/1, 2014 at 22:3 Comment(0)
M
5

Another few cases that can cause this type of error:

  • Your sheet name is longer than 31 characters
  • You have invalid characters in sheet name
  • You have cells with values longer than 32k
Muggins answered 22/9, 2016 at 13:17 Comment(0)
N
2

The issue is due to using

package.Save();

and

package.GetAsByteArray();

at the same time

when we call

package.GetAsByteArray();

it will do following operations

this.Workbook.Save(); this._package.Close(); this._package.Save(this._stream);

Hence, removing

package.Save();

will solve this problem "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."

Nationwide answered 21/8, 2019 at 10:22 Comment(0)
X
1

The issue was due to storing a string in the cell directly using cell.CellValue = new CellValue("Text"). It is possible to store numbers like this but not string. For string, define data type as string before assigning the text using Cell.DataType = CellValues.String;

Xeric answered 6/10, 2019 at 7:14 Comment(0)
S
0

Another possible cause could be exceeded maximum number of cell styles.

You can define:

  • up to 4000 styles in a .xls workbook
  • up to 64000 styles in a .xlsx workbook

In this case you should re-use the same cell style for multiple cells, instead of creating a new cell style for every cell.

Sublapsarianism answered 7/12, 2016 at 15:2 Comment(0)
Q
0

I added the right cellReference and fixed this issue for me:

string alpha = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";
for (int colInx = 0; colInx < reader.FieldCount; colInx++)
{
    AppendTextCell(alpha[colInx] + "1", reader.GetName(colInx), headerRow);
}

private static void AppendTextCell(string cellReference, string cellStringValue, Row excelRow)
{
    //  Add a new Excel Cell to our Row 
    Cell cell = new Cell() { CellReference = cellReference, DataType = new EnumValue<CellValues>(CellValues.String) };
    CellValue cellValue = new CellValue();
    cellValue.Text = cellStringValue.ToString();
    cell.Append(cellValue);
    excelRow.Append(cell);
}
Questionless answered 14/2, 2017 at 16:49 Comment(1)
I just got closedXml and no issues with it. Also it is much easier.Questionless
T
0

Same warning but the problem with me was that I was using a client input (name of wave) as sheet name for the file and when date was presented within the name, the character '/' used as date part separator was causing the issue.

I think Microsoft need to provide a better error log to save people time investigate such minor issues. Hope my answer will save someone else's time.

Thundery answered 13/9, 2019 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.