本帖最后由 lin666 于 2018-5-9 20:53 编辑
注明:可以用任意的excel表格 用我的代码和步骤重现我的问题
步骤:1 用我如下的代码在网页上打开一张excel表格test,截图如下:
保存到电脑取名为1;
2 继续在网页上打开表格1,截图如下
;
3 再次打开表格test,表格变成这样
,代码如下:测试表格无法上传,可用任意excel表格按我的步骤重现我的问题。
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
-->
<link href="Content/gc.spread.sheets.excel2013white.11.0.0.css" rel="stylesheet" />
<script src="Scripts/jquery-1.10.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/gc.spread.excelio.11.0.0.min.js" type="text/javascript"></script>
<script src="Scripts/FileSaver.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/fonts.js"></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:1100px; height:670px;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"));
var excelIo = new GC.Spread.Excel.IO();
spread.options.highlightInvalidData = true;
GC.Spread.Common.CultureManager.culture("zh-cn");
$("#loadExcel").click(function () {
var excelFile = document.getElementById("fileDemo").files[0];
// here is excel IO API
excelIo.open(excelFile, function (json) {
var workbookObj = json;
spread.fromJSON(workbookObj);
//删除自带的表格
spread.removeSheet(0);
//设置滚动条
spread.options.scrollbarMaxAlign = true;
spread.options.scrollbarShowMax = true;
spread.options.showHorizontalScrollbar = $(this).prop("checked");
spread.options.showVerticalScrollbar = $(this).prop("checked");
var sheet1 = spread.getSheet(0);
var sheet2 = spread.getSheet(1);
sheet1.options.rowHeaderVisible = false;
sheet1.options.colHeaderVisible = false;
sheet2.options.rowHeaderVisible = false;
sheet2.options.colHeaderVisible = false;
sheet1.options.gridline.showHorizontalGridline = false;
sheet1.options.gridline.showVerticalGridline = false;
sheet2.options.gridline.showHorizontalGridline = false;
sheet2.options.gridline.showVerticalGridline = false;
sheet1.addColumns(0, 3);
sheet2.addColumns(0, 3);
}, function (e) {
alert(e.errorMessage);
if (e.errorCode === 2/*noPassword*/ || e.errorCode === 3 /*invalidPassword*/) {
$("#password").select();
}
}, { });
});
$("#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>
|
|