Sometimes, you need to display different tables of information in one document. For better visibility, it’s often necessary to display them in different sheets. In this case, you need to create, rename, hide or remove a sheet, or simply know which sheet the user is currently on.
With 4D v19 R2, you can manage the sheets in your 4D View Pro documents by programming.
By default, a new document only has one sheet:
Adding Worksheets
There are two ways to create new worksheets:
- with the VP SET SHEET COUNT command, you can define at once the number of sheets you need. For example, if you need three sheets:
VP SET SHEET COUNT("ViewProArea"; 3)
Each sheet has an index that you can use in the commands. Indexing starts at 0, so here the index of “Sheet1” is 0, the index of “Sheet2” is 1, and so on… Keep in mind that the index is the sheet position in the tab bar, and it changes when you add, remove or change the order of your sheets.
- with the VP ADD SHEET command, you can insert a sheet with a custom name at a specific index. For example, if you need to insert a new sheet with the name “Total first quarter”:
VP ADD SHEET("ViewProArea"; 0; "Total first quarter")
Because we have inserted a new sheet, the indexes have changed. The index of “Total first quarter” is 0, the index of “Sheet1” is now 1, and so on…
reNaming a Worksheet
By default, the sheets in a View Pro document are named “SheetX”. To give them names that are more relevant for your users, use the VP SET SHEET NAME command. In our example, we can change the names “Sheet1″,”Sheet2″,”Sheet3” to “January”, “February” and “March”:
VP SET SHEET NAME("ViewProArea"; "January"; 1)
VP SET SHEET NAME("ViewProArea"; "February"; 2)
VP SET SHEET NAME("ViewProArea"; "March"; 3)
selectING a worksheet
You can change the sheet selected with VP SET CURRENT SHEET. For example, if we add a new worksheet and select it:
// find the last position by counting the sheets
$lastPosition:=VP Get sheet count("ViewProArea")
// add new sheet at the last position
VP ADD SHEET("ViewProArea"; $lastPosition; "Total second quarter")
// select the new sheet
VP SET CURRENT SHEET("ViewProArea"; $lastPosition)
Hiding a Worksheet
If you need to hide a sheet because it contains only information for calculation, use VP SET SHEET OPTIONS. In our example, if we want to show only the “Total X quarter” sheets, and use the others only for calculations:
$options:=New object
$options.visible:=False
VP SET SHEET OPTIONS("ViewProArea"; $options; 1)
VP SET SHEET OPTIONS("ViewProArea"; $options; 2)
VP SET SHEET OPTIONS("ViewProArea"; $options; 3)
And check out the doc center for more details!