Created
October 8, 2025 08:26
-
-
Save elutz/610608ff3170d5e65eb81e7ac05f8140 to your computer and use it in GitHub Desktop.
Class for offline Excel export using 4D VP View Pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method: VPOffscreen | |
// Parameters: | |
// Description | |
// For offscreen processing of Excel files with 4D View Pro aka SpreadJS | |
// Why: As a service (i.e., in headless mode), the | |
// generation of Excel files using ViewPro objects in forms | |
// does not work (4D v18 Project Mode)// For offscreen processing of Excel files with 4D View Pro aka SpreadJS | |
// Why: As a service (i.e., in headless mode), the | |
// generation of Excel files using ViewPro objects in forms | |
// does not work (4D v18 Project Mode) | |
// @param $params Parameter object for VPro | |
// @param $signal for error handling from the callback method in VP EXPORT DOCUMENT | |
Class constructor($params : Object; $signal : 4D.Signal) | |
This.VPObject:=$params.VPObject | |
This.docPath:=$params.docPath | |
This.customParams:=$params.customParams // IBPP-5952: optional for Post Processing after 4d View Pro Excel Export | |
This.autoQuit:=False // Closing of the offscreen area is manage by developer | |
This.timeout:=30 | |
This.result:=True // nothing wrong yet | |
This.signal:=$signal | |
Function onEvent | |
Case of | |
: (FORM Event.code=On VP Ready) | |
// TODO ausfaktorieren | |
// This.area is a implicit property from VP Run offscreen area | |
var $errhdl : Text | |
$errhdl:=Err_SetHandler(Formula(Err_IOHandler).source) | |
OK:=1 | |
VP IMPORT FROM OBJECT(This.area; This.VPObject) | |
C_BOOLEAN($vbOK) | |
$vbOK:=((OK=1) & (ErrorCode=0)) // IBPP-7021 | |
//TRACE | |
If ($vbOK) // Work around 4d View Pro Object's missing import of formulae: | |
C_OBJECT($sheet; $dataTable; $row; $col) | |
C_LONGINT($zeile; $spalte) | |
$sheet:=This.VPObject.spreadJS.sheets[This.VPObject.spreadJS.sheetNames[This.VPObject.spreadJS.activeSheetIndex]] // get current worksheet | |
$dataTable:=$sheet.data.dataTable | |
For ($zeile; 1; $sheet.rowCount) | |
For ($spalte; 1; $sheet.columnCount) | |
$row:=$dataTable[String($zeile-1)] | |
$col:=$row[String($spalte-1)] | |
If (OB Is defined($col; "formula")) | |
// V18 | |
VP SET FORMULA(VP Cell(This.area; Num($spalte-1); Num($zeile-1)); $col.formula) | |
End if | |
End for | |
End for | |
Else // IBPP-7021 | |
Allg_LogText(Current method name+" "+FORM Event.description+" "+String(ErrorCode)+": "+ErrorText; True) | |
End if | |
// | |
C_OBJECT($params) | |
$params:=New object | |
$params.formula:=Formula(ngPrintVPAfterExport) | |
$params.signal:=This.signal | |
$params.customParams:=This.customParams // IBPP-5952: optional for Post Processing after 4d View Pro Excel Export | |
If ($vbOK) | |
VP EXPORT DOCUMENT(This.area; This.docPath; $params) | |
End if | |
This.result:=New object(\ | |
"signaled"; This.signal.signaled; \ | |
"result"; This.signal.result=Null ? "" : This.signal.result; \ | |
"ok"; $vbOK) | |
Err_SetHandler($errhdl) | |
End case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment