У меня есть такой код
string[] data = new string[] { "1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14",
"1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14",
"1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14",
"1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14",
"1", "2", "3", "4", "5", "6", "7", "8",
"1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14",
"9", "10", "11", "12", "13", "14",};
using (PdfWriter writer = new PdfWriter(destinationFile))
{
// Creating a PdfDocument object
using (PdfDocument pdfDoc = new PdfDocument(writer))
{
// Creating a Document object
using (Document doc = new Document(pdfDoc))
{
// Creating a table
float[] pointColumnWidths1 = { 150f, 150f, 150f, 150f };
Table table = new Table(pointColumnWidths1);
Cell cell;
float[] pointColumnWidths2 = { 150f };
Table nestedTable = new Table(pointColumnWidths2);
for (int y = 0; y < data.Length; y++)
{
cell = new Cell();
cell.Add(data[y]);
nestedTable.AddCell(cell);
}
table.AddCell(nestedTable);
doc.Add(table);
doc.Close();
}
}
}
И это вывод
![enter image description here](https://i.stack.imgur.com/6F0Bq.png)
Что я делаю, это заполняю четыре столбца таблицы, используя itext, а не itextsharp.
Хорошо, пока вложенная таблица работает. Но если массив data
заполнен до 100 строк массива. Я получаю сообщение об ошибке
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
И я предполагаю, что ошибка в том, что заполненная вложенная таблица слишком велика для родительской таблицы?
Так как мне настроить его, если вложенная таблица слишком велика? некоторые данные будут записаны в следующем столбце. Я сам не могу решить эту проблему, поэтому задаю вопрос здесь.
Извините за неполный вопрос.
Вот ошибка
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.set_Item(Int32 index, T value)
at iText.Layout.Renderer.TableRenderer.UpdateFirstRowBorders(Int32 colN)
at iText.Layout.Renderer.TableRenderer.CollapseAllBorders()
at iText.Layout.Renderer.TableRenderer.Layout(LayoutContext layoutContext)
at iText.Layout.Renderer.RootRenderer.AddChild(IRenderer renderer)
at iText.Layout.RootElement`1.Add(IBlockElement element)
at iText.Layout.Document.Add(IBlockElement element)
at PdfItextSample.Program.CreatePdf(String destinationFile, List`1 lst)
и он указывает на линию
doc.Add(table);
Большое спасибо