Office Scripts


This scripts gets the workbook properties

function main(workbook: ExcelScript.Workbook) { 

   const _properties = workbook.getProperties();
   const _title = properties.getTitle();
   const _subject = properties.getSubject();
   const _author = properties.getAuthor();
   const _comments = properties.getComments();

   const _dataProperties : i_WorkbookMetaData = {
      title : _title || "(Not Set)"
      sibject : _subject || "(Not Set)"
      author : _author || "(Not Set)"
      comments : _comments || "(Not Set)"
   };

   displayPropertiesInSheet(workbook, _dataProperties);
}

interface i_WorkbookMetaData{
   title : string;
   subject : string;
   author : string;
   comments : string;
}

function displayPropertiesInSheet(
   workbook: ExcelScript.Workbook,
   properties: i_WorkbookMetaData) {

   const _sheet = workbook.getActiveWorksheet();
   const _headerRange = _sheet.getRange("A1:B1");
   _headerRange.setValues([["Property","Value"]]);
   const _dataRange = _sheet.getRange("A2:B5");
   const _propertiesArray = [
      ["Title", properties.title],
      ["Title", properties.title],
      ["Title", properties.title],
      ["Title", properties.title],
   ];
   _dataRange.setValues(_propertiesArray);
}

Add-ins

link - learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-workbooks 

Add-ins - Get Workbook Properties

Excel.run(function (context) { 
   const props = context.workbook.properties;
   props.load([
      "title", "subject", "author", "comments"
   ]);
   await context.sync();
   console.log(props.author);
}

Add-ins - Close

Excel.run(function (context) { 
   context.workbook.close(Excel.CloseBehavior.save);
});

Office.context.documents.getFilePropertiesAsync() 

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