Page 1 of 1

Keep CHPX of table when adding rows

Posted: Wed Feb 07, 2024 8:17 am
by Gasper
I'm adding rows to a TAXWTable and I want those rows to keep the same formatting (font, font size, color, etc.) as the first row.

Code: Select all

//ATable: TAXWTable, TableRow: TAXWTableRow
TableRow := ATable.Rows.Add;
TableRow.Assign(ATable[0], False); //Font of first cell of first row is 'Times New Roman' (Also tried AAssignText True)
	
TableRow.Cells[0].Paras.PlainText := 'Sample Text'; //Font of cell is 'Arial'
I have found half of the solution

Code: Select all

chpx := TAXWCHPX.Create(nil);
chpx.FontName := 'Times New Roman';
	
TableRow.Cells[0].Paras.FormatAll(chpx); 
But this hard sets the font to Times New Roman and our clients want to be able to customize their docx templates with their desired fonts, sizes and colors and not have them changed when filling the table with data.

How do I retain the formatting of the table from the template?

Re: Keep CHPX of table when adding rows

Posted: Tue Feb 13, 2024 7:37 am
by Vinzenz
Hi,
you can try something like

Code: Select all

chpx.FontName := ATable.FirstCell.Paras.Last.CHPXAtPos(0).FontName;
I don't know if it still works without text in the first cell, but it should copy whatever font is used there.
As long as you can access any TAXWLogPara the option to get a FontName is there, so you can experiment a bit.

Re: Keep CHPX of table when adding rows

Posted: Tue Feb 20, 2024 8:26 am
by Gasper
This did the trick! Thank you!!