Some questions about DocxReadWrite

Questions and answers on how to use DOCXReadWrite
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Some questions about DocxReadWrite

Post 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 ?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Some questions about DocxReadWrite

Post 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';
Lars Arvidsson, Axolot Data
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Re: Some questions about DocxReadWrite

Post 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.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Some questions about DocxReadWrite

Post 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;
Lars Arvidsson, Axolot Data
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Re: Some questions about DocxReadWrite

Post 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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Some questions about DocxReadWrite

Post 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.
Lars Arvidsson, Axolot Data
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Re: Some questions about DocxReadWrite

Post 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;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Some questions about DocxReadWrite

Post by larsa »

Hello

Yes, you can do so.
Lars Arvidsson, Axolot Data
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Re: Some questions about DocxReadWrite

Post 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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Some questions about DocxReadWrite

Post 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.
Lars Arvidsson, Axolot Data
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Re: Some questions about DocxReadWrite

Post 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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Some questions about DocxReadWrite

Post 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.
Lars Arvidsson, Axolot Data
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Re: Some questions about DocxReadWrite

Post 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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Some questions about DocxReadWrite

Post by larsa »

Hello

1. I will check this.

2. Use field codes for show page number.
Lars Arvidsson, Axolot Data
Svet-lana
Posts: 12
Joined: Tue Dec 07, 2021 11:04 am

Re: Some questions about DocxReadWrite

Post 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?
Post Reply