spreadjs~~一个Excel在线编辑的工具
spreadjs的用法
专注于为中小企业提供做网站、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业萧县免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
var spreaDNS = GC.Spread.Sheets; var spread = new spreadNS.Workbook($("#spreadjsExc")[0], {sheetCount:0}); var excelIO = new GC.Spread.Excel.IO(); var fbx = new spreadNS.FormulaTextBox.FormulaTextBox(document.getElementById('formulabox')); fbx.workbook(spread); var _blob = parent.$("#fileImportIO").data("fileIO"); var readonly = parent.$("#fileImportIO").attr('readonly'); excelIO.open(_blob, function (spreadJson) { function updateActiveCells() { for (var i = 0; i < spread.getSheetCount(); i++) { var sheet = spread.getSheet(i); columnIndex = sheet.getActiveColumnIndex(), rowIndex = sheet.getActiveRowIndex(); if (columnIndex !== undefined && rowIndex !== undefined) { spread.getSheet(i).setActiveCell(rowIndex, columnIndex); } else { spread.getSheet(i).setActiveCell(0, 0); } if(readonly == "true"){ sheet.options.isProtected = true;//禁止编辑 sheet.options.colHeaderVisible = false; sheet.options.rowHeaderVisible = false;//取消头跟左侧工具栏 spread.options.newTabVisible = false;//取消新建sheet按钮 }else{ sheet.options.isProtected = false; } } } if (spreadJson.version && spreadJson.sheets) { spread.unbindAll(); spread.fromJSON(spreadJson); //attachSpreadEvents(true); updateActiveCells(); spread.focus(); fbx.workbook(spread); onCellSelected(); //syncSpreadPropertyValues(); //syncSheetPropertyValues(); } }, function (e) { if (e.errorCode === 0 || e.errorCode === 1) { //alert("error"); } }); if(readonly == "true"){ $("#saveFile").remove(); $("#close").remove(); } //spread.print();打印 function onCellSelected() { $("#addslicer").addClass("hidden"); var sheet = spread.getActiveSheet(), row = sheet.getActiveRowIndex(), column = sheet.getActiveColumnIndex(); if (showSparklineSetting(row, column)) { setActiveTab("sparklineEx"); return; } var cellInfo = getCellInfo(sheet, row, column), cellType = cellInfo.type; syncCellRelatedItems(); updatePositionBox(sheet); updateCellStyleState(sheet, row, column); var tabType = "cell"; clearCachedItems(); // add map from cell type to tab type here if (cellType === "table") { tabType = "table"; syncTablePropertyValues(sheet, cellInfo.object); $("#addslicer").removeClass("hidden"); } else if (cellType === "comment") { tabType = "comment"; syncCommentPropertyValues(sheet, cellInfo.object); } setActiveTab(tabType); } $("#saveFile").click(function(e){ e.preventDefault(); var json = spread.toJSON({includeBindingSource: true}); json = JSON.stringify(json); var xhr = new XMLHttpRequest(); var buttonid = parent.$("#fileImportIO").attr("buttonid"); var _beanid = parent.$("#fileImportIO").attr("_beanid"); var url = '/map/download!save?_beanid='+_beanid+'&buttonid='+buttonid; xhr.open("POST", url , true); xhr.onload = function (oEvent) { if(this.status == 200){ if(this.response == "success"){ alert('保存成功'); } } }; xhr.send(json); /*excelIO.save(json, function (blob) { }, function (e) { //alert(e); });*/ }); $("#printFile").click(function(e){ e.preventDefault(); spread.print(); }); $("#exportFile").click(function(e){ e.preventDefault(); var json = spread.toJSON({includeBindingSource: true}); var _fname = parent.$("#fileImportIO").attr("filename"); excelIO.save(json, function (blob) { saveAs(blob,_fname+".xlsx"); }, function (e) { alert(e); }); }); $("#close").click(function(e){ e.preventDefault(); var _beanid = parent.$("#fileImportIO").attr("_beanid"); var buttonid = parent.$("#fileImportIO").attr("buttonid"); var url = '/map/download!delete?_beanid='+_beanid+'&buttonid='+buttonid; var _ajax = { url : url, success : function(data){ parent.$("#fileImportIO").closest("#wapper").find(".ui-dialog-titlebar").find(".ui-dialog-titlebar-close").click(); } }; $.ajax(_ajax); }); $("#closes").click(function(e){ parent.$("#fileImportIO").closest("#wapper").find(".ui-dialog-titlebar").find(".ui-dialog-titlebar-close").click(); });
网站栏目:spreadjs~~一个Excel在线编辑的工具
文章分享:http://myzitong.com/article/gjepee.html