pkabirrvelixo's avatar
pkabirrvelixo
Iron Contributor
Oct 24, 2024
Status:
New

API call to move or copy a single worksheet to a new workbook

In our legacy COM add-in, we have a very frequent use case when a user does a "data drill-down" operation, which produces a detailed data view on a separate worksheet called "Drilldown".

 

 

 

 

To avoid spoiling the original workbook with multiple ad-hoc drill-down views, we then move those sheets to a new workbook.

 

It is very convenient and easy to do with our legacy COM add-in, because Excel's interop API supports the "move to a new workbook" operation for a single worksheet.

 

However, with Office.js we need to resort to crazy and inefficient black magic:

  • We first copy the entire current workbook to a new workbook as base64
  • Then, using a BroadcastChannel (since a new workbook has a separate add-in runtime), we issue a "command" to clean up everything except the new worksheet.

This is comparatively slow and inefficient, and it also produces flicker.

 

Can we please have an API call to easily move only the specified worksheets to a new workbook?

  • AdrianWu as discussed, I explored the possibility of using the insertWorksheetsFromBase64 function, thanks for this suggestion!

     
    While this is likely work, it still requires us to pass the entire source workbook's base64 through some sort of MessageChannel or BroadcastChannel before we discard most of it and append only one worksheet.
     
    It would be more efficient and savvy if Excel.createWorkbook could accept the same options object, allowing us to only pick a subset of the source workbook's worksheets.