Why worksheet Id changing after reopening document

2019-07-08 05:54发布

问题:

In my Excel tab-pane addin after adding worksheet(manually/programmatically) and running code below I have worksheet object where id is "{040E0F18-0F61-4CD9-886D-95112C925793}", then I save workbook, close and open again, run code below and it shows me that the worksheet.id now is "{00000000-0001-0000-0000-000000000000}"! In office.js reference about worksheet id:

The value of the identifier remains the same even when the worksheet is renamed or moved. Read-only.

Excel.run(function (ctx) {
    var sheet = ctx.workbook.worksheets.getActiveWorksheet().load('name');
          return ctx.sync().then(function () {  
                console.log(sheet);
          });
  });

回答1:

The documentation was (very) recently updated to clarify this. The ID shouldn't change within the same session (i.e. while the document is open). They do however change between sessions (i.e. when a document is opened and closed).

From the latest documentation:

Returns a value that uniquely identifies the worksheet in a given workbook. The value of the identifier remains the same even when the worksheet is renamed or moved. Values change with each session of the file being opened. Read-only.