本帖最后由 lin666 于 2018-3-8 10:11 编辑
上面那个问题暂时算了 这个部署到服务器上 我使用上面的代码 也把excel文件放到相应的目录下了 为什么不能读取文件
我把导入服务器文件的代码写在了 导入本地文件的button里面。
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<!--<meta name="viewport" content="width=device-width, initial-scale=1.0" />-->
<!--<meta name="spreadjs culture" content="zh-cn" />-->
<link rel="stylesheet" href="Content/gc.spread.sheets.excel2013white.11.0.0.css" />
<script src="Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="Scripts/gc.spread.sheets.all.11.0.0.min.js" type="text/javascript"></script>
<script src="Scripts/FileSaver.js" type="text/javascript"></script>
<script src="Scripts/gc.spread.excelio.11.0.0.min.js" type="text/javascript"></script>
<script src="Scripts/gc.spread.sheets.charts.11.0.0.min.js" type="text/javascript"></script>
<script src="Scripts/gc.spread.sheets.resources.zh.11.0.0.min.js" type="text/javascript"></script>
<script src="Scripts/excel_data.js" type="text/javascript"></script>
<style type="text/css">
.inputContainer {
width: 390px;
height: auto;
border: 1px solid gray;
padding: 6px 12px;
margin: 10px;
float: left;
}
.input {
font-size: 14px;
width: 300px;
height: 20px;
border: 0px;
outline: none;
}
.button {
font-size: 16px;
height: 30px;
padding: 6px 12px;
width: 80px;
}
.top-options {
height: 70px;
}
</style>
</head>
<body style='font-size:14px;'>
<div class="demo-options">
<div class="top-options">
<div class="inputContainer">
<input type="file" id="fileDemo" class="input">
<input type="button" id="loadExcel" value="导入文件" class="button">
</div>
<div class="inputContainer">
<input type="text" id="exportFileName" value="export.xlsx" class="input" style="font-size: 16px">
<input type="button" id="saveExcel" value="导出文件" class="button">
</div>
</div>
</div>
<div class="sample-turtorial">
<div id="ss" style="width:100%; height:700px;border: 1px solid gray"></div>
<div class="demo-options">
<div class="option-row">
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
spread.fromJSON(jsonData);
var excelIo = new GC.Spread.Excel.IO();
var sheet = spread.getActiveSheet();
spread.options.scrollbarMaxAlign = true;
spread.options.scrollbarShowMax = true;
//sheet.options.isProtected = true;
//sheet.getCell(1, 1).locked(true);
$("#loadExcel").click(function () {
var excelIo = new GC.Spread.Excel.IO();
var excelFilePath = 'resources/Excel/demo.xlsx';
var xhr = new XMLHttpRequest();
xhr.open('GET', excelFilePath, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
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();
});
$("#saveExcel").click(function () {
var fileName = $("#exportFileName").val();
var password = $("#password").val();
if (fileName.substr(-5, 5) !== '.xlsx') {
fileName += '.xlsx';
}
var json = spread.toJSON();
// here is excel IO API
excelIo.save(json, function (blob) {
saveAs(blob, fileName);
}, function (e) {
// process error
console.log(e);
}, { password: password });
});
});
</script>
</body>
</html> |