Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Microsoft office.js Excel add-in - retrieve worksheet/workbook unique ID using javascript/react

$
0
0

We have built an Excel Task pane add in that primarily works with worksheets. As per our requirement we wants to identify excel with there unique ID's whenever user close's the excel and reopen it again.

Sample code to load excel ID from workbook:

Office.initialize = () => {
                Excel.run(function (context) {
                    var sheet = context.workbook.worksheets.getItem("Sheet1");                 
                    const worksheets = context.workbook.worksheets;
                    //tried to load ID property using below code
                    worksheets.load("id, name");
                    worksheets.load(["items/id", "items/name"]);
                    worksheets.load(["id", "name", "worksheet/id"]);
                    sheet.load(["items/id", "items/name"]);
                    context.sync();
                    //below is the code to print excel ID
                    console.log(sheet.id);
                    // OR
                    worksheets.items.forEach(ws => {
                      console.log(`id: ${ws.id}, name: ${ws.name}`)
                    });
                }).catch(function (error) {
                  console.log(error.debugInfo);
              });
            }

we are receiving below error: Uncaught RichApi.Error: The property 'id' is not available. Before reading the property's value, call the load method on the containing object and call "context.sync()" on the associated request context.


Viewing all articles
Browse latest Browse all 88835


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>