Tech Tip: Accessing the 4D View Pro Workbook in JS
PRODUCT: 4D View Pro | VERSION: 18 | PLATFORM: Mac & Win
Published On: January 29, 2020
The 4D View Pro area is a custom Web Area form object running SpreadJS. As such, it is possible to run Javascript on the object to do things that are not yet implemented. The SpreadJS feature set is very large and many of them require access to the Workbook first, which is the entire document.
The Workbook is accessed differently depending on the UI applied to the 4D View Pro area. If the Ribbon Bar is applied the Workbook is accessed by "Utils.spread" and if any of the other two UIs are applied (Toolbar or None) the Workbook is accessed by just "spread".
Below is a utility method to find the correct Workbook:
//Method: vpGetWorkbook C_TEXT($0) C_TEXT($1) C_TEXT($vpArea_t) C_OBJECT($res_o) If (Count parameters=1) $vpArea_t:=$1 $res_o:=WA Evaluate JavaScript(*;$vpArea_t;"Utils.spread;";Is object) If ($res_o=Null) $0:="spread" Else $0:="Utils.spread" End if End if |
The command simply checks if "Utils.spread" returns an Object (of the SpreadJS Workbook) if it does then the VP area is using a Ribbon bar, if not is uses the Toolbar or No user interface.
Below is an example of using the method with a simple JS to get the number of rows.
$wb_t:=vpGetWorkBook("ViewProArea") $jsScript_t:=$wb_t+".getActiveSheet().getRowCount();" $res_t:=WA Evaluate JavaScript(*;"ViewProArea";$jsScript_t;Is text) |