-
I am building an Excel Add-in and would like to create a new workbook that is a copy of the currently open workbook. I am able to create an empty workbook using Excel.createWorkbook(), I am able to read the currently open file as plaintext using Office.context.document.getFileAsync(), and I am even able to create a duplicate of an existing file using Excel.createWorkbook(base64) where base64 is the output of an online converter like this one. However, I am unable to connect these pieces together. In particular, I've found that Office.context.document.getFileAsync() and its documentation don't clearly explain how to get the necessary base64 format of the file. As I said, I can load the file as plaintext or a byte array, but not base64. I believe that once I can figure this part out, I can use the base64 to create a duplicate of the currently open file. In the docs, there is a section about creating a copy of an existing workbook. The docs go on to say that:
The docs claim that we can get the current workbook as a base64-encoded string, but the function mentioned requires a FileType which only has 3 options: Text, Compressed Byte Array, and PDF. None of these are base64 encoded. Do I have to manually convert these myself? The documentation is a bit lacking in this area. Any help is appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Well, I finally broke down and pasted this entire question into ChatGPT. It worked. The key was to combine all of the byte arrays using file slicing (basically just concatenating the slices into one large array) and then throwing it into
|
Beta Was this translation helpful? Give feedback.
Well, I finally broke down and pasted this entire question into ChatGPT. It worked. The key was to combine all of the byte arrays using file slicing (basically just concatenating the slices into one large array) and then throwing it into
Buffer.from(new Uint8Array(fileContent)).toString('base64');
.