4D Blog

Home Product Manage sections with code in a 4D Write Pro document

Manage sections with code in a 4D Write Pro document

October 15, 2018

Product

Want a different background per section? Or maybe a different margin per section? How about a different number of columns per section? Want to do all this with code?

With 4D v17 R3, you can manipulate sections with code to create complex and beautiful 4D Write Pro documents!

Database example

sections and a subsections

Sections allow you to have different layouts in the same document. For example, for each section you can define a different paper size and orientation, different margins, use columns, have different headers and footers, and so on.

A section can contain subsections. There are three types of subsections: first, left, and right page. For example, in a brochure, you want to align the titles and page numbers on the outer edges of your brochure, so left for left pages and right for right pages.

Retrieve the current section or all sections

You can retrieve a collection of sections in your document with the new command: WP Get sections.

C_COLLECTION(wpSections)
wpSections:=WP Get sections(wpDoc)

You can also retrieve a reference to the first section intersected by the selection (range or element) the with the command: WP Get section.

C_OBJECT(wpSection)
wpSection:=WP Get section(WP Get selection(wpDoc))

Update an attribute for a specific section

Now that you can retrieve the section, it’s very easy to change the attributes for a specific section or its content. Just pass the section reference to the WP SET ATTRIBUTES and WP GET ATTRIBUTES commands.

For example, if you want three columns in the current section, you’d write:

WP SET ATTRIBUTE(wpSection;wk column count;3)

Create subsections with code

You can create a subsection with code using the new command: WP Create subsection.

You can create a subsection for the left page as follows:

$subSection:=WP Create subsection(wpSection;wk left page)

With a subsection reference, you can access the subsection’s header or footer and modify its attributes. It’s similar to the section.

For example, to left align the text in the header:

$header:=WP Get header($subSection)
WP SET ATTRIBUTES($header;wk text align;wk left)

 

When you create the left subsection, the right subsection is automatically created. You can get the reference to the right subsection with the WP Get subsection command.

On the right page, to right align the header text:

$subSection:=WP Get subsection(wpSection;wk right page)
$header:=WP Get header($subSection)
WP SET ATTRIBUTES($header;wk text align;wk right)

Discuss

Tags 4D Write Pro, Document creation, Programming, Section break, v17 R3, v18, Word processor

Latest related posts

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

Vanessa Talbot
Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy