Reputation: 3
When I add a cell to the table it is added to the next column.
Is there a way to add the rows first or add values more flexible? Im a beginner so I don't know much about this.
This is my code:
Document document = new Document(PageSize.A3, 50, 50, 25, 25);
MemoryStream PDFData = new MemoryStream();
PdfWriter PDFWriter = PdfWriter.GetInstance(document, PDFData);
document.Open();
PdfPTable table = new PdfPTable(testTimes);
table.DefaultCell.Border = 1;
table.HorizontalAlignment = 0;
table.WidthPercentage = 100f;
foreach (Test test in tests)
{
switch (test.type)
{
case 3:
//new Column (fail)
PdfPCell type = new PdfPCell(new Phrase(TestType.Aimatologikes.ToString()));
table.AddCell(type);
PdfPCell data = new PdfPCell(new Phrase("values"));
foreach (TestData testdata in test.TestDatas)
{
//Rows
table.AddCell(data);
}
break;
}
}
document.Add(table);
document.Close();
This is the result:
And I want to separate columns below second foreach. Is this posible?
Upvotes: 0
Views: 512
Reputation: 9012
Two suggestions:
Allow me to explain.
Let's call this intermediary object EasyTable.
EasyTable needs to do a few things:
To do this, you could easily implement EasyTable to use a Map. This way you can map Point objects to PdfObject. You can calculate the number of rows by iterating over all keys and finding the maximum Y value. Similar for number of columns.
Upvotes: 1