Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
function readSheetProperties() { // Get the active worksheet var worksheet = context.workbook.getActiveWorksheet(); // Read sheet properties var sheetName = worksheet.name; var sheetIndex = worksheet.position; var sheetVisibility = worksheet.visibility; var sheetProtection = worksheet.protection.isProtected; // Logging the sheet properties console.log("Sheet Name: " + sheetName); console.log("Sheet Index: " + sheetIndex); console.log("Sheet Visibility: " + sheetVisibility); console.log("Sheet Protection: " + sheetProtection); }
In this example, the readSheetProperties
function performs the following steps:
It gets the active worksheet using the
getActiveWorksheet
method.It reads various properties of the sheet, such as the name, position (index), visibility, and protection.
The sheet properties are stored in variables:
sheetName
,sheetIndex
,sheetVisibility
, andsheetProtection
, respectively.Finally, it logs the sheet properties to the console.
You can call the readSheetProperties
function to see the sheet properties in the console output.
Please note that this example assumes that you have a workbook open and a worksheet active in Excel for the web or Excel Online, where you can execute the OfficeScript.
Additionally, remember to set up the necessary context and load the OfficeScript runtime to ensure the script executes successfully.