请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

风起的日子

注册会员

3

主题

7

帖子

26

积分

注册会员

积分
26
风起的日子
注册会员   /  发表于:2019-11-28 19:14  /   查看:4657  /  回复:4
1金币

在sample.js中增加如下方法:
function OpenFile() {

    var excelFilePath = "../test.xlsx";
    var excelIo = new GC.Spread.Excel.IO();
    var excelFilePath = 'resources/Excel/importExcel.xlsx';
    var xhr = new XMLHttpRequest();
    xhr.open('GET', excelFilePath, true);
    xhr.responseType = 'blob';
    xhr.onload = function (e) {
        alert(this.status)
        if (this.status == 200) {
            // get binary data as a response
            var blob = this.response;
            // convert Excel to JSON
            excelIo.open(blob, function (json) {
                var workbookObj = json;
                spread.fromJSON(workbookObj);
            }, function (e) {
                // process error
                alert(e.errorMessage);
            }, {});
        }
    };

    xhr.send();
}  没有任何反应?如何解决?

附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册

最佳答案

查看完整内容

应该是出现了跨域的问题,建议百度上搜索下相关的解决方案, JAVA应用SpreadJS实现服务器端导入导出 这有一个完整的实例: https://gcdn.grapecity.com.cn/showtopic-37389-1-1.html

4 个回复

最佳答案
最佳答案
Fiooona
论坛元老   /  发表于:2019-11-28 19:14:03
来自 5#
应该是出现了跨域的问题,建议百度上搜索下相关的解决方案,

JAVA应用SpreadJS实现服务器端导入导出 这有一个完整的实例:
https://gcdn.grapecity.com.cn/showtopic-37389-1-1.html
组件化表格编辑器(预览版)试用进行中,点击了解详情!
请点击评分,对我的服务做出评价!5分为非常满意!
回复 使用道具 举报
Fiooona
论坛元老   /  发表于:2019-11-29 09:18:17
2#
你有把项目部署吗?看下控制台是不是有跨域的报错?可以跟下代码看具体程序走到哪一步后就没反应了?
组件化表格编辑器(预览版)试用进行中,点击了解详情!
请点击评分,对我的服务做出评价!5分为非常满意!
回复 使用道具 举报
风起的日子
注册会员   /  发表于:2019-11-29 10:19:48
3#
xhr.onload = function (e) {
        alert(this.status)

执行不到这块,alert没有弹出
回复 使用道具 举报
风起的日子
注册会员   /  发表于:2019-11-29 13:49:23
4#
function initSpread() {
    //formulabox
    fbx = new spreadNS.FormulaTextBox.FormulaTextBox(document.getElementById('formulabox'));
    fbx.workbook(spread);

    //setCellContent();
    //setFormulaContent();
    //setConditionalFormatContent();
    //setTableContent();
    //setSparklineContent();
    //setCommentContent();
    //setPictureContent();
    //setDataContent();
    //setSlicerContent();
    //addChartContent();
    //addBarCodeConent();
    //addShapeConent();

    var excelFilePath = "../test.xlsx";
    var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));

    var excelIo = new GC.Spread.Excel.IO();
    var xhr = new XMLHttpRequest();
    xhr.open('GET', excelFilePath, true);
    xhr.responseType = 'blob';
    alert(xhr.status)
    xhr.onload = function (e) {
        alert(this.status)
        if (this.status == 200) {
            // get binary data as a response
            var blob = this.response;
            // convert Excel to JSON

            excelIo.open(blob, function (json) {
                var workbookObj = json;
                spread.fromJSON(workbookObj);
            }, function (e) {
                // process error
                alert(e.errorMessage);
            }, {});
        }
    };
    xhr.send();
   
}
显示xhr.status=0
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部