none
Excel 1.1 JavaScript API worksheet.delete() fails in Excel online/web app with "An internal error has occurred." RRS feed

  • Question

  • worksheet.delete() works fine in Office Client but fails in the Excel Online / Web apps. The docs indicate that this should work in Excel Online also.

    sample code below can be pasted in an Excel (2016) Task Pane app using a new workbook and then create a try to delete "Sheet2".

    <!DOCTYPE html>
    <html>
    <head>
       <meta charset="UTF-8" />
       <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
       <title></title>
       <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
     
       <link href="../../Content/Office.css" rel="stylesheet" type="text/css"/>
     
       <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
       
       <script>
          (function () {
     
             "use strict";
     
             var bindingId = "TestBindingId";
             var msg = "";
     
             // The initialize function must be run each time a new page is loaded
             Office.initialize = function (reason) {
                $(document).ready(function () {
                   $('#delete-sheet').click(deleteSheet);
     
                   
                   $('#clear-msg').click(clearMsg);
                });
             };
     
     
             function deleteSheet()
             {
                var sheetName = $("#sheet-to-delete").val();
     
                Excel.run(function (ctx)
                {
                   var worksheet = ctx.workbook.worksheets.getItem(sheetName);
                   worksheet.delete();
     
     
                   return ctx.sync().then(function () {
                      // do whatever
     
                   }).catch(function (error)
                   {
                      write(error.message);
                   });
     
                }).catch(function (error) {
                   write(error.message);
                });
             }
     
     
             function write(message) 
                msg += message + "<br/><br/>";
                $('#message').html(msg);
             }
     
             function clearMsg() {
                msg = "";
                $('#message').html("");
             }
     
          })();
     
       </script>
     
    </head>
    <body>
    <div id="content-main">
     
       <div style="padding10px">
          <h1>Test Delete</h1>
     
          Sheet Name
          <input id="sheet-to-delete" type="text" value="Sheet2"/>
     
          <br/>
          <button id="delete-sheet">Delete Sheet</button>
     
     
          <br />
          <br/>
          <button id="clear-msg">Clear Message</button>
     
          <br/><br/>
          Status
          <div id="message" style="background#e0e0e0padding15px;"></div>
       </div>
    </div>
    </body>
    </html>
    

    Wednesday, March 30, 2016 11:22 PM

Answers

  • Hi Edward,

    I retried this today and in a simple spreadsheet both getItem(sheetName).delete() and activeWorksheet.delete() both worked but in a more complex sheet the former still doesn't work. In the complex sheet I had a table binding on the sheet so not sure if that is causing the problem.

    I guess we can mark this as the answer but as a developer it is scary when something just "starts working" and you don't know why. Are there release notes or some other log of fixes on dev.office.com that the dev team makes?

    Thanks,

    Jim

    Tuesday, April 5, 2016 2:03 PM

All replies

  • Hi Jim,

    >> The docs indicate that this should work in Excel Online also.

    Could you share us the document which indicate this should work in Excel online? As the document below, Excel javascript API is for Excel 2016.

    # Excel JavaScript API programming overview
    https://dev.office.com/docs/add-ins/excel/excel-add-ins-javascript-programming-overview?product=excel

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, March 31, 2016 10:09 AM
  • Hi Edward,

    I guess what I meant to say is that the docs do not specify that Excel Online is not supported. In most of the docs they call out lack of or limited support for Excel Online but they do not for worksheet.delete().

    Also, there are other Excel 1.1 APIs that do work in Excel Online such as getting sheets.  For example:

    Excel.run(function (ctx) 
             {
                var worksheets = ctx.workbook.worksheets.load("name");

    ...

    Thanks,

    Jim

    Thursday, March 31, 2016 4:18 PM
  • Hi Jim,

    I made a test with worksheet.delete and activeWorksheet.name in the code below, first did not work, and second did work.

    Excel.run(function (ctx) {  
        var activeWorksheet = ctx.workbook.worksheets.getActiveWorksheet();
        activeWorksheet.load('name');
        return ctx.sync().then(function() {
                console.log(activeWorksheet.name);
        });
    }).catch(function(error) {
            console.log("Error: " + error);
            if (error instanceof OfficeExtension.Error) {
                console.log("Debug info: " + JSON.stringify(error.debugInfo));
            }
    });

    Since the document is not clear which api is supported in Excel online, for this issue, I suggest you submit a feedback in the link below.

    http://officespdev.uservoice.com

    With your feedbacks, the Excel api would be better and better.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, April 1, 2016 6:36 AM
  • Hi Edward,

    I retried this today and in a simple spreadsheet both getItem(sheetName).delete() and activeWorksheet.delete() both worked but in a more complex sheet the former still doesn't work. In the complex sheet I had a table binding on the sheet so not sure if that is causing the problem.

    I guess we can mark this as the answer but as a developer it is scary when something just "starts working" and you don't know why. Are there release notes or some other log of fixes on dev.office.com that the dev team makes?

    Thanks,

    Jim

    Tuesday, April 5, 2016 2:03 PM
  • Hi Jim,

    I agree with you, you could mark your reply as answer.

    As you know, Office add ins is a new product, I think it is not complete on document description and APIs. To improve document and apis, I would suggest you submit a feedback.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, April 6, 2016 2:25 AM
  • Edward,

    Thanks for the reply.  I've been sick this week and not online.  I'll try to be more patient especially with the docs since they have had a recent makeover and it is currently much more difficult to find information than it was before (I have submitted feedback on this).

    Jim

    Friday, April 8, 2016 10:27 AM