Setting first row in table sets first and second row


#1

Hello,

I'm adding a single row to a table, then populating the table with the ImportDataTable() method. After setting up my columns I try to reset the Accredited heading column back to the desired color and alignment. When I do this both the first and second rows in the table are changed.

This is my code:

Section section3 = pdf.Sections.Add();
SetSectionMargins(section3);
section3.IsNewPage = true;

// Table for data
Aspose.Pdf.Table pdfTable = new Aspose.Pdf.Table();
pdfTable.Margin.Top = 10;
pdfTable.Alignment = AlignmentType.Center;
section3.Paragraphs.Add(pdfTable);
pdfTable.ColumnWidths = "70 80 90 70 50 50";
pdfTable.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);

//
// Add a header row to the table.
//
Row pdfRow = pdfTable.Rows.Add();
TextInfo headingTextInfo = new TextInfo();
headingTextInfo.FontSize = 13;
headingTextInfo.IsTrueTypeFontBold = true;
headingTextInfo.Color = new Aspose.Pdf.Color(255, 255, 255);
headingTextInfo.BackgroundColor = new Aspose.Pdf.Color(51, 51, 101);
pdfRow.Cells.Add("Test Name", headingTextInfo);
pdfRow.Cells.Add("Method", headingTextInfo);
pdfRow.Cells.Add("Description", headingTextInfo);
pdfRow.Cells.Add("Accredited", headingTextInfo);
pdfRow.Cells.Add("DL High", headingTextInfo);
pdfRow.Cells.Add("DL Low", headingTextInfo);

pdfTable.ImportDataTable(legendTable, false, 0, 0);

// Center data in the Accredited column
TextInfo colTextInfo = new TextInfo();
colTextInfo.Alignment = AlignmentType.Center;
pdfTable.SetColumnTextInfo(ACCREDITED_CELL, colTextInfo);

// Need to reset the Accredited column heading
pdfTable.Rows[0].Cells[ACCREDITED_CELL].DefaultCellTextInfo = headingTextInfo;

return pdf;


#2

Hi,

Thank you for consiering Aspose.

I have tested with the following code and have not found any error:
Pdf pdf = new Pdf();

Section section3 = pdf.Sections.Add();
section3.IsNewPage = true;

// Table for data
Aspose.Pdf.Table pdfTable = new Aspose.Pdf.Table();
pdfTable.Margin.Top = 10;
pdfTable.Alignment = AlignmentType.Center;
section3.Paragraphs.Add(pdfTable);
pdfTable.ColumnWidths = "70 80 90 70 50 50";
pdfTable.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);

//
// Add a header row to the table.
//
Row pdfRow = pdfTable.Rows.Add();
TextInfo headingTextInfo = new TextInfo();
headingTextInfo.FontSize = 13;
headingTextInfo.IsTrueTypeFontBold = true;
headingTextInfo.Color = new Aspose.Pdf.Color(255, 255, 255);
headingTextInfo.BackgroundColor = new Aspose.Pdf.Color(51, 51, 101);
pdfRow.Cells.Add("Test Name", headingTextInfo);
pdfRow.Cells.Add("Method", headingTextInfo);
pdfRow.Cells.Add("Description", headingTextInfo);
pdfRow.Cells.Add("Accredited", headingTextInfo);
pdfRow.Cells.Add("DL High", headingTextInfo);
pdfRow.Cells.Add("DL Low", headingTextInfo);

string[] arr = new string[]{"1","2","3","4","5","6",
"1","2","3","4","5","6"};
pdfTable.ImportArray(arr,1,0,false);

// Center data in the Accredited column
TextInfo colTextInfo = new TextInfo();
colTextInfo.Alignment = AlignmentType.Center;
pdfTable.SetColumnTextInfo(3, colTextInfo);

// Need to reset the Accredited column heading
pdfTable.Rows[0].Cells[3].DefaultCellTextInfo = headingTextInfo;

pdf.Save("e:/temp/test.pdf");