找回密码
 立即注册

QQ登录

只需一步,快速开始

armgong
金牌服务用户   /  发表于:2017-4-13 13:55  /   查看:3308  /  回复:1
请问GC.Spread.Excel.IO 可以从ArrayBuffer或者blob中导入么?我们的程序调用 c# WEB API 读取excel文件。目前的前端是直接将结果保存,代码如下:
function angularcall(projectdata) {
    angular.module('main.app', []).factory('CaculateService', ['$http', function ($http) {
        return new function () {
            this.DoCalculate = function () {
                $http.post("/api/ReadExcel/", projectdata, { responseType: 'arraybuffer' })
                      .success(function (data) {
                          var file = new Blob([data], { type: 'application/vnd.ms-excel.sheet.macroEnabled.12' });
                          var fileURL = URL.createObjectURL(file);
                          if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                              window.navigator.msSaveOrOpenBlob(file);
                          }
                          else {
                              window.open(fileURL);
                          }
                      }
                     )
               .error(function (data, status, header, config) {
                   encodedString = String.fromCharCode.apply(null, Uint8Array(data)),
                   decodedString = decodeURIComponent(escape(encodedString));
                   alert("计算出错:  " + decodedString);
               })
            }
        };
    }]);
    angular.injector(['ng', 'main.app']).get("CaculateService").DoCalculate();
}

请问如何将 上述代码中的arraybuffer或者Blob导入到spreadjs中?






1 个回复

倒序浏览
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2017-4-13 18:49:10
沙发
获取到blob之后调用excelIo的open方法打开文件,获取json,然后fromJSON展示
http://demo.gcpowertools.com.cn/ ... e/#/samples/ExcelIO
//import excel file to Spread.Sheets json
excelIo.open(excelFile, function (json) {
    var workbookObj = json;
    workbook.fromJSON(workbookObj);
}, function (e) {
    // process error
    console.log(e);
});
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部