Page 1 of 1

Table alignment not applying when saving document

Posted: Wed Feb 21, 2024 7:30 am
by Gasper
I am facing an issue when saving our docx template that contains a table.
The table is aligned to the center of the document, however when I load and save the tamplate it gets aligned to the right.

I have made a very simple test project to test this.

Code: Select all

docx := TDOCXReadWriteVcl.Create(nil);
docx.LoadFromFile(template.docx'); //template.docx contains table aligned to center
docx.SaveToFile('test.docx'); //saving the template aligns the table to the left
Here's a few things I have tried, but none of them seem to do the trick.

Code: Select all

     //Loop through the entire document, check if paras = table, set PAPX.Alignment := axptaCenter
     for i := 0 to WordDoc.Editor.Paras.Count - 1 do
     begin
        if WordDoc.Editor.Paras.Items[i].Type_ = alptTable then
        begin
//          WordDoc.Editor.Paras.Items[i].TempPAPX.Alignment := axptaCenter;
//          WordDoc.Editor.Paras.ParaAtIndex(i).PAPX.Alignment := axptaCenter;
          WordDoc.Editor.Paras.Items[i].Paras.Last.PAPX.Alignment := axptaCenter;
        end;
     end;

//     WordDoc.Editor.Footers.AddDefault;
//     WordDoc.Editor.Footers.Default_.Paras[1].PAPX.Alignment := axptaCenter;
Ideas and any insight is greatly appreciated!

Re: Table alignment not applying when saving document

Posted: Mon Feb 26, 2024 9:00 am
by Gasper
Would anyone happen to have a solution for this please? I'm at a loss of what else to try.

Code: Select all

if docx.Editor.Footers.Default_.Paras.Items[0].Type_ = alptTable then
  begin
    writeln(sLineBreak + 'Item ' + IntToStr(Counter) + ' of footer is a table');
    footerTable := docx.Editor.Footers.Default_.Paras.Tables[0];
    newTable := docx.Editor.Footers.Default_.Paras.AddTable;
    newTable.Assign(footerTable);
  end;
 
docx.Editor.Footers.Default_.Paras[1].PAPX.Alignment := axptaCenter;
docx.Editor.Footers.Default_.Paras[1].AppendPlainText('Text');
I have even tried copying the table, which works, but the new table is still aligned to the left. The appended plain text however gets aligned to the center.
If I try modifying the PAPX of Paras[0] (table?) I get an exception saying 'Para item is not para'.

A solution would be greatly appreciated!

Re: Table alignment not applying when saving document

Posted: Tue Apr 16, 2024 5:48 am
by Gasper
For anyone facing the same issue - the fix is to apply update 2.00.26 where they fixed a bug with table alignment not being saved.