Worksheets


Get the current worksheet.

let selectedSheet = workbook.getActiveWorksheet(); 

Get the worksheet with that name "Better".

let sheet = workbook.getWorksheet("Better"); 
if (sheet)
{
   console.log("exists");
}

Switch to the new worksheet.

newSheet.activate(); 

Get all the worksheets in the workbook.

let sheets = workbook.getWorksheets(); 

Get a list of all the worksheet names.

let names = sheets.map ((sheet) => sheet.getName()); 

Get the total number of worksheets in a workbook.

console.log(`Total worksheets inside of this workbook: ${sheets.length}`); 


Set the tab color each worksheet to a random color.

for (let sheet of sheets) { 
  let colorString = `#${Math.random().toString(16).substr(-6)}`;
  sheet.setTabColor(colorString);
}

Delete a worksheet

sheet.delete(); 

Add a blank worksheet with the name "Solutions".

let newSheet = workbook.addWorksheet("Solutions"); 


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext