How to open new SpreadJS file type of .sjs in a Blazor WASM application?

222 Views Asked by At

SpreadJS just released v16. How do I open the new file type of .sjs? This is a compressed/zipped file.

I tried creating a javascript Blob and passing this blob to spread.open(). See below.

openFileWithSjs: function (host, sjsFile) {
        try {
            var blob = new Blob([sjsFile]);
            var spread = GC.Spread.Sheets.findControl(host);

            spread.open(blob, () => {
                console.log("Sjs opened");
            }, (e) => {
                console.log(e.errorMessage);
            });
            return "Bidder successfully opened."
        }
        catch (e) {
            console.log(e);
            return "Error opening Bidder with ssjson. Error message: " + e;
        }
    }
1

There are 1 best solutions below

0
On

I figured this out after reaching out to GrapeCity support.

First, I want to explain what my 'sjsFile' parameter is when it gets passed to my javascript function. sjsFile is a byte array that I get by making an http call in a service class. See below.

var result = await _http.GetByteArrayAsync("sample-data/sjsFile.sjs");

Next, I use IJSRuntime to pass the sjsFile parameter to my javascript function.

var result = await JSRuntime.InvokeAsync<string>("sjsAdaptor.openFileWithSjs", host, sJsFile);

Finally, I use my sjsFile which is of type byte[] to create a Blob object. Then I pass that object to the spread.open() function. NOTE: You must include the blob options parameter of '{ type: "application/zip" }' when creating your blob. I spent a full day trying to figure out why I couldn't open my blob file when all I needed to do was add '{ type: "application/zip" }'.

 var blob = new Blob([sjsFile], { type: "application/zip" });
        var spread = GC.Spread.Sheets.findControl(host);
        spread.open(blob, () => {
            console.log("Sjs opened");
        }, (e) => {
            console.log(e.errorMessage);
        });

I hope this helps with the upgrade to v16 and saves you some time.