Page 1 of 2

Some questions about DocxReadWrite

Posted: Tue Dec 07, 2021 11:13 am
by Svet-lana
Hello!

I am studying the possibilities of DocxReadWrite to understand how the program will solve all my problems.
And I have sone questions about it.

1) Can I align the header to the right or to the center?
2) Can I insert page break when I need it?
3) Can I repeat the table header on every page?
Or can I copy some of rows of the table when the page number changes? How can I have the page number ?

Re: Some questions about DocxReadWrite

Posted: Wed Dec 08, 2021 8:38 am
by larsa
Hello

1. Not the whole header, but you can align the paragraphs:

Code: Select all

DOCX.Editor.Paras.AppendPara.PAPX.Alignment := axptaRight;
2. Yes, insert a page break at character position 25 in the first paragraph:

Code: Select all

DOCX.Editor.Paras[0].InsertBreak(acrbtPageBreak,25);
3. Yes, use Default header:

Code: Select all

  DOCX.Editor.Headers.AddDefault;
  DOCX.Editor.Headers.Default_.Paras.PlainText := 'My header text';

Re: Some questions about DocxReadWrite

Posted: Wed Dec 08, 2021 8:51 am
by Svet-lana
Thanks for answer!

3. I need repeat a current TABLE header (the first row of the table or a few rows), not the header of the page.

Re: Some questions about DocxReadWrite

Posted: Wed Dec 08, 2021 5:11 pm
by larsa
Hello

If you want to repeat the same table over several pages, the you can just assign the first table to the rest, like:

Code: Select all

var
  T: TAXWTable;
begin
  T := FDOCX.Editor.Paras.AddTable(6,6);
  ...
  FDOCX.Editor.Paras.AddTable.Assign(T);
  ...
  FDOCX.Editor.Paras.AddTable.Assign(T);
end;

Re: Some questions about DocxReadWrite

Posted: Thu Dec 09, 2021 6:35 am
by Svet-lana
Thank you for your answer!

I understand how I can copy some table rows, but I don't know how can I know that the page number was changed and I should past the table header.
Can I know the page number before pasting the next row?

Re: Some questions about DocxReadWrite

Posted: Thu Dec 09, 2021 12:48 pm
by larsa
Hello

No, you can know the page number because there are no pages in a Word file. Pages are produced when you visualize the document like printing it. And how many pages there will be depends on things like paper size margins etc.

Re: Some questions about DocxReadWrite

Posted: Tue Dec 14, 2021 7:37 am
by Svet-lana
And can I insert page preak after some rows of a table?

For example, I have a table with 40 rows and I want to print 25 rows in the first page, insert break and print other rows in the second page.
I fill out the table like this

Query.First;
while not qMain.Eof do begin
Cell := ATable.Rows[C].Cells[0];
Docx.Editor.TempPAPX.Alignment := axptaCenter;
ATable[C][0].Paras.PlainText :=Query.Fields[0].AsString;
Cell := ATable.Rows[C].Cells[1];
Docx.Editor.TempPAPX.Alignment := axptaLeft;
ATable[C][1].Paras.PlainText := Query.Fields[1].AsString;
...
c:=c+1;
Query.Next;
end;

Re: Some questions about DocxReadWrite

Posted: Wed Dec 15, 2021 10:06 am
by larsa
Hello

Yes, you can do so.

Re: Some questions about DocxReadWrite

Posted: Thu Dec 16, 2021 2:38 pm
by Svet-lana
Hello again!

A have a question about Merge Cells in a table.
In the sample I saw this
DOCX.Editor.Selections.TableSelect(DOCX.Editor.Paras.Tables[0],1,1,3,2);

So you merge Cols from 1 to 3 and Row from 1 to 2. Let's look a preview. You have in these cells
R2C2 R2C3 R2C4
R3C2 R3C3 R3C4

And after merge operation we have in preview
R2C2
R2C4
R2C3
R3C2
R3C4
R3C3

Why not
R2C2
R2C3
R2C4
R3C2
R3C3
R3C4 ?

And the second question. Is it possible to combine several cells so that there is no newline after the contents of each?
Why you insert a line even when some of cells are empty?

Re: Some questions about DocxReadWrite

Posted: Mon Dec 20, 2021 9:11 am
by larsa
Hello

1. Cells are combined in this way because this is how the component works. Usually this don't matters as you replaces the content after the merged cells are created.

2. The new line is inserted because otherwise the cells will be empty, and empty cells will have wrong height.

Re: Some questions about DocxReadWrite

Posted: Tue Dec 21, 2021 11:44 am
by Svet-lana
Thanks for the reply. So, we will adapt to what we have. in

Tell me, is it possible to upload files with the .dot extension as a template?

Re: Some questions about DocxReadWrite

Posted: Tue Dec 21, 2021 12:08 pm
by larsa
Hello

I assume you mean DOTX files (DOT or DOC files are not supported). A DOTX file is the same as a DOCX file and it is supported.

Re: Some questions about DocxReadWrite

Posted: Thu Jan 13, 2022 7:37 am
by Svet-lana
Hello again!

I have a problem when working with styles. I noticed this when I tried to run your example. I press the 'Use styles' button, then save everything to a file. When I open the file, I see that the font size has changed, the color too. But the font name is not.
Can something be changed here?

And the secons question. I need to specify in the header not only the page number, but also the number of pages. For example, in this form - "Page 2 Pages 10". How to do it?

Re: Some questions about DocxReadWrite

Posted: Fri Jan 14, 2022 12:38 pm
by larsa
Hello

1. I will check this.

2. Use field codes for show page number.

Re: Some questions about DocxReadWrite

Posted: Thu Jan 20, 2022 1:28 pm
by Svet-lana
Good afternoon!
A few questions about bookmarks.
1) the same situation as with styles - I specify the Arial font for the bookmark, but no changes occur. Font size, underline and italics work fine.
2) Is there any way to change the alignment for the bookmark? After assigning the value, the bookmarks for some reason are displayed with alignment in the center, and I need, for example, to the left.
How can I do this? Can you show an example?