Page 1 of 1
How to insert section break when exporting to .docx?
Posted: Mon Jul 04, 2022 6:26 am
by edwinyzh
Assume the program is merging doc1, doc2, doc3... into a single Word .docx document, how to insert section breaks between documents?
TRichView has 'page break', so that's not a problem to insert page break between two documents. However, Word has two more breaks: Continuous section break and Next-page Section break, how to insert those two types of sections?
Thank you!
Re: How to insert section break when exporting to .docx?
Posted: Mon Jul 04, 2022 11:06 am
by Sergey Tkachenko
Section breaks are not implemented yet, sorry.
If you want, I can explain how to export several TRichView documents with section breaks between them to DocX or RTF, but in TRichView section breaks are not supported.
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 3:02 am
by edwinyzh
Sergey Tkachenko wrote: ↑Mon Jul 04, 2022 11:06 am
If you want, I can explain how to export several TRichView documents with section breaks between them to DocX or RTF
Please, please, this is exactly what I want, thank you very much!
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 8:46 am
by Sergey Tkachenko
For RTF, see
https://www.trichview.com/forums/viewtopic.php?t=2742
It creates multisection RTF from a single documents.
Sections are separated either by a control or by a special text.
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 9:56 am
by edwinyzh
Thanks, but I'm mostly concerned about exporting to .docx, would you show me some tips for that? Thanks.
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 10:05 am
by edwinyzh
Hi Sergey,
I think I should describe how to merge multiple small docs into a single doc:
1 - I have multiple small docs saved as .xml.
2 - I create a temporary TRichView.
3 - I insert the small docs one by one into the temporary TRichView.
4 - Save the content of temporary TRichView to .docx.
Thanks.
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 11:36 am
by Sergey Tkachenko
Which properties should these sections have? (i.e., why is it necessary to use sections breaks instead of page breaks?)
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 12:16 pm
by edwinyzh
Sergey Tkachenko wrote: ↑Tue Jul 05, 2022 11:36 am
Which properties should these sections have?
No special properties needed, just want to be able to insert those two types of section breaks.
Sergey Tkachenko wrote: ↑Tue Jul 05, 2022 11:36 am
(i.e., why is it necessary to use sections breaks instead of page breaks?)
I don't know, but some users want to insert section breaks between "small documents" they've written when merging into the final document.
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 12:32 pm
by Sergey Tkachenko
I believe that section breaks make sense only if you define special section properties (that may include page size, orientation, margins, headers and footers, column count). Also, unlike page breaks, sections provide options for not adding break, or from starting next content on even or on odd page.
But ok, I'll try to make an example tomorrow.
In any case, this example will require creating a large document from multiple small documents in a single TRichView, then saving to DocX.
Re: How to insert section break when exporting to .docx?
Posted: Tue Jul 05, 2022 1:03 pm
by edwinyzh
With VBA in Word you can simple add a new section break without worry about the extra properties you mentioned above:
Code: Select all
Selection.Paragraphs(1).Range.InsertBreak Type:=wdSectionBreakContinuous
Thanks!
Re: How to insert section break when exporting to .docx?
Posted: Wed Jul 06, 2022 7:44 pm
by Sergey Tkachenko
I created an example: how to create a document from several XML files and save it to DocX with continuous sections between them.
As you can see, the code is very simple. First, we create a big document in TRichView, consisting of all XML files. When adding a new document, we store the index of the first item of its last paragraph in an array.
Then we save a DocX, processing OnSaveDocXExtra event. In this event, we check for Area = rv_docxs_ParaStyle, and if we are saving properties of the last paragraph of each document, we add a DocX code for a continuous section break.
This example assumes that page properties are not stored in DocX, i.e. rvrtfSaveDocParameters is not included in RichView1.RTFOptions.
If you need to store page properties, it would require more work.
Re: How to insert section break when exporting to .docx?
Posted: Thu Jul 07, 2022 4:11 pm
by edwinyzh
Thanks, will try it very soon!