Unable to Load an xlsm file onto an existing excel workbook(.xlsx) with the help of SpreadJS using OfficeJS

75 Views Asked by At

I am working on an Web Addin for Excel using officeJS.

My requirement is to allow the user to select a file(.xlsm) from their local drive and load it onto the existing excel workbook as a new sheet.

I was going through SpreadJS which might help with my requirement,

However it looks like SpreadJS can only be used to create/edit/display spreadsheets on web application.

But I wanted to know if there is any way where I can use SpreadJS to convert the xlsm file into a JSON object and then use OfficeJS to load it into a different sheet?

This is what I tried

this.spread =  new GC.Spread.Sheets.Workbook("");

selectedFileChange(e: any) {
        this.selectedFile = e.target.files[0];
        this.openFileType = this.getFileType(this.selectedFile);
        this.open()
    }
getFileType(file: File) {
        if (!file) {
            return;
        }

        const fileName = file.name;
        const extensionName = fileName.substring(fileName.lastIndexOf(".") + 1);

        if (extensionName === 'sjs') {
            return 'sjs';
        } else if (extensionName === 'xlsx' || extensionName === 'xlsm') {
            return 'xlsx';
        } else if (extensionName === 'ssjson' || extensionName === 'json') {
            return 'ssjson';
        } else if (extensionName === 'csv') {
            return 'csv';
        }
    }
open() {
        const file = this.selectedFile;
        if (!file) {
            return;
        }

        const fileType = this.getFileType(file);
        const options = this.getOptions('open');

        if (fileType === 'sjs') {
            this.spread.open(file, function() {}, function() {}, options);
        } else {
            this.spread.import(file, function() {}, function() {});
        }
    }

this.getOptions('open'); --> this function returns preset options.

Can someone help me with this requirement?

0

There are 0 best solutions below