How to insert section break when exporting to .docx?

General TRichView support forum. Please post your questions here
Post Reply
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

How to insert section break when exporting to .docx?

Post 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!
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to insert section break when exporting to .docx?

Post 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.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: How to insert section break when exporting to .docx?

Post 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!
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to insert section break when exporting to .docx?

Post 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.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: How to insert section break when exporting to .docx?

Post by edwinyzh »

Thanks, but I'm mostly concerned about exporting to .docx, would you show me some tips for that? Thanks.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: How to insert section break when exporting to .docx?

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to insert section break when exporting to .docx?

Post by Sergey Tkachenko »

Which properties should these sections have? (i.e., why is it necessary to use sections breaks instead of page breaks?)
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: How to insert section break when exporting to .docx?

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to insert section break when exporting to .docx?

Post 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.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: How to insert section break when exporting to .docx?

Post 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!
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to insert section break when exporting to .docx?

Post 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.
Attachments
XMLToSections.zip
(93.65 KiB) Downloaded 1123 times
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: How to insert section break when exporting to .docx?

Post by edwinyzh »

Thanks, will try it very soon!
Post Reply