Opening the excel file brings up a window with the message "restore book contents",

While I try to open the excel file, a window appears with a message like "We found a problem with some contents in the file name. Do you want us to try to recover as much as we can? The source of this book, click" Yes. "." In fact, I have an excel template designed and copying a file to another file, and a temp file created. I insert the data into the temp file using OPEN XML and the data comes from the database.

I tried the solutions provided on the network, but these fixes do not solve my problem. My advantage is 2010

enter image description here

enter image description here

Any solution provided is much appreciated.

+11
excel openxml
source share
7 answers

I had this problem. This was due to the way I stored numbers and rows in cells.

Numbers can be stored simply with cell.CellValue = new CellValue("5") , but for non-numeric text you need to insert a row into the SharedStringTable element and get the index of that row. Then change the cell data type to SharedString and set the cell index to the row index in 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

+5
source share

A few more cases that can cause this type of error:

  • Your sheet name is longer than 31 characters
  • You have invalid characters in the sheet name
  • You have cells with values ​​longer than 32k
+2
source share

Another possible reason could be that the maximum number of cell styles could be exceeded .

You can define:

  • up to 4000 styles in a .xls workbook
  • up to 64,000 styles in a .xlsx workbook

In this case, you should reuse the same cell style for multiple cells, instead of creating a new cell style for each cell.

0
source share

I added the correct cellReference and fixed this problem 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); } 
0
source share

The problem is with using

package.Save ();

and

package.GetAsByteArray ();

in the same time

when we call

package.GetAsByteArray ();

he will perform the following operations

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

Hence the removal

package.Save ();

will solve this problem "We found a problem with some content in the file name. Do you want us to try to recover as much as we can? If you trust the source of this book, click" Yes. "

0
source share

The same warning, but the problem with me was that I used the client input (wave name) as the sheet name for the file, and when the date was presented in the name, the β€œ/” character used as the separator of the date part caused a problem.

I think Microsoft needs to provide a better error log to save people time investigating such minor issues. I hope my answer saves someone else time.

0
source share

The problem was due to saving the row in the cell directly using cell.CellValue = new CellValue ("Text"). You can store numbers like this, but not a string. For a string, define the data type as a string before assigning text using Cell.DataType = CellValues.String;

0
source share

All Articles