I am trying to add a complex field with the page number. The code below produces the xml below. It formats the default value (xxxx) correctly but once the page number gets refreshed it uses the default style. If I add the font definition manually to the block "<w:instrText xml:space="preserve"> PAGE </w:instrText>" the page number is displayed correctly. It seems to me that the docx writer suppresses the formats for instrText. Is there a way to work around?
Code: Select all
para := DOCX.Editor.Paras.AppendPara;
para.AppendComplexField('xxxx','PAGE');
for I := para.Runs.First.Index to para.Runs.Last.Index do
begin
CR := para.Runs[I];
format2 := CR.AddCHPX;
format2.Size := 8;
format2.FontName := 'Arial';
format2.CHP.hAnsi := 'Arial';
format2.CHP.Ascii := 'Arial';
format2.EastAsia := 'Arial';
end;
Code: Select all
<w:p>
<w:r>
<w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
<w:instrText xml:space="preserve"> PAGE </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:eastAsia="Arial" w:cs="Arial"/>
<w:sz w:val="16"/>
</w:rPr>
<w:t>xxxx</w:t>
</w:r>
<w:r>
<w:fldChar w:fldCharType="end"/>
</w:r>
</w:p>