Share via

Getting Issue while Copy Sheet using Office JS , "errorLocation":"Worksheet.copy"

Anonymous
2023-08-19T11:19:15+00:00

Application : Excel web Add-in office js using Angular

Scenario : When Started Copy a sheet in Excel Web Add-in application using button and then moved to another Blank excel workbook getting 500 issue in web Add-in application. Below is the debug Info

Debug Info :

{"code":"GeneralException","message":"There was an internal error while processing the request.","errorLocation":"Worksheet.copy","statement":"var copy = worksheet.copy(...);",

"surroundingStatements":["var workbook = context.workbook;","var worksheets = workbook.worksheets;","var worksheet = worksheets.getItem(...);",

"// >>>>>","var copy = worksheet.copy(...);","// <<<<<","copy.name = ...;","copy.visibility = ...;","copy.position = ...;",

"var worksheet1 = worksheets.getItem(...);","worksheets.load([\"name\"]);"],

"fullStatements":["var workbook = context.workbook;","var worksheets = workbook.worksheets;",

"var worksheet = worksheets.getItem(\"My_Template\");","var copy = worksheet.copy(\"None\", worksheet);",

"copy.name = \"State Tax Rate\";","copy.visibility = \"Visible\";","copy.position = 2;",

"var worksheet1 = worksheets.getItem(\"State Tax Rate\");","worksheets.load([\"name\"]);"]}

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2023-08-22T01:40:05+00:00

    Hi Mukul,

    Unfortunately, I do not have any more troubleshooting to offer, there are knowledgeable experts on the platform and I hope someone else will take a look at your issue.

    Thanks, Sola

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-08-21T05:08:47+00:00

    Hi Sola

    I appreciate your efforts, but still it is not resolved we are directly using CDN office.js script in our application in index.html
    and also I tried with latest version of office.js npm package which is 1.1.88

    <html lang="en"> <head><meta charset="utf-8" /><title>My Application </title><base href="/" /><link rel="icon" type="image/x-icon" href="favicon.ico" /><script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script></head>
    </html>

    Regards

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-08-21T04:14:10+00:00

    Thanks for the feedback. You may need to update your JS version, you can do this by going to https://appsforoffice.microsoft.com/lib/1/hosted/office.js and downloading and replacing the office.js file in your add-in project folder.

    Best, Sola

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-08-20T10:31:40+00:00

    Hi Sola,

    Thanks for your reply.

    Issue is not with the Position of copying a sheet with our application it is working fine when I am staying on same excel in which my add is running till copying process is getting completed.

    Issue occurs only when say I initiated Copying process and I moved or switch to another opened blank Excel or workbook, I am getting above issue 500.

    problem occurs only when I switch to another excel where my add in is not running. seems like Excel context is changed when I switch between Excel application.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2023-08-19T15:52:28+00:00

    Hi Mukul,

    I’m sorry to hear that you are having trouble with copying a worksheet using Office JS. This seems to be a known issue that has been reported by other users as well. According to the documentation https://learn.microsoft.com/office/dev/add-ins/excel/excel-add-ins-worksheets, the worksheet.copy() method requires two parameters: the position where the new worksheet should be added, and the worksheet to be copied. The position can be one of the following values: “Before”, “After”, “Beginning”, “End”, or “None”. If you use “None”, the new worksheet will not be added to the workbook, but you can still access it through the returned Worksheet object. However, some users have reported that using “Before” or “After” causes an error, and that using “None” works only if the workbook has at least one other worksheet1. A possible workaround is to use “Beginning” or “End” instead of “None”, and then move the new worksheet to the desired position using the worksheet.position property. Alternatively, you can try using the workbook.worksheets.add() method to create a new worksheet, and then copy the values and formats from the original worksheet using range.copyFrom() or range.copyFromSpecial().

    I hope this helps you resolve your issue.

    Regards, Sola

    Was this answer helpful?

    0 comments No comments