Work with .xlsx documents using 4D View Pro

Automatically translated from English

Do you need to open a Microsoft Excel document directly in your 4D View Pro area, or convert a 4D View Pro document to Microsoft Excel format to send it to a customer? It’s now possible! Thanks to this feature, your 4D business applications have taken a further step towards better compatibility with the MS Office environment.

To do this, the existing 4D View Pro commands, VP IMPORT DOCUMENT and VP EXPORT DOCUMENT, have been enhanced so that they now support files using the .xlsx extension. Just pass your file path to the commands, and you’re all set!

This video shows you how simple it is to open and save an Excel file with a 4D View Pro area. Check it out!

To see this new feature in action, download our database example:

 4DVP Export Excel Example

code examples

These commands are very simple to use, as you can see in the following code:

$areaName:="ViewProArea"
// File name with an .xslx extension
$filePath:="c:\\tmp\\convertedfile.xlsx"
 
VP IMPORT DOCUMENT ($areaName;$filePath)

Because the import and export are asynchronous, you can pass an optional formula which will be called once the import or export is finished. The New formula command allows assigning an expression or method as formula to an object. For more information about this new command, take a look at this blog post.

In the following example, the formula is a method which sends an email once the file is created.

$areaName:="ViewProArea"
$filePath:="c:\\tmp\\convertedfile.xlsx"
$params:=New object
// Formula called when the export is finished
$params.formula:=New formula(AfterExport )
// Specific parameters
$params.email:=New object("address";$user.emailAddress;"name";$user.name)
VP EXPORT DOCUMENT ($areaName;$filePath;$params)

The AfterExport method takes the three parameters passed to VP EXPORT DOCUMENT with an additional parameter for the error status:

$areaName:=$1 // Area name passed to VP EXPORT DOCUMENT
$filePath:=$2 // Filepath passed to VP EXPORT DOCUMENT
$params:=$3 // Optional object passed to VP EXPORT DOCUMENT
$status:=$4 // Error status
If ($status.success=False)
   ALERT($status.errorMessage)
Else
   // Method which sends email with attached file
   SendEmail($params.email;$filePath)
End if

If you need to pass some specific parameters to the callback method, just add them in your $param object. The example above sends an email when the document is ready, so we pass the email information to the callback method with an email object added to the $params object.

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.