[英]How to open new SpreadJS file type of .sjs in a Blazor WASM application?
SpreadJS just released v16. SpreadJS 刚刚发布了 v16。 How do I open the new file type of.sjs?
如何打开新文件类型.sjs? This is a compressed/zipped file.
这是一个压缩/压缩文件。
I tried creating a javascript Blob and passing this blob to spread.open().我尝试创建一个 javascript Blob 并将此 Blob 传递给 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;
}
}
I figured this out after reaching out to GrapeCity support.在联系 GrapeCity 支持人员后,我发现了这一点。
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.首先,我想解释一下当我的“sjsFile”参数被传递到我的 javascript function 时它是什么。sjsFile 是一个字节数组,我通过在服务 class 中调用 http 获得它。见下文。
var result = await _http.GetByteArrayAsync("sample-data/sjsFile.sjs");
Next, I use IJSRuntime to pass the sjsFile parameter to my javascript function.接下来,我使用 IJSRuntime 将 sjsFile 参数传递给我的 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.最后,我使用 byte[] 类型的 sjsFile 创建一个 Blob object。然后我将该 object 传递给 spread.open() function。注意:您必须包含 '{ type: "application/ zip" }' 创建 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" }'.
我花了一整天的时间试图弄清楚为什么我需要做的就是添加 '{ type: "application/zip" }' 而无法打开我的 blob 文件。
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.我希望这有助于升级到 v16 并为您节省一些时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.