4D Blog

Home Product Get and Set cell content in 4D View Pro

Get and Set cell content in 4D View Pro

January 29, 2019

Product

The ability to interact with a document via programming is an important part of using 4D View Pro. Now you can fill your documents by programming. You can set data as labels, database fields, or formulas in your document. Of course, if you can set, you can get too! You can also retrieve cell formulas or values entered by your users.

To set and get values in 4D View Pro, 4D provides you a new set of commands:

  • VP SET VALUE
  • VP SET BOOLEAN VALUE
  • VP SET DATE TIME VALUE
  • VP SET DATE VALUE
  • VP SET TIME VALUE
  • VP SET NUM VALUE
  • VP SET TEXT VALUE
  • VP SET FORMULA
  • VP SET FIELD
  • VP Get value
  • VP Get formula

 

Here’s an HDI to see these commands in action:

HDI Get / Set value

SET and GET value in cells

SET value in cell(s)

To set a value in one or several cells, you first need to create a range of all the cells you want to fill.

Then depending on the type of value (text, date, time, etc.), you have two ways to set it:

Per type: VP SET BOOLEAN VALUE, VP SET DATE TIME VALUE, VP SET DATE VALUE, VP SET TIME VALUE, VP SET NUM VALUE, VP SET TEXT VALUE // Setting "Hello World" in cell G11 
VP SET TEXT VALUE (VP Cell ("ViewProArea";6;10);"Hello world")

Generic: VP SET VALUE

// Setting "Hello World" text in the cells G11 
VP SET VALUE (VP Cell ("ViewProArea";6;10);New object("value";"Hello world"))

GET value in a cell(s)

To get a value from a cell, use the VP Get value command. It returns an object containing the value of the cell:

$cell:=VP Cell ("ViewProArea";5;2)
// retrieve value of F3 cell
$value:=VP Get value ($cell)
// Verify if value is a Text
If (Value type($value.value)=Is text)
  // set the value in uppercase in the cell
  VP SET TEXT VALUE ($cell;Uppercase($value.value))
end if

Set and Get formula

set a formula

To assign a formula to a cell or a group of cells, use the VP SET FORMULA command. For example:

// Automatically calculate a total in F26
VP SET FORMULA (VP Cell ("ViewProArea";5;25);"SUM($F$21:$F$25)")

You can also assign a declared 4D method, as explained in Use methods and database fields in 4D View Pro with the VP SET FORMULA command:

// Set the licence information in A1
VP SET FORMULA (VP Cell ("ViewProArea";0;0);"get_LicenceInfo()")

get a formula

To get a formula assigned to a cell using the VP Get formula command:

// Create a cell range: D17
$cell:=VP Cell ("ViewProArea";3;16)
// Get the formula of the cell D17
$formula:=VP Get formula($cell)
// Returns $formula="SUM($F$21:$F$25)"

Set database fields

set a field

You can assign a field to a cell with the VP SET FIELD command. Of course, you need to declare your fields as virtual structures as explained in the Use methods and database fields in 4D View Pro blog post.

// assign the Price1 field to the F21 cell
VP SET FIELD (VP Cell ("ViewProArea1";5;20);->[Invoices]Price1)

Keep in mind that this field appears in the formula bound to the cell, and the table and field names are replaced by the names declared in the virtual structure.

Discuss

Tags 4D View Pro, Document creation, Spreadsheet, v17 R4, v18

Latest related posts

  • June 16, 2025

    Generate, share and use web sessions One-Time Passcodes (OTP)

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

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
  • 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 Listbox Logs Mail Microsoft 365 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 Listbox Logs Mail Microsoft 365 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