4D Blog

Home Product 4D View Pro: Merge and unmerge cells

4D View Pro: Merge and unmerge cells

July 31, 2020

Product

Often when you create a table, you might need to combine two or more cells to create a centered title on a particular section of your table. As of 4D v18 R4, a new set of commands is at your disposal to help you merge and unmerge a group of cells by programming. Let’s take a look at some examples.

Merged cells

To create a merged cell, simply define a range with all of the cells you want to combine. Pass the range as parameter to the VP  ADD SPAN command and you’ll be good to go!

For example, let’s use the document below:

If you want to merge the First quarter and Second quarter cells into the adjacent cells and merge the South area cell into the two rows below it, simply use this code:

// First quarter range
$q1:=VP Cells ("ViewProArea";2;3;3;1)
 
// Second quarter range
$q2:=VP Cells ("ViewProArea";5;3;3;1)
 
// South area range
$south:=VP Cells ("ViewProArea";0;5;1;3)
 
VP ADD SPAN (VP Combine ranges ($q1;$q2;$south))

Here’s the result:

blank

retrieve merged cells

Now if you want to center the text for all of the merged cells in your document, you can use the VP Get spans command to retrieve all the merged cells:


// Search all the merge cells in the spreadsheet

$range:=VP Get spans (VP All ("ViewProArea"))
 
//apply a style to all spans
$style:=New object("vAlign";vk vertical align center;"hAlign";vk horizontal align center)
VP SET CELL STYLE ($range;$style)

blank

remove merged cells

If for any reason you need to remove the cell spans (aka unmerge the cells) in your document, just use the VP REMOVE SPAN:

// Search all the merge cells in the spreadsheet
$range:=VP Get spans (VP All ("ViewProArea"))
 
// remove the found merged cells
VP REMOVE SPAN ($range)

blank

Need more information? Check out the documentation.

Discuss

Tags 4D View Pro, Spreadsheet, v18 R4, v19

Latest related posts

  • February 3, 2026

    4D Write Pro – Adding a margin automatically when bullets are set using standard actions

  • January 22, 2026

    Transform Static Documents into Actionable Knowledge with AIKit

  • January 22, 2026

    Deploy Fluent UI effortlessly in your 4D applications

Fabrice Mainguené
Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • AI
  • 4D Write Pro
  • Email, Microsoft 365, Gmail
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • 4D Qodly Pro
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 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