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:
These commands are very simple to use, as you can see in the following code:
// File name with an .xslx extension
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.
// Formula called when the export is finished
$params.formula:=New formula(AfterExport )
// Specific parameters
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
// Method which sends email with attached file
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.