1,066 questions
Inserting multiple SVG images into a spreadsheet asynchronously
Mitch Miller
0
Reputation points
This is an add-in for MS Excel built using the JavaScript API.
General task:
- Start with a worksheet that has a column of identifiers.
- User wants to add data. Uses checkboxes on form to select data fields. Clicks 'add data' button.
- Add-in reads identifiers and creates a query for each.
- Each query returns according to how long it takes and then a callback within the add-in transfers data to the sheet.
- Works fine for text data.
- In additional to text, images are generated for each row using code similar to
dataCell.select();
await context.sync();
Office.context.document.setSelectedDataAsync(imageData, imageOptions, function (asyncResult) {
- This set of calls works fine when one row is processed at a time.
- When multiple rows are returned, the images are scrambled -- some rows have several images stacked on top of one another; other rows have no image.
- What I assume is happening: one row's results come back and the dataCell.select() happens. Before the setSelectedDataAsync call can happen, another row of results comes back and the selection changes.
- How can I make the above work? Is there a way of locking a JavaScript function so only one 'thread' can execute at a time?
Microsoft 365 and Office Development Office JavaScript API
Microsoft 365 and Office Development Other
4,374 questions
Microsoft 365 and Office Excel For business Windows
3,887 questions
Sign in to answer