Create a 4D View Pro document offscreen

Do you need to create a 4D View Pro document using code, without any user interface? It’s possible! Because 4D View Pro documents are objects, it’s very easy to create off-screen documents. You can create a new document in a variable of object type and manipulate it through its properties. When your document is ready, you can register it in your database, in a file, or display it directly in a 4D View Pro area.

Creating a 4D View Pro document is quite simple.

First, create an object with the following structure:

$doc:=New object
$doc.version:=1 // version [mandatory]
$doc.dateCreation:=Timestamp // creation date
$doc.dateModified:=Timestamp // modification date
$doc.spreadJS:=New object // spreadJS [mandatory]
$doc.meta:=New object("comment";"4D - How do I") // optional metadata

This object contains:

  • Internal information for 4D: document version
  • Developer information: metadata, creation, and modification dates
  • Document structure and data: data to be passed in the spreadJS property.


Once your structure is ready, complete the spreadJS property. It’s an object which contains, among other things, spreadsheet information, data, cell styles, formulas, etc.

starter example

In the example bellow we write “Hello 4D View Pro!” in the first cell of your document:

// Create the document
$doc:=New object("version";1;"dateCreation";Timestamp;"dateModified";Timestamp)
$doc.spreadJS:=New object("version";"11.0.0";"sheets";New object)
// Creation of the first sheet
$sheet:=New object("name";"Sheet1";"rowCount";100;"columnCount";20)
// Fill first sheet cells
$ object("dataTable";New object)
$["0"]:=New object // first row
$["0"]["0"]:=New object("value";"Hello 4D View Pro!") // set A1
$["0"]["1"]:=New object("value";42) // set B1
VP IMPORT FROM OBJECT ("ViewProArea";$doc)

Advanced example

In the example database, you can see how to quickly and easily create a simple document off-screen.

Off-screen creation of a 4D View Pro doc

To assist you with the creation of more complicated documents, you can refer to the JSON schema of SpreadJS documents.

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.