diff --git a/docs/guide/FAQ.md b/docs/guide/FAQ.md index 6712b0c..56c6ad0 100644 --- a/docs/guide/FAQ.md +++ b/docs/guide/FAQ.md @@ -42,8 +42,32 @@ luckysheet.buildGridData(luckysheetfile) ------------ -## **Q** How to understand the `index` and `order` of each worksheet? +## **Q** What is the difference between `index` and `order` for each sheet page? -**A**: Each worksheet has a unique id, which is `index`, which can be incremented by numbers or a random string. And `order` is the order of all worksheets, starting from 0. +**A**: Each sheet page has a unique id, which is `index`, which can be incremented by numbers or a random string. And `order` is the sorting situation of all sheets, starting from 0, can only be numbers `0,1,2...`. ------------ + +## **Q** Why can’t I run the project directly under the dist folder? + +**A**: Need to start the local server + +- [Node build a local server](https://github.com/JacksonTian/anywhere) +- [Python build local server](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/set_up_a_local_testing_server) + +------------ + +## **Q** How to import and export excel? + +**A**: You can refer to the following cases at this stage +- Luckysheet import: https://www.cnblogs.com/DuShuSir/p/13179483.html +- Luckysheet export: https://www.cnblogs.com/recode-hyh/p/13168226.html + +Later, we will open another import and export library for adaptation, so stay tuned! + +------------ + +## **Q** How to merge cells during initialization? + +**A**: Refer to the following case +- Luckysheet initializes data with merged cells: https://www.cnblogs.com/DuShuSir/p/13272397.html \ No newline at end of file diff --git a/docs/zh/guide/FAQ.md b/docs/zh/guide/FAQ.md index 4591e9c..164fb98 100644 --- a/docs/zh/guide/FAQ.md +++ b/docs/zh/guide/FAQ.md @@ -42,8 +42,32 @@ luckysheet.buildGridData(luckysheetfile) ------------ -## **Q** 如何理解每个sheet页的`index`和`order`? +## **Q** 每个sheet页的`index`和`order`有什么区别? -**A** : 每个sheet页都有一个唯一id,就是`index`,可以用数字递增,也可以使用随机字符串,而`order`是所有的sheet的排序情况,从0开始,即为索引。 +**A** : 每个sheet页都有一个唯一id,就是`index`,可以用数字递增,也可以使用随机字符串,而`order`是所有的sheet的排序情况,从0开始,只能为数字`0,1,2...`。 ------------- \ No newline at end of file +------------ + +## **Q** dist文件夹下为什么不能直接运行项目? + +**A** :需要启动本地服务器 + +- [Node搭建本地服务器](https://github.com/JacksonTian/anywhere) +- [Python搭建本地服务器](https://developer.mozilla.org/zh-CN/docs/Learn/Common_questions/set_up_a_local_testing_server) + +------------ + +## **Q** excel导入导出怎么做? + +**A** :现阶段可以参考以下案例 +- Luckysheet导入: https://www.cnblogs.com/DuShuSir/p/13179483.html +- Luckysheet导出 : https://www.cnblogs.com/recode-hyh/p/13168226.html + +后期会另外开源一个导入导出库做适配,敬请期待! + +------------ + +## **Q** 初始化时合并单元格怎么做? + +**A** :参考以下案例 +- Luckysheet初始化含合并单元格的数据: https://www.cnblogs.com/DuShuSir/p/13272397.html diff --git a/docs/zh/guide/api.md b/docs/zh/guide/api.md index ac5aaef..f7e209e 100644 --- a/docs/zh/guide/api.md +++ b/docs/zh/guide/api.md @@ -2010,6 +2010,14 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开 ------------ +### toJson() + +- **说明**: + + 导出的json字符串可以直接当作`luckysheet.create(options)`初始化工作簿时的参数`options`使用,使用场景在用户自己操作表格后想要手动保存全部的参数,再去别处初始化这个表格使用,类似一个luckysheet专有格式的导入导出。 + +------------ + ## 旧版API ::: warning diff --git a/docs/zh/guide/config.md b/docs/zh/guide/config.md index a20a4ac..dc908d4 100644 --- a/docs/zh/guide/config.md +++ b/docs/zh/guide/config.md @@ -43,9 +43,12 @@ luckysheet.create(options) - [accuracy](#accuracy) - [allowCopy](#allowCopy) - [showtoolbar](#showtoolbar) +- [showtoolbarConfig](#showtoolbarConfig) - [showinfobar](#showinfobar) - [showsheetbar](#showsheetbar) +- [showsheetbarConfig](#showsheetbarConfig) - [showstatisticBar](#showstatisticBar) +- [showstatisticBarConfig](#showstatisticBarConfig) - [allowEdit](#allowEdit) - [enableAddRow](#enableAddRow) - [enableAddCol](#enableAddCol) @@ -60,6 +63,7 @@ luckysheet.create(options) - [beforeCreateDom](#beforeCreateDom) - [fireMousedown](#fireMousedown) - [forceCalculation](#forceCalculation) +- [rightClickConfig](#rightClickConfig) ### container - 类型:String @@ -162,6 +166,48 @@ luckysheet.create(options) - 默认值:true - 作用:是否第二列显示工具栏 +------------ +#### showtoolbarConfig +- 类型:Object +- 默认值:{} +- 作用:自定义配置工具栏 +- 格式: + ```json + { + undoRedo: false, //撤销重做 + paintFormat: false, //格式刷 + currencyFormat: false, //货币格式 + percentageFormat: false, //百分比格式 + numberDecrease: false, // '减少小数位数' + numberIncrease: false, // '增加小数位数 + moreFormats: false, // '更多格式' + font: false, // '字体' + fontSize: false, // '字号大小' + bold: false, // '粗体 (Ctrl+B)' + italic: false, // '斜体 (Ctrl+I)' + strikethrough: false, // '删除线 (Alt+Shift+5)' + textColor: false, // '文本颜色' + fillColor: false, // '单元格颜色' + border: false, // '边框' + mergeCell: false, // '合并单元格' + horizontalAlignMode: false, // '水平对齐方式' + verticalAlignMode: false, // '垂直对齐方式' + textWrapMode: false, // '换行方式' + textRotateMode: false, // '文本旋转方式' + frozenMode: false, // '冻结方式' + sort: false, // '排序' + filter: false, // '筛选' + findAndReplace: false, // '查找替换' + function: false, // '公式' + conditionalFormat: false, // '条件格式' + postil: false, //'批注' + pivotTable: false, //'数据透视表' + chart: false, // '图表'(图标隐藏,但是如果配置了chart插件,右击仍然可以新建图表) + screenshot: false, // '截图' + splitColumn: false, // '分列' + } + ``` + ------------ ### showinfobar - 类型:Boolean @@ -174,12 +220,38 @@ luckysheet.create(options) - 默认值:true - 作用:是否显示底部表格名称区域 +------------ +### showsheetbarConfig +- 类型:Object +- 默认值:{} +- 作用:自定义配置底部表格名称区域 +- 格式: + ```json + { + add: false, //新增sheet + menu: false, //sheet管理菜单 + sheet: false //sheet页显示 + } + ``` + ------------ ### showstatisticBar - 类型:Boolean - 默认值:true - 作用:是否显示底部计数栏 +------------ +### showstatisticBarConfig +- 类型:Object +- 默认值:{} +- 作用:自定义配置底部计数栏 +- 格式: + ```json + { + count: false, // 计数栏 + zoom: false // 缩放 + } + ------------ ### allowEdit - 类型:Boolean @@ -270,4 +342,76 @@ luckysheet.create(options) ⚠️提醒,公式较多时会有性能问题,慎用! ------------- \ No newline at end of file +------------ +### rightClickConfig +- 类型:Object +- 默认值:{} +- 作用:自定义配置右击菜单 +- 格式: + ```json + { + copy:false, // '复制' + copyAs:false, // '复制为' + paste:false, // '粘贴', + insert:false, // '插入', + delete:false, // '删除', + hide:false, // '隐藏', + deleteCell:false, // '删除单元格', + clear:false, // '清除内容', + matrix:false, // '矩阵操作选区', + sort:false, // '排序选区', + filter:false, //'筛选选区', + chart:false, // '图表生成', + } + +## 钩子函数 + +钩子函数应用于二次开发时,会在各个常用鼠标或者键盘操作时植入钩子,调用开发者传入的函数,起到扩展Luckysheet功能的作用。 + +钩子函数统一配置在`options.hook`下,可以分别针对单元格、sheet页、表格创建配置hook + +### cellHover +- 类型:Function +- 默认值:null +- 作用:鼠标移过单元格时(hover)触发 +- 参数: + - {Number} [r]: 单元格所在行数 + - {Number} [c]: 单元格所在列数 + - {Object} [v]: 单元格对象 + +------------ + +### cellClickBefore +- 类型:Function +- 默认值:null +- 作用:点击单元格前触发,即在点击单元格的时候,最先触发这个方法 + +------------ + +### cellClickAfter +- 类型:Function +- 默认值:null +- 作用:点击单元格后触发,即在点击单元格的时候,最后触发这个方法 + +------------ + +### sheetClickBefore +- 类型:Function +- 默认值:null +- 作用:点击sheet页前触发 + +------------ + +### sheetClickAfter +- 类型:Function +- 默认值:null +- 作用:点击sheet页后触发 + +------------ + +### sheetClickAfter +- 类型:Function +- 默认值:null +- 作用:点击sheet页后触发 + +------------ diff --git a/docs/zh/guide/sheet.md b/docs/zh/guide/sheet.md index b831b31..41ce8f4 100644 --- a/docs/zh/guide/sheet.md +++ b/docs/zh/guide/sheet.md @@ -148,6 +148,8 @@ options.data示例如下: - 默认值:{} - 作用:表格行高、列宽、合并单元格、边框、隐藏行等设置 + 注意,config如果为空,必须为空对象`{}`,不能为字符串或者null + #### config.merge - 类型:Object - 默认值:{} diff --git a/src/controllers/handler.js b/src/controllers/handler.js index f3182ed..2f9291d 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -108,7 +108,7 @@ export default function luckysheetHandler() { const _locale = locale(); const locale_drag = _locale.drag; const locale_info = _locale.info; - let prev + let prev, mousewheelArrayUniqueTimeout; $("#luckysheet-grid-window-1").mousewheel(function (event, delta) { let scrollLeft = $("#luckysheet-scrollbar-x").scrollLeft(), scrollTop = $("#luckysheet-scrollbar-y").scrollTop(); @@ -123,8 +123,26 @@ export default function luckysheetHandler() { visibledatacolumn_c = luckysheetFreezen.freezenverticaldata[3]; } - visibledatacolumn_c = ArrayUnique(visibledatacolumn_c); - visibledatarow_c = ArrayUnique(visibledatarow_c); + clearTimeout(mousewheelArrayUniqueTimeout); + + if(Store.visibledatacolumn_unique!=null){ + visibledatacolumn_c = Store.visibledatacolumn_unique; + } + else{ + visibledatacolumn_c = ArrayUnique(visibledatacolumn_c); + Store.visibledatacolumn_unique = visibledatacolumn_c; + } + + if(Store.visibledatarow_unique!=null){ + visibledatarow_c = Store.visibledatarow_unique; + } + else{ + visibledatarow_c = ArrayUnique(visibledatarow_c); + Store.visibledatarow_unique = visibledatarow_c; + } + + // visibledatacolumn_c = ArrayUnique(visibledatacolumn_c); + // visibledatarow_c = ArrayUnique(visibledatarow_c); let col_st = luckysheet_searcharray(visibledatacolumn_c, scrollLeft); let row_st = luckysheet_searcharray(visibledatarow_c, scrollTop); @@ -179,6 +197,11 @@ export default function luckysheetHandler() { $("#luckysheet-scrollbar-x").scrollLeft(scrollLeft); } + + mousewheelArrayUniqueTimeout = setTimeout(() => { + Store.visibledatacolumn_unique = null; + Store.visibledatarow_unique = null; + }, 200); }); $("#luckysheet-scrollbar-x").scroll(function(){ diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index 1afc7d2..d618271 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -694,6 +694,7 @@ const sheetmanage = { } let execF = function(){ + _this.mergeCalculation(file["index"]); _this.storeSheetParam(); _this.restoreselect(); _this.CacheNotLoadControll = []; @@ -903,6 +904,48 @@ const sheetmanage = { Store.luckysheetfile[index]["data"] = Store.flowdata; Store.luckysheetfile[index]["config"] = $.extend(true, {}, Store.config); }, + mergeCalculationSheet:{}, + mergeCalculation:function(index){ + let file = Store.luckysheetfile[this.getSheetIndex(index)]; + let config = file.config, data = file.data, mergeConfig = config.merge; + if(mergeConfig==null || index in this.mergeCalculationSheet || file["autoCalculationMerge"]===false){ + return; + } + + this.mergeCalculationSheet[index] = 1; + + for(let x in mergeConfig){ + let r = parseInt(x.substr(0, x.indexOf('_'))); + let c = parseInt(x.substr(x.indexOf('_') + 1)); + let mcInfo = mergeConfig[x]; + if(data[r][c]==null){ + data[r][c] = {}; + } + + data[r][c]["mc"] = { + r:r, + c:c, + rs:mcInfo.rs, + cs:mcInfo.cs, + } + + for(let ir=r;ir 0) { for (let i = 0; i < dataArr.length; i++) { - if (arr.indexOf(dataArr[i]) == -1) { - arr.push(dataArr[i]); + let item = dataArr[i]; + if (!obj[item]) { + result.push(item); + obj[item] = 1; } } } - - return arr; + return result } //获取字体配置