找回密码
 立即注册

QQ登录

只需一步,快速开始

mabh

注册会员

5

主题

7

帖子

49

积分

注册会员

积分
49
mabh
注册会员   /  发表于:2018-11-30 16:44  /   查看:2391  /  回复:1
image.png483035582.png
  1. <!DOCTYPE >
  2. <html>
  3.         <head>
  4.                 <meta name="spreadjs culture" content="zh-cn" />
  5.                 <meta charset="utf-8" />
  6.                 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7.                 <link rel="styleSheet" href="gc.spread.sheets.excel2013white.12.0.0.css" />
  8.                 <script src="TutorialSample/js/jquery-1.8.2.min.js"></script>
  9.                 <script src="gc.spread.sheets.all.12.0.0.min.js" type="text/javascript"></script>
  10.                 <script src="TutorialSample/js/FileSaver.js"></script>
  11.                 <script src="TutorialSample/js/spread/plugins/gc.spread.excelio.12.0.0.min.js"></script>
  12.                 <script src="gc.spread.sheets.resources.zh.12.0.0.min.js" type="text/javascript"></script>


  13.                 <style type="text/css">
  14.                         .sample-tutorial {
  15.                                 position: relative;
  16.                                 height: 100%;
  17.                                 overflow: hidden;
  18.                         }

  19.                         .sample-spreadsheets {
  20.                                 width: calc(100% - 280px);
  21.                                 height: 100%;
  22.                                 overflow: hidden;
  23.                                 float: left;
  24.                         }

  25.                         .options-container {
  26.                                 float: right;
  27.                                 width: 280px;
  28.                                 padding: 12px;
  29.                                 height: 100%;
  30.                                 box-sizing: border-box;
  31.                                 background: #fbfbfb;
  32.                                 overflow: auto;
  33.                         }

  34.                         .sample-options {
  35.                                 z-index: 1000;
  36.                         }

  37.                         .inputContainer {
  38.                                 width: 100%;
  39.                                 height: auto;
  40.                                 border: 1px solid #eee;
  41.                                 padding: 6px 12px;
  42.                                 margin-bottom: 10px;
  43.                                 box-sizing: border-box;
  44.                         }

  45.                         .input {
  46.                                 font-size: 14px;
  47.                                 height: 20px;
  48.                                 border: 0;
  49.                                 outline: none;
  50.                                 background: transparent;
  51.                         }

  52.                         .button {
  53.                                 height: 30px;
  54.                                 padding: 6px 12px;
  55.                                 width: 80px;
  56.                                 margin-top: 6px;
  57.                         }

  58.                         .group {
  59.                                 padding: 12px;
  60.                         }

  61.                         .group input {
  62.                                 padding: 4px 12px;
  63.                         }
  64.                 </style>

  65.         </head>

  66.         <body style='font-size:14px;'>
  67.                 <div class="sample-tutorial">
  68.                         <div id="ss" style="width:100%; height:360px;border: 1px solid gray;"></div>
  69.                         <div class="options-container">
  70.                                 <div class="option-row">
  71.                                         <div class="inputContainer">
  72.                                                 <input type="file" id="fileDemo" class="input">
  73.                                                 <input type="button" id="loadExcel" value="import" class="button">
  74.                                         </div>
  75.                                         <div class="inputContainer">
  76.                                                 <input id="exportFileName" value="export.xlsx" class="input">
  77.                                                 <input type="button" id="saveExcel" value="export" class="button">
  78.                                         </div>
  79.                                 </div>
  80.                                 <div class="option-row">
  81.                                         <div class="group">
  82.                                                 <label>Password:
  83.                                                         <input type="password" id="password">
  84.                                                 </label>
  85.                                         </div>
  86.                                 </div>
  87.                         </div>
  88.                 </div>
  89.                 <script type="text/javascript">
  90.                         window.onload = function() {
  91.                                 var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), {
  92.                                         sheetCount: 1
  93.                                 });
  94.                                 var excelIo = new GC.Spread.Excel.IO();
  95.                                 window.onload = function() {
  96.                                         var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
  97.                                         spread.fromJSON(jsonData);
  98.                                         var excelIo = new GC.Spread.Excel.IO();
  99.                                         var sheet = spread.getActiveSheet();
  100.                                         document.getElementById('loadExcel').onclick = function() {
  101.                                                 var excelFile = document.getElementById("fileDemo").files[0];
  102.                                                 var password = document.getElementById('password').value;
  103.                                                 // here is excel IO API
  104.                                                 excelIo.open(excelFile, function(json) {
  105.                                                         var workbookObj = json;
  106.                                                         spread.fromJSON(workbookObj);
  107.                                                 }, function(e) {
  108.                                                         // process error
  109.                                                         alert(e.errorMessage);
  110.                                                         if (e.errorCode === 2 /*noPassword*/ || e.errorCode === 3 /*invalidPassword*/ ) {
  111.                                                                 document.getElementById('password').onselect = null;
  112.                                                         }
  113.                                                 }, {
  114.                                                         password: password
  115.                                                 });
  116.                                         };
  117.                                         document.getElementById('saveExcel').onclick = function() {

  118.                                                 var fileName = document.getElementById('exportFileName').value;
  119.                                                 var password = document.getElementById('password').value;
  120.                                                 if (fileName.substr(-5, 5) !== '.xlsx') {
  121.                                                         fileName += '.xlsx';
  122.                                                 }

  123.                                                 var json = spread.toJSON();

  124.                                                 // here is excel IO API
  125.                                                 excelIo.save(json, function(blob) {
  126.                                                         saveAs(blob, fileName);
  127.                                                 }, function(e) {
  128.                                                         // process error
  129.                                                         console.log(e);
  130.                                                 }, {
  131.                                                         password: password
  132.                                                 });

  133.                                         };
  134.                                 };

  135.                         };
  136.                 </script>
  137.         </body>
  138. </html>
复制代码


我的运行效果,
image.png529864806.png
我用的Spreadjs  想实现导入excel解析功能,按照官网的教程,没有显示出来。js,css已经正确引入,导入一个excel文件,点击导入没有反应

1 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2018-11-30 17:47:09
沙发
我给您上传一个Demo,您把引用包的路径改一下就可以用了,里面的代码您可以参考一下。

IO_Template_01.html

8.91 KB, 下载次数: 68

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部