How to insert section break when exporting to .docx?
How to insert section break when exporting to .docx?
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!
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!
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: How to insert section break when exporting to .docx?
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.
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?
Please, please, this is exactly what I want, thank you very much!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
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: How to insert section break when exporting to .docx?
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.
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?
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?
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.
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.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: How to insert section break when exporting to .docx?
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?
No special properties needed, just want to be able to insert those two types of section 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 wrote: ↑Tue Jul 05, 2022 11:36 am (i.e., why is it necessary to use sections breaks instead of page breaks?)
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: How to insert section break when exporting to .docx?
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.
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?
With VBA in Word you can simple add a new section break without worry about the extra properties you mentioned above:
Thanks!
Code: Select all
Selection.Paragraphs(1).Range.InsertBreak Type:=wdSectionBreakContinuous
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: How to insert section break when exporting to .docx?
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.
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 1098 times
Re: How to insert section break when exporting to .docx?
Thanks, will try it very soon!