本帖最后由 mabh 于 2018-12-3 15:40 编辑
问题描述: 1. 我定义了函数 =MABH(232,34,34,454) 参数值是逗号分割字符
2. 单元格输入完成会把当前单元格转换成 下拉列表。现在已经完成了。
3.处于下拉列表的单元格 ,双击自动转换成 公式单元格的编辑状态。现在转换成功了,但是转换完成后,需要点击别的框,才会变成文本输入框,而且内容值也没有了。
- <!DOCTYPE >
- <html>
- <head>
- <meta name="spreadjs culture" content="zh-cn" />
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <link rel="styleSheet" href="gc.spread.sheets.excel2013white.12.0.0.css" />
- <script src="TutorialSample/js/jquery-1.8.2.min.js"></script>
- <script src="gc.spread.sheets.all.12.0.0.min.js" type="text/javascript"></script>
- <script src="TutorialSample/js/FileSaver.js"></script>
- <script src="TutorialSample/js/spread/plugins/gc.spread.excelio.12.0.0.min.js"></script>
- <script src="gc.spread.sheets.resources.zh.12.0.0.min.js" type="text/javascript"></script>
- <style type="text/css">
- .sample-tutorial {
- position: relative;
- height: 100%;
- overflow: hidden;
- }
- .sample-spreadsheets {
- width: calc(100% - 280px);
- height: 100%;
- overflow: hidden;
- float: left;
- }
- .options-container {
- float: right;
- width: 280px;
- padding: 12px;
- height: 100%;
- box-sizing: border-box;
- background: #fbfbfb;
- overflow: auto;
- }
- .sample-options {
- z-index: 1000;
- }
- .inputContainer {
- width: 100%;
- height: auto;
- border: 1px solid #eee;
- padding: 6px 12px;
- margin-bottom: 10px;
- box-sizing: border-box;
- }
- .input {
- font-size: 14px;
- height: 20px;
- border: 0;
- outline: none;
- background: transparent;
- }
- .button {
- height: 30px;
- padding: 6px 12px;
- width: 80px;
- margin-top: 6px;
- }
- .group {
- padding: 12px;
- }
- .group input {
- padding: 4px 12px;
- }
- </style>
- </head>
- <body style='font-size:14px;'>
- <div class="sample-tutorial">
- <div id="ss" style="width:100%; height:360px;border: 1px solid gray;"></div>
- <div class="options-container">
- <div class="option-row">
- <div class="inputContainer">
- <input type="file" id="fileDemo" class="input">
- <input type="button" id="loadExcel" value="import" class="button">
- </div>
- <div class="inputContainer">
- <input id="exportFileName" value="export.xlsx" class="input">
- <input type="button" id="saveExcel" value="export" class="button">
- </div>
- </div>
- <div class="option-row">
- <div class="group">
- <label>Password:
- <input type="password" id="password">
- </label>
- </div>
- </div>
- </div>
- </div>
- <script type="text/javascript">
- var spread;
- var excelIo;
- var sheet;
- window.onload = function() {
- //, { sheetCount: 1 } 导入execel去掉这个参数
- spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {
- sheetCount: 1
- });
- excelIo = new GC.Spread.Excel.IO();
- //导入要用活动的 sheet
- // sheet = spread.getActiveSheet();
- sheet = spread.getSheet(0);
- myFN();
- };
- var curRow, curCol;
- function myFN() {
- //自定义函数
- function FactorialFunction() {
- this.name = "MABH";
- this.maxArgs = 5;
- this.minArgs = 1;
- }
- FactorialFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
- FactorialFunction.prototype.evaluate = function(arg) {
- if (arguments.length >= 1) {
- var items = [];
- for (var i = 0; i < arguments.length; i++) {
- items.push({
- text: arguments[i],
- value: arguments[i]
- });
- }
- return setComboBox(items, this.name);
- }
- return "#VALUE";
- };
- var factorial = new FactorialFunction();
- sheet.addCustomFunction(factorial);
- sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, function(sender, args) {
- curRow = args.row;
- curCol = args.col;
- if (sender.type == 'CellDoubleClick') {
- var cellType = sheet.getCellType(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport);
- if (cellType instanceof GC.Spread.Sheets.CellTypes.ComboBox) {
- var texts = [];
- for (var i = 0; i < cellType._items.length; i++) {
- texts.push(cellType._items[i].text);
- }
- var type = new GC.Spread.Sheets.CellTypes.Text();
- sheet.setCellType(args.row, args.col, type ,GC.Spread.Sheets.SheetArea.viewport);
-
- var value = '=' + cellType.factorialName + '(' + texts.join(',') + ')';
- sheet.setValue(args.row, args.col, "====", GC.Spread.Sheets.SheetArea.viewport);
- }
- }
- });
- }
- function setComboBox(items, factorialName) {
- var combo = new GC.Spread.Sheets.CellTypes.ComboBox();
- combo.factorialName = factorialName;
- sheet.setCellType(curRow, curCol, combo, GC.Spread.Sheets.SheetArea.viewport);
- combo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
- combo.items(items);
- editableCombo.editable(false);
- combo.itemHeight(24);
- return combo;
- }
- function importOrExport() {
- document.getElementById('loadExcel').onclick = function() {
- var excelFile = document.getElementById("fileDemo").files[0];
- var password = document.getElementById('password').value;
- // here is excel IO API
- excelIo.open(excelFile, function(json) {
- var workbookObj = json;
- spread.fromJSON(workbookObj);
- }, function(e) {
- // process error
- alert(e.errorMessage);
- if (e.errorCode === 2 /*noPassword*/ || e.errorCode === 3 /*invalidPassword*/ ) {
- document.getElementById('password').onselect = null;
- }
- }, {
- password: password
- });
- };
- document.getElementById('saveExcel').onclick = function() {
- var fileName = document.getElementById('exportFileName').value;
- var password = document.getElementById('password').value;
- 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>
复制代码
|
|