Office Samples

link - learn.microsoft.com/en-us/office/dev/add-ins/overview/create-an-office-add-in-from-script-lab 

You may come across code samples that use JQuery.
You may see code samples that contain JQuery in Script Lab.


npm install jquery --save 
npm install @types/jquery --save-dev

<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.js"></script> 

( function () { 
   Office.initialize = function (reason) {
      $(document).ready(function) () {
         $('body').html('display some text');
      });
   };
}) ();


Home.html

  <button class="Button Button--primary" id="shadecell-button"> 
     <span class="Button-icon"><i class="ms-Icon ms-Icon--plus"></i></span>
     <span class="Button-label" id="button-text"></span>
  </button>

Home.js

Office.initialize = function (reason) { 
    $(document).ready(function () {

       $('#button-text').text("Shade Cell");

       $('#shadecell-button').click(shadeCell);
    });
};

function shadeCell() {
    Excel.run(function (ctx) {
        var _range = ctx.workbook.worksheets.getItem("Sheet1").getRange("A1");

        return ctx.sync()
            .then(function () {
                _range.format.fill.color = "orange";
            })

            .then(ctx.sync);
    })
    .catch(errorHandler);
}



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