Reputation: 3052
I'm creating an Office Add-in that runs in a task pane which is launched by clicking a button from the command ribbon. The app itself is a simple lookup tool. You select a cell (or range of cells) and it hits another endpoint (one I've setup) to lookup and return related information.
On most spreadsheets, everything works as expected, however on some spreadsheets, it seems to break trying to hit the endpoint, and I get this error:
ItemNotFound: The requested resource doesn't exist.
However, I know the resource does exist and that it is working properly because I can copy the data over to another sheet within the same file and the add-in works fine; however, I can't seem to get it working on this particular main sheet.
Any ideas?
Upvotes: 2
Views: 2787
Reputation: 3052
I was mistaken, my endpoint was not related to this issue.
Turns out I was having issues with Worksheet -> getRange() as a result of having spaces in the sheet name and probably using it incorrectly.
Here's an example. This type of code worked for me just fine if there were no spaces in the sheet name:
Excel.run(async (ctx) => {
var sheetName = 'Sheet1';
var rangeAddress = 'A1:A4';
var address = sheetName +"!"+ rangeAddress;
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(address);
await ctx.sync();
...
However, if I tried to use the same code, on a sheet name that had spaces, everything would blow up:
var sheetName = 'Sheet Two';
What worked for me (Just pass the "range" part to the getRange() function, not my whole address):
Excel.run(async (ctx) => {
var sheetName = 'Sheet1';
var rangeAddress = 'A1:A4';
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(rangeAddress);
await ctx.sync();
...
Upvotes: 1
Reputation: 1403
This is likely an error with the add-in and not with your external resource. Excel will throw ItemNotFound: The requested resource doesn't exist.
when you try to use range.getUsedRange() and there is nothing in the range.
If you log the error with OfficeHelpers.Utilities.log() (found here), it will provide you the context you need to see why it threw that error.
Upvotes: 1