0

I have a problem, I'm trying to update a worksheet inside excel in Add-in Javascript API with encoded content in Base64 but I don't want to create a new worksheet like the function insertWorksheetsFromBase64() does , but just insert the data in my existing worksheet. Hope I was been clear enough. So if you know how to do it that will be really helpful.

Thanks for your Help guys.

T1masv
  • 1
  • 1

1 Answers1

0

I had the same problem and i this is how i dealt with it.

// initialize workbook
// get the active sheet you want to update and load name property
let workbook = context.workbook;
let activeSheet = context.workbook.worksheets.getActiveWorksheet();
activeSheet.load("name");

// load the base64 sheet to your workbook with name newSheet
workbook.insertWorksheetsFromBase64(yourbase64, { sheetNamesToInsert: ["newSheet"]});

// grab the worksheet object
const newSheet = workbook.worksheets.getItem("newSheet");

// grab the active/used range from the worksheet
const activeRange = newSheet.getUsedRangeOrNullObject();

// sync context so objects will be available
await context.sync();

// activate the activeSheet since it will be inactive after loading the base64 earlier
activeSheet.activate();

// get the active cell in the activeSheet (this will be the origin when we paste the data)
let workingSheet = context.workbook.getSelectedRange();

// copy the active/used range we initialized earlier to the activeSheet/workingSheet
workingSheet.copyFrom(activeRange, Excel.RangeCopyType.all, false, false);

// delete the new sheet
newSheet.delete();

// sync context again
await context.sync();
jasjamjos
  • 79
  • 6