开放XML SDK:获取“无法读取的内容"尝试填充超过25列时发生错误 [英] Open XML SDK: get "Unreadable content" error when trying to populate more than 25 columns
问题描述
我已经使用C#中的Open XML SDK创建了一个电子表格,并成功填充了两个工作表.
I have created a spreadsheet using Open XML SDK in C#, and successfully populated two worksheets.
当尝试填充第三个时,打开完整的文档时出现无法读取的内容" 错误,当我尝试在行上连续填充25个以上的单元格时,似乎会出现此错误.第三.
When trying to populate a third, I get an "Unreadable content" error when opening the completed document, and it appears to occur when I attempt to populate more than 25 cells in a row on the third.
我使用的代码段与文档其他地方已成功使用的代码段相同:
I'm using the same code fragment as has worked successfully elsewhere in the document:
string[] headers2 = {
"Reference", "Raised", "Priority", "Affected", "Linked incidents",
"Points", "SLA", "Stopped", "Target" };
// remaining headers are month/years created on the fly
string[] headerCells = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH" };
...
// headers
// once we've finished the presets, the month/year pairs take over
cellNo = (uint)0;
foreach (string h in headers2)
{
cell = InsertCellInWorksheet(headerCells[cellNo++], 2, worksheetPart);
cell.CellValue = new CellValue(h);
cell.DataType = new EnumValue<CellValues>(CellValues.String);
}
string[] monthYears =
GetData_month_years(currentReportingPeriod - 1);
for (int j = 0; j < monthYears.Count(); j++)
{
cell = InsertCellInWorksheet(headerCells[cellNo++], 2, worksheetPart);
cell.CellValue = new CellValue(monthYears[j].ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.String);
}
填充的唯一单元格是A和AA到AH.
The only cells populated are A and AA through AH.
我认为自己已经达到某种极限是正确的吗?如果是的话,重置极限的方法是什么?
Am I right in thinking I'm hitting some sort of limit, and if so, what's the way to reset it?
我已经看到了几篇有关内容无法读取的错误的信息,并且已经阅读了文档,但是到目前为止,我找不到任何适用的内容.
I've seen several posts about the unreadable content error, and I've looked through the documentation, but I've so far been unable to find anything that applies.
我们将不胜感激!
谢谢
推荐答案
请签出"InsertCellInWorksheet(...)"方法.如果您在内部使用此结构-
Please check out the "InsertCellInWorksheet(...)" method. If you use this construction inside -
...
row.InsertBefore(newCell, refCell);
...
即使您只想填写两列(例如,-"Z"和"A-Z"和"AA-..."列),它也无法正常工作. "AA". 因此,请改用此方法:
it won't work correctly if you want to fill in "A - Z" AND "AA - ..." columns, even if you want to fill in only two columns (for example), - "Z" and "AA". So, try to use this method instead:
...
row.Append(newCell);
...
祝你好运!
这篇关于开放XML SDK:获取“无法读取的内容"尝试填充超过25列时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!