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.
当我尝试打开excel文件时,一个消息框会提示“我们发现文件名中的一些内容有问题”。你想让我们尽可能地恢复吗?如果您信任此工作簿的源代码,请单击Yes。实际上,我设计了一个excel模板,将文件复制到另一个文件中,并创建了一个临时文件,我使用OPEN XML将数据插入到临时文件中,数据从数据库中获取。
i have tried the solutions provided in the net but those fixes are not resolving my issue.My excel is 2010
我已经尝试了网上提供的解决方案,但这些解决方案并不能解决我的问题。我的擅长是2010
Anyone solution provided is much appreciated.
非常感谢您提供的任何解决方案。
4 个解决方案
#1
3
I had this problem. It was caused by the way I was storing numbers and strings in cells. Numbers can be stored simply like cell.CellValue = new CellValue("5")
, but for you non-numeric text, you need to change the cell data type to SharedString, insert the string in the SharedString table, and then put that table index in the cell, as explained here: http://msdn.microsoft.com/en-us/library/office/cc861607.aspx
我有这个问题。它是由我在单元格中存储数字和字符串的方式引起的。数字可以像单元格一样简单地存储。CellValue = new CellValue(“5”),但是对于非数字文本,您需要将单元数据类型更改为SharedString,在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());
#2
0
Another few cases that can cause this type of error:
还有一些案例会导致这种类型的错误:
- Your sheet name is longer than 31 characters
- 您的表名超过31个字符
- You have invalid characters in sheet name
- 表名中有无效字符
- You have cells with values longer than 32k
- 值大于32k的单元格
#3
0
Another possible cause could be exceeded maximum number of cell styles.
另一个可能的原因可能是超过最大的细胞类型。
You can define:
您可以定义:
- up to 4000 styles in a .xls workbook
- 在.xls工作簿中最多有4000个样式
- up to 64000 styles in a .xlsx workbook
- 在.xlsx工作簿中最多有64000种样式
In this case you should re-use the same cell style for multiple cells, instead of creating a new cell style for every cell.
在这种情况下,您应该对多个单元格重用相同的单元格样式,而不是为每个单元格创建新的单元格样式。
#4
0
I added the right cellReference and fixed this issue for me:
我添加了正确的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);
}
#1
3
I had this problem. It was caused by the way I was storing numbers and strings in cells. Numbers can be stored simply like cell.CellValue = new CellValue("5")
, but for you non-numeric text, you need to change the cell data type to SharedString, insert the string in the SharedString table, and then put that table index in the cell, as explained here: http://msdn.microsoft.com/en-us/library/office/cc861607.aspx
我有这个问题。它是由我在单元格中存储数字和字符串的方式引起的。数字可以像单元格一样简单地存储。CellValue = new CellValue(“5”),但是对于非数字文本,您需要将单元数据类型更改为SharedString,在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());
#2
0
Another few cases that can cause this type of error:
还有一些案例会导致这种类型的错误:
- Your sheet name is longer than 31 characters
- 您的表名超过31个字符
- You have invalid characters in sheet name
- 表名中有无效字符
- You have cells with values longer than 32k
- 值大于32k的单元格
#3
0
Another possible cause could be exceeded maximum number of cell styles.
另一个可能的原因可能是超过最大的细胞类型。
You can define:
您可以定义:
- up to 4000 styles in a .xls workbook
- 在.xls工作簿中最多有4000个样式
- up to 64000 styles in a .xlsx workbook
- 在.xlsx工作簿中最多有64000种样式
In this case you should re-use the same cell style for multiple cells, instead of creating a new cell style for every cell.
在这种情况下,您应该对多个单元格重用相同的单元格样式,而不是为每个单元格创建新的单元格样式。
#4
0
I added the right cellReference and fixed this issue for me:
我添加了正确的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);
}