打开excel文件会提示一个消息框“工作簿的内容恢复”

当我试图打开excel文件时,一个消息框会提示“我们发现文件名中有些内容存在问题,您是否希望我们尽可能地恢复?如果您信任此工作簿的源,单击是。 “ 实际上做了什么是我有一个Excel模板devise和复制文件到另一个文件,并创build临时文件我插入数据到临时文件使用OPEN XML和数据从数据库中获取。

我曾尝试在networking提供的解决scheme,但这些修复不能解决我的问题。我的Excel是2010年

在这里输入图像说明

在这里输入图像说明

提供的任何解决scheme非常感谢。

我有这个问题。 这是我在单元格中存储数字和string的方式造成的。 数字可以像cell.CellValue = new CellValue("5")一样存储,但是对于非数字文本,您需要将单元格数据types更改为SharedString,将string插入SharedString表中,然后将该表在单元格索引,如下所述: http : //msdn.microsoft.com/en-us/library/office/cc861607.aspx

 string text = "Non-numeric text."; cell.DataType = new EnumValue<CellValues>(CellValues.SharedString); var sharedStringTable = document.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First().SharedStringTable; var item = sharedStringTable.AppendChild(new SharedStringItem(new Text(text))); cell.CellValue = new CellValue(item.ElementsBefore().Count().ToString()); 

另外几个可能导致这种types错误的情况:

  • 您的工作表名称长度超过31个字符
  • 工作表名称中包含无效字符
  • 你有值大于32K的单元格

另一个可能的原因可能会超过单元格样式的最大数量

你可以定义:

  • .xls工作簿中多达4000种样式
  • .xlsx工作簿中的最多64000个样式

在这种情况下,您应该为多个单元格重复使用相同的单元格样式,而不是为每个单元格创build新的单元格样式。

我添加了正确的cellReference并为我解决了这个问题:

 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); }