Browse Source

feat(tojson): api/docs

1.Update FAQ:celldata to data 2.Support config:showtoolbarConfig 3.Add API:toJson 4.Add h5-Dooring
link to readme.md
master
mengshukeji 5 years ago
parent
commit
8e410f5d3c
  1. 1
      README-zh.md
  2. 1
      README.md
  3. 24
      docs/guide/FAQ.md
  4. 2
      docs/guide/api.md
  5. 55
      docs/guide/config.md
  6. 21
      docs/zh/guide/FAQ.md
  7. 4
      docs/zh/guide/api.md
  8. 51
      docs/zh/guide/config.md
  9. 13
      src/config.js
  10. 430
      src/controllers/resize.js
  11. 10
      src/core.js
  12. 24
      src/global/api.js

1
README-zh.md

@ -161,6 +161,7 @@ npm run build
- [鲁班h5](https://github.com/ly525/luban-h5)
- [excelize](https://github.com/360EntSecGroup-Skylar/excelize)
- [h5-Dooring](https://github.com/MrXujiang/h5-Dooring)
## 加入共建

1
README.md

@ -162,6 +162,7 @@ Create a table
- [luban-h5](https://github.com/ly525/luban-h5)
- [excelize](https://github.com/360EntSecGroup-Skylar/excelize)
- [h5-Dooring](https://github.com/MrXujiang/h5-Dooring)
## Co-construction

24
docs/guide/FAQ.md

@ -4,16 +4,16 @@
**<span style="font-size:20px;">A</span>**: Use one-dimensional array format [celldata](/zh/guide/sheet.html#celldata), after the initialization is completed, the data converted into a two-dimensional array format is used for storage and update, and celldata is no longer used.
If you need to take out data as initial data, you need to execute `luckysheet.getGridData(data)` to convert it to celldata data.
Among them, the celldata in `{ r, c, v }` format is converted to a two-dimensional array using `luckysheet.buildGridData(luckysheetfile)`, and the input parameter is the table data object `luckysheetfile`
If you need to take out `data` as initial data, you need to execute [transToCellData(data)](/guide/api.html#transtocelldata-data-setting) to convert it to celldata data.
Among them, the celldata in `{ r, c, v }` format is converted to a two-dimensional array using [transToData(celldata)](/guide/api.html#transtodata-celldata-setting)
Summarized as follows:
```js
// data => celldata two-dimensional array data is converted into {r, c, v} format one-dimensional array, the input parameter is two-dimensional data
luckysheet.getGridData(data)
// data => celldata two-dimensional array data into {r, c, v} format one-dimensional array
luckysheet.transToCellData(data)
// celldata => data The two-dimensional array required to generate the table, the input parameter is the table data object file
luckysheet.buildGridData(luckysheetfile)
// celldata => data to generate the two-dimensional array required for the table
luckysheet.transToData(celldata)
```
------------
@ -63,14 +63,17 @@ Note: Initial data needs to be configured with loadUrl and loadSheetUrl paramete
## **<span style="font-size:20px;">Q</span>** How to import and export excel?
**<span style="font-size:20px;">A</span>**: The excel import and export library developed with Luckysheet-[Luckyexcel](https://github.com/mengshukeji/Luckyexcel) has realized the excel import function, and the export function is under development. You can refer to this blog post for excel export at this stage: https://www.cnblogs.com/recode-hyh/p/13168226.html.
**<span style="font-size:20px;">A</span>**: The excel import and export library developed with Luckysheet-[Luckyexcel](https://github.com/mengshukeji/Luckyexcel) has realized the excel import function, and the export function is under development.You can refer to these 2 blog posts for excel export at this stage:
- [Development of Excel download function based on LuckySheet online form](https://www.cnblogs.com/recode-hyh/p/13168226.html)
- [Use exceljs to export luckysheet form](https://blog.csdn.net/csdn_lsy/article/details/107179708)
------------
## **<span style="font-size:20px;">Q</span>** How to merge cells during initialization?
**<span style="font-size:20px;">A</span>**: Refer to the following case
- Luckysheet initializes data with merged cells: https://www.cnblogs.com/DuShuSir/p/13272397.html
**<span style="font-size:20px;">A</span>**: Refer to the following case:
- [How Luckysheet initializes the data with merged cells](https://www.cnblogs.com/DuShuSir/p/13272397.html)
------------
@ -80,7 +83,8 @@ Note: Initial data needs to be configured with loadUrl and loadSheetUrl paramete
- 1. after the table operation is completed, you can use `luckysheet.getAllSheets()` to get all sheet data that stroed in the back-end.
- 2. enable the collaborative editing function to transmit data to the back-end in real-time.
refer this article:https://www.cnblogs.com/DuShuSir/p/13857874.html
refer this article:
[How Luckysheet saves the data in the table to the database](https://www.cnblogs.com/DuShuSir/p/13857874.html)
------------

2
docs/guide/api.md

@ -1928,7 +1928,7 @@ Use note:
- **Parameter**
- {PlainObject} [setting]: optional parameters
+ {Object} [sheetObject]: The data of the newly added worksheet; the default value is an empty object
+ {Object} [sheetObject]: The data of the newly added worksheet; the default value is an empty object.Worksheet data format reference [options.data](/guide/sheet.html#initial)
+ {Number} [order]: New worksheet subscript; the default value is the last subscript
+ {Function} [success]: callback function for the end of the operation

55
docs/guide/config.md

@ -186,11 +186,9 @@ Note that you also need to configure `loadUrl` and `loadSheetUrl` to take effect
------------
### showtoolbarConfig
[todo]
- Type: Object
- Default: {}
- Usage: Custom configuration toolbar
- Usage: Custom configuration toolbar,can be used in conjunction with showtoolbar, `showtoolbarConfig` has a higher priority.
- Format:
```json
{
@ -214,19 +212,48 @@ Note that you also need to configure `loadUrl` and `loadSheetUrl` to take effect
verticalAlignMode: false, //'Vertical alignment'
textWrapMode: false, //'Wrap mode'
textRotateMode: false, //'Text Rotation Mode'
frozenMode: false, //'freeze mode'
sort: false, //'sort'
filter: false, //'filter'
findAndReplace: false, //'Find and Replace'
function: false, //'formula'
conditionalFormat: false, //'Conditional Format'
postil: false, //'comment'
pivotTable: false, //'PivotTable'
chart: false, //'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click)
screenshot: false, //'screenshot'
splitColumn: false, //'Split column'
image:false, // 'Insert picture'
chart: false, //'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click)
postil: false, //'comment'
pivotTable: false, //'PivotTable'
function: false, //'formula'
frozenMode: false, //'freeze mode'
sortAndFilter: false, //'Sort and filter'
conditionalFormat: false, //'Conditional Format'
dataVerification: false, // 'Data Verification'
splitColumn: false, //'Split column'
screenshot: false, //'screenshot'
findAndReplace: false, //'Find and Replace'
protection:false, // 'Worksheet protection'
print:false, // 'print'
//link:false, // 'Insert link'(TODO)
}
```
- Example:
- Show only the `undo/redo` and `font` buttons:
```js
//options
{
showtoolbar: false,
showtoolbarConfig:{
undoRedo: true,
font: true,
}
}
```
- Hide only the `image` and `print` buttons:
```js
//options
{
showtoolbar: true, // 默认就是true,可以不设置
showtoolbarConfig:{
image: false,
print: false,
}
}
```
------------
### showinfobar

21
docs/zh/guide/FAQ.md

@ -6,16 +6,16 @@
**<span style="font-size:20px;">A</span>** : 表格初始化时使用一维数组格式的 [celldata](/zh/guide/sheet.html#celldata),初始化完成后转化为二维数组格式的data作为存储更新使用,celldata不再使用。
如果需要将data拿出来作为初始化数据,则需要执行 `luckysheet.getGridData(data)`转换为celldata数据。
其中`{ r, c, v }`格式的celldata转换为二维数组使用的是`luckysheet.buildGridData(luckysheetfile)`,传入参数为表格数据对象`luckysheetfile`
如果需要将`data`拿出来作为初始化数据,则需要执行 [transToCellData(data)](/zh/guide/api.html#transtocelldata-data-setting)转换为celldata数据。
其中`{ r, c, v }`格式的celldata转换为二维数组使用的是[transToData(celldata)](/zh/guide/api.html#transtodata-celldata-setting)
总结如下:
```js
// data => celldata 二维数组数据 转化成 {r, c, v}格式 一维数组,传入参数为二维数据data
luckysheet.getGridData(data)
// data => celldata 二维数组数据 转化成 {r, c, v}格式 一维数组
luckysheet.transToCellData(data)
// celldata => data 生成表格所需二维数组,传入参数为表格数据对象file
luckysheet.buildGridData(luckysheetfile)
// celldata => data 生成表格所需二维数组
luckysheet.transToData(celldata)
```
------------
@ -65,14 +65,17 @@ luckysheet.buildGridData(luckysheetfile)
## **<span style="font-size:20px;">Q</span>** excel导入导出怎么做?
**<span style="font-size:20px;">A</span>** :配合Luckysheet开发的excel导入导出库-[Luckyexcel](https://github.com/mengshukeji/Luckyexcel)已经实现了excel导入功能,导出功能正在开发当中。现阶段excel导出可以参考这篇博文: https://www.cnblogs.com/recode-hyh/p/13168226.html。
**<span style="font-size:20px;">A</span>** :配合Luckysheet开发的excel导入导出库-[Luckyexcel](https://github.com/mengshukeji/Luckyexcel)已经实现了excel导入功能,导出功能正在开发当中。现阶段excel导出可以参考这2篇博文:
- [基于LuckySheet在线表格的Excel下载功能开发](https://www.cnblogs.com/recode-hyh/p/13168226.html)
- [使用exceljs导出luckysheet表格](https://blog.csdn.net/csdn_lsy/article/details/107179708)
------------
## **<span style="font-size:20px;">Q</span>** 初始化时合并单元格怎么做?
**<span style="font-size:20px;">A</span>** :参考以下案例
- Luckysheet初始化含合并单元格的数据: https://www.cnblogs.com/DuShuSir/p/13272397.html
- [Luckysheet如何初始化含合并单元格的数据](https://www.cnblogs.com/DuShuSir/p/13272397.html)
------------
@ -82,7 +85,7 @@ luckysheet.buildGridData(luckysheetfile)
- 一是表格操作完成后,使用`luckysheet.getAllSheets()`方法获取到全部的工作表数据,全部发送到后台存储。
- 二是开启协同编辑功能,实时传输数据给后端。
具体的操作步骤参考这篇文章:https://www.cnblogs.com/DuShuSir/p/13857874.html
具体的操作步骤参考这篇文章:[Luckysheet如何把表格里的数据保存到数据库](https://www.cnblogs.com/DuShuSir/p/13857874.html)
------------

4
docs/zh/guide/api.md

@ -1880,13 +1880,13 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
- **参数**
- {PlainObject} [setting]: 可选参数
+ {Object} [sheetObject]: 新增的工作表的数据;默认值为空对象
+ {Object} [sheetObject]: 新增的工作表的数据;默认值为空对象,工作表数据格式参考[options.data](/zh/guide/sheet.html#初始化配置)
+ {Number} [order]: 新增的工作表下标;默认值为最后一个下标位置
+ {Function} [success]: 操作结束的回调函数
- **说明**
新增一个sheet,返回新增的工作表对象,`setting`中可选设置数据为 `sheetObject`,不传`sheetObject`则会新增一个空白的工作表
新增一个sheet,返回新增的工作表对象,`setting`中可选设置数据为 `sheetObject`,不传`sheetObject`则会新增一个空白的工作表
- **示例**:

51
docs/zh/guide/config.md

@ -274,15 +274,13 @@ Luckysheet开放了更细致的自定义配置选项,分别有
------------
### showtoolbarConfig
[todo]
- 类型:Object
- 默认值:{}
- 作用:自定义配置工具栏
- 作用:自定义配置工具栏,可以与showtoolbar配合使用,`showtoolbarConfig`拥有更高的优先级。
- 格式:
```json
{
undoRedo: false, //撤销重做
undoRedo: false, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏
paintFormat: false, //格式刷
currencyFormat: false, //货币格式
percentageFormat: false, //百分比格式
@ -302,19 +300,48 @@ Luckysheet开放了更细致的自定义配置选项,分别有
verticalAlignMode: false, // '垂直对齐方式'
textWrapMode: false, // '换行方式'
textRotateMode: false, // '文本旋转方式'
frozenMode: false, // '冻结方式'
sort: false, // '排序'
filter: false, // '筛选'
findAndReplace: false, // '查找替换'
function: false, // '公式'
conditionalFormat: false, // '条件格式'
image:false, // '插入图片'
chart: false, // '图表'(图标隐藏,但是如果配置了chart插件,右击仍然可以新建图表)
postil: false, //'批注'
pivotTable: false, //'数据透视表'
chart: false, // '图表'(图标隐藏,但是如果配置了chart插件,右击仍然可以新建图表)
function: false, // '公式'
frozenMode: false, // '冻结方式'
sortAndFilter: false, // '排序和筛选'
conditionalFormat: false, // '条件格式'
dataVerification: false, // '数据验证'
splitColumn: false, // '分列'
screenshot: false, // '截图'
splitColumn: false, // '分列'
findAndReplace: false, // '查找替换'
protection:false, // '工作表保护'
print:false, // '打印'
// link:false, // '插入链接'(TODO)
}
```
- 示例:
- 仅显示撤消重做和字体按钮:
```js
//options
{
showtoolbar: false,
showtoolbarConfig:{
undoRedo: true,
font: true,
}
}
```
- 仅隐藏图片和打印按钮:
```js
//options
{
showtoolbar: true, // 默认就是true,可以不设置
showtoolbarConfig:{
image: false,
print: false,
}
}
```
------------
### showinfobar

13
src/config.js

@ -57,4 +57,17 @@ export default {
defaultColWidth:73,
defaultRowHeight:19,
defaultFontSize:10,
showRowBar:true, //是否显示行号区域
showColumnBar:true, //是否显示列号区域
sheetFormulaBar:true, //是否显示公式栏
showtoolbarConfig:{}, //自定义工具栏
showsheetbarConfig:{}, //自定义底部sheet页
showstatisticBarConfig:{}, //自定义计数栏
sheetBottomConfig:{}, //自定义添加行和回到顶部
cellRightClickConfig:{}, //自定义单元格右键菜单
sheetRightClickConfig:{}, //自定义底部sheet页右击菜单
}

430
src/controllers/resize.js

@ -20,16 +20,29 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
Store.infobarHeight = document.querySelector('#luckysheet_info_detail').offsetHeight;
}
if (!luckysheetConfigsetting.showtoolbar) {
$("#" + Store.container).find(".luckysheet-wa-editor, .luckysheet-share-logo").hide();
//
// if (!luckysheetConfigsetting.showtoolbar) {
// $("#" + Store.container).find(".luckysheet-wa-editor, .luckysheet-share-logo").hide();
// Store.toolbarHeight = 0;
// }
// else {
// $("#" + Store.container).find(".luckysheet-wa-editor, .luckysheet-share-logo").show();
// // Store.toolbarHeight = 72;
// Store.toolbarHeight = document.querySelector('#' + Store.container +' .luckysheet-wa-editor').offsetHeight;
// }
if (Store.toobarObject.toobarElements.length === 0) {
$("#" + Store.container).find(".luckysheet-wa-editor").hide();
Store.toolbarHeight = 0;
}
else {
$("#" + Store.container).find(".luckysheet-wa-editor, .luckysheet-share-logo").show();
$("#" + Store.container).find(".luckysheet-wa-editor").show();
// Store.toolbarHeight = 72;
Store.toolbarHeight = document.querySelector('#' + Store.container +' .luckysheet-wa-editor').offsetHeight;
}
// customToolbarConfig(luckysheetConfigsetting.showtoolbar,luckysheetConfigsetting.showtoolbarConfig);
if (!luckysheetConfigsetting.showsheetbar) {
$("#" + Store.container).find("#luckysheet-sheet-area").hide();
Store.sheetBarHeight = 0;
@ -289,85 +302,340 @@ export function changeSheetContainerSize(gridW, gridH){
}
/**
* 统计工具栏各个按钮宽度值,用于计算哪些需要放到 更多按钮里
*
* 注意每增加一个工具栏按钮都要在toobarWidths和toobarElements这两个数组里加上按钮的统计数据
*
* Toolbar judgment rules: First set the display and hide of all tool buttons according to showtoolbar, and then override the judgment of showtoolbar according to showtoolbarConfig rules
*
* The width value of each button in the statistics toolbar is used to calculate which needs to be placed in more buttons
*/
export function menuToolBarWidth() {
const toobarObject = Store.toobarObject;
toobarObject.toobarWidths= [
$('#luckysheet-icon-undo').offset().left,
$('#luckysheet-icon-redo').offset().left,
$('#luckysheet-icon-paintformat').offset().left,
$('#luckysheet-icon-currency').offset().left,
$('#luckysheet-icon-percent').offset().left,
$('#luckysheet-icon-fmt-decimal-decrease').offset().left,
$('#luckysheet-icon-fmt-decimal-increase').offset().left,
$('#luckysheet-icon-fmt-other').offset().left,
$('#luckysheet-icon-font-family').offset().left,
$('#luckysheet-icon-font-size').offset().left,
$('#luckysheet-icon-bold').offset().left,
$('#luckysheet-icon-italic').offset().left,
$('#luckysheet-icon-strikethrough').offset().left,
$('#luckysheet-icon-text-color').offset().left,
$('#luckysheet-icon-cell-color').offset().left,
$('#luckysheet-icon-border-all').offset().left,
$('#luckysheet-icon-merge-button').offset().left,
$('#luckysheet-icon-align').offset().left,
$('#luckysheet-icon-valign').offset().left,
$('#luckysheet-icon-textwrap').offset().left,
$('#luckysheet-icon-rotation').offset().left,
$('#luckysheet-insertImg-btn-title').offset().left,
$('#luckysheet-chart-btn-title').offset().left,
$('#luckysheet-icon-postil').offset().left,
$('#luckysheet-pivot-btn-title').offset().left,
$('#luckysheet-icon-function').offset().left,
$('#luckysheet-freezen-btn-horizontal').offset().left,
$('#luckysheet-icon-autofilter').offset().left,
$('#luckysheet-icon-conditionformat').offset().left,
$('#luckysheet-dataVerification-btn-title').offset().left,
$('#luckysheet-splitColumn-btn-title').offset().left,
$('#luckysheet-chart-btn-screenshot').offset().left,
$('#luckysheet-icon-seachmore').offset().left,
$('#luckysheet-icon-protection').offset().left,
$('#luckysheet-icon-print').offset().left,
$('#luckysheet-icon-print').offset().left + $('#luckysheet-icon-protection').outerWidth() + 5,
];
toobarObject.toobarElements = [
'#luckysheet-icon-undo',
'#luckysheet-icon-redo',
['#luckysheet-icon-paintformat','#toolbar-separator-paint-format'],
'#luckysheet-icon-currency',
'#luckysheet-icon-percent',
'#luckysheet-icon-fmt-decimal-decrease',
'#luckysheet-icon-fmt-decimal-increase',
['#luckysheet-icon-fmt-other','#toolbar-separator-more-format'],
['#luckysheet-icon-font-family','#toolbar-separator-font-family'],
['#luckysheet-icon-font-size','#toolbar-separator-font-size'],
'#luckysheet-icon-bold',
'#luckysheet-icon-italic',
'#luckysheet-icon-strikethrough',
['#luckysheet-icon-text-color','#luckysheet-icon-text-color-menu','#toolbar-separator-text-color'],
['#luckysheet-icon-cell-color','#luckysheet-icon-cell-color-menu'],
['#luckysheet-icon-border-all','#luckysheet-icon-border-menu'],
['#luckysheet-icon-merge-button','#luckysheet-icon-merge-menu','#toolbar-separator-merge-cell'],
['#luckysheet-icon-align','#luckysheet-icon-align-menu'],
['#luckysheet-icon-valign','#luckysheet-icon-valign-menu'],
['#luckysheet-icon-textwrap','#luckysheet-icon-textwrap-menu'],
['#luckysheet-icon-rotation','#luckysheet-icon-rotation-menu','#toolbar-separator-text-rotate'],
'#luckysheet-insertImg-btn-title',
'#luckysheet-chart-btn-title',
'#luckysheet-icon-postil',
['#luckysheet-pivot-btn-title','#toolbar-separator-pivot-table'],
['#luckysheet-icon-function','#luckysheet-icon-function-menu'],
['#luckysheet-freezen-btn-horizontal','#luckysheet-icon-freezen-menu'],
'#luckysheet-icon-autofilter',
'#luckysheet-icon-conditionformat',
'#luckysheet-dataVerification-btn-title',
'#luckysheet-splitColumn-btn-title',
'#luckysheet-chart-btn-screenshot',
'#luckysheet-icon-seachmore',
'#luckysheet-icon-protection',
'#luckysheet-icon-print',
]
const showtoolbar = luckysheetConfigsetting.showtoolbar;
const showtoolbarConfig = luckysheetConfigsetting.showtoolbarConfig;
const toobarWidths = Store.toobarObject.toobarWidths = [];
const toobarElements = Store.toobarObject.toobarElements = [];
const toobarConfig = Store.toobarObject.toobarConfig = {
undo: {
ele:'#luckysheet-icon-undo',
index:0,
}, //Undo redo
redo: {
ele:'#luckysheet-icon-redo',
index:1,
},
paintFormat: {
ele:['#luckysheet-icon-paintformat','#toolbar-separator-paint-format'],
index:2,
}, //Format brush
currencyFormat: {
ele:'#luckysheet-icon-currency',
index:3,
}, //currency format
percentageFormat: {
ele:'#luckysheet-icon-percent',
index:4,
}, //Percentage format
numberDecrease: {
ele:'#luckysheet-icon-fmt-decimal-decrease',
index:5,
}, //'Decrease the number of decimal places'
numberIncrease: {
ele:'#luckysheet-icon-fmt-decimal-increase',
index:6,
}, //'Increase the number of decimal places
moreFormats: {
ele:['#luckysheet-icon-fmt-other','#toolbar-separator-more-format'],
index:7,
}, //'More Formats'
font: {
ele:['#luckysheet-icon-font-family','#toolbar-separator-font-family'],
index:8,
}, //'font'
fontSize: {
ele:['#luckysheet-icon-font-size','#toolbar-separator-font-size'],
index:9,
}, //'Font size'
bold: {
ele:'#luckysheet-icon-bold',
index:10,
}, //'Bold (Ctrl+B)'
italic: {
ele:'#luckysheet-icon-italic',
index:11,
}, //'Italic (Ctrl+I)'
strikethrough: {
ele:'#luckysheet-icon-strikethrough',
index:12,
}, //'Strikethrough (Alt+Shift+5)'
textColor: {
ele:['#luckysheet-icon-text-color','#luckysheet-icon-text-color-menu','#toolbar-separator-text-color'],
index:13,
}, //'Text color'
fillColor: {
ele:['#luckysheet-icon-cell-color','#luckysheet-icon-cell-color-menu'],
index:14,
}, //'Cell color'
border: {
ele:['#luckysheet-icon-border-all','#luckysheet-icon-border-menu'],
index:15,
}, //'border'
mergeCell: {
ele:['#luckysheet-icon-merge-button','#luckysheet-icon-merge-menu','#toolbar-separator-merge-cell'],
index:16,
}, //'Merge cells'
horizontalAlignMode: {
ele:['#luckysheet-icon-align','#luckysheet-icon-align-menu'],
index:17,
}, //'Horizontal alignment'
verticalAlignMode: {
ele:['#luckysheet-icon-valign','#luckysheet-icon-valign-menu'],
index:18,
}, //'Vertical alignment'
textWrapMode: {
ele:['#luckysheet-icon-textwrap','#luckysheet-icon-textwrap-menu'],
index:19,
}, //'Wrap mode'
textRotateMode: {
ele:['#luckysheet-icon-rotation','#luckysheet-icon-rotation-menu','#toolbar-separator-text-rotate'],
index:20,
}, //'Text Rotation Mode'
image:{
ele:'#luckysheet-insertImg-btn-title',
index:21,
}, // 'Insert picture'
chart: {
ele:'#luckysheet-chart-btn-title',
index:22,
}, //'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click)
postil: {
ele:'#luckysheet-icon-postil',
index:23,
}, //'comment'
pivotTable: {
ele:['#luckysheet-pivot-btn-title','#toolbar-separator-pivot-table'],
index:24,
}, //'PivotTable'
function: {
ele:['#luckysheet-icon-function','#luckysheet-icon-function-menu'],
index:25,
}, //'formula'
frozenMode: {
ele:['#luckysheet-freezen-btn-horizontal','#luckysheet-icon-freezen-menu'],
index:26,
}, //'freeze mode'
sortAndFilter: {
ele:'#luckysheet-icon-autofilter',
index:27,
}, //'sort and filter'
conditionalFormat: {
ele:'#luckysheet-icon-conditionformat',
index:28,
}, //'Conditional Format'
dataVerification: {
ele:'#luckysheet-dataVerification-btn-title',
index:29,
}, // 'Data Verification'
splitColumn: {
ele:'#luckysheet-splitColumn-btn-title',
index:30,
}, //'Split column'
screenshot: {
ele:'#luckysheet-chart-btn-screenshot',
index:31,
}, //'screenshot'
findAndReplace: {
ele:'#luckysheet-icon-seachmore',
index:32,
}, //'Find and Replace'
protection:{
ele:'#luckysheet-icon-protection',
index:33,
}, // 'Worksheet protection'
print:{
ele:'#luckysheet-icon-print',
index:34,
}, // 'print'
// link:false, // 'Insert link'
};
// toobarObject.toobarWidths= [
// $('#luckysheet-icon-undo').offset().left,
// $('#luckysheet-icon-redo').offset().left,
// $('#luckysheet-icon-paintformat').offset().left,
// $('#luckysheet-icon-currency').offset().left,
// $('#luckysheet-icon-percent').offset().left,
// $('#luckysheet-icon-fmt-decimal-decrease').offset().left,
// $('#luckysheet-icon-fmt-decimal-increase').offset().left,
// $('#luckysheet-icon-fmt-other').offset().left,
// $('#luckysheet-icon-font-family').offset().left,
// $('#luckysheet-icon-font-size').offset().left,
// $('#luckysheet-icon-bold').offset().left,
// $('#luckysheet-icon-italic').offset().left,
// $('#luckysheet-icon-strikethrough').offset().left,
// $('#luckysheet-icon-text-color').offset().left,
// $('#luckysheet-icon-cell-color').offset().left,
// $('#luckysheet-icon-border-all').offset().left,
// $('#luckysheet-icon-merge-button').offset().left,
// $('#luckysheet-icon-align').offset().left,
// $('#luckysheet-icon-valign').offset().left,
// $('#luckysheet-icon-textwrap').offset().left,
// $('#luckysheet-icon-rotation').offset().left,
// $('#luckysheet-insertImg-btn-title').offset().left,
// $('#luckysheet-chart-btn-title').offset().left,
// $('#luckysheet-icon-postil').offset().left,
// $('#luckysheet-pivot-btn-title').offset().left,
// $('#luckysheet-icon-function').offset().left,
// $('#luckysheet-freezen-btn-horizontal').offset().left,
// $('#luckysheet-icon-autofilter').offset().left,
// $('#luckysheet-icon-conditionformat').offset().left,
// $('#luckysheet-dataVerification-btn-title').offset().left,
// $('#luckysheet-splitColumn-btn-title').offset().left,
// $('#luckysheet-chart-btn-screenshot').offset().left,
// $('#luckysheet-icon-seachmore').offset().left,
// $('#luckysheet-icon-protection').offset().left,
// $('#luckysheet-icon-print').offset().left,
// $('#luckysheet-icon-print').offset().left + $('#luckysheet-icon-protection').outerWidth() + 5,
// ];
// toobarObject.toobarElements = [
// '#luckysheet-icon-undo',
// '#luckysheet-icon-redo',
// ['#luckysheet-icon-paintformat','#toolbar-separator-paint-format'],
// '#luckysheet-icon-currency',
// '#luckysheet-icon-percent',
// '#luckysheet-icon-fmt-decimal-decrease',
// '#luckysheet-icon-fmt-decimal-increase',
// ['#luckysheet-icon-fmt-other','#toolbar-separator-more-format'],
// ['#luckysheet-icon-font-family','#toolbar-separator-font-family'],
// ['#luckysheet-icon-font-size','#toolbar-separator-font-size'],
// '#luckysheet-icon-bold',
// '#luckysheet-icon-italic',
// '#luckysheet-icon-strikethrough',
// ['#luckysheet-icon-text-color','#luckysheet-icon-text-color-menu','#toolbar-separator-text-color'],
// ['#luckysheet-icon-cell-color','#luckysheet-icon-cell-color-menu'],
// ['#luckysheet-icon-border-all','#luckysheet-icon-border-menu'],
// ['#luckysheet-icon-merge-button','#luckysheet-icon-merge-menu','#toolbar-separator-merge-cell'],
// ['#luckysheet-icon-align','#luckysheet-icon-align-menu'],
// ['#luckysheet-icon-valign','#luckysheet-icon-valign-menu'],
// ['#luckysheet-icon-textwrap','#luckysheet-icon-textwrap-menu'],
// ['#luckysheet-icon-rotation','#luckysheet-icon-rotation-menu','#toolbar-separator-text-rotate'],
// '#luckysheet-insertImg-btn-title',
// '#luckysheet-chart-btn-title',
// '#luckysheet-icon-postil',
// ['#luckysheet-pivot-btn-title','#toolbar-separator-pivot-table'],
// ['#luckysheet-icon-function','#luckysheet-icon-function-menu'],
// ['#luckysheet-freezen-btn-horizontal','#luckysheet-icon-freezen-menu'],
// '#luckysheet-icon-autofilter',
// '#luckysheet-icon-conditionformat',
// '#luckysheet-dataVerification-btn-title',
// '#luckysheet-splitColumn-btn-title',
// '#luckysheet-chart-btn-screenshot',
// '#luckysheet-icon-seachmore',
// '#luckysheet-icon-protection',
// '#luckysheet-icon-print',
// ]
const config = {
undo: true, //Undo
redo: true, //Redo
paintFormat: true, //Format brush
currencyFormat: true, //currency format
percentageFormat: true, //Percentage format
numberDecrease: true, //'Decrease the number of decimal places'
numberIncrease: true, //'Increase the number of decimal places
moreFormats: true, //'More Formats'
font: true, //'font'
fontSize: true, //'Font size'
bold: true, //'Bold (Ctrl+B)'
italic: true, //'Italic (Ctrl+I)'
strikethrough: true, //'Strikethrough (Alt+Shift+5)'
textColor: true, //'Text color'
fillColor: true, //'Cell color'
border: true, //'border'
mergeCell: true, //'Merge cells'
horizontalAlignMode: true, //'Horizontal alignment'
verticalAlignMode: true, //'Vertical alignment'
textWrapMode: true, //'Wrap mode'
textRotateMode: true, //'Text Rotation Mode'
image:true, // 'Insert picture'
chart: true, //'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click)
postil:true, //'comment'
pivotTable: true, //'PivotTable'
function: true, //'formula'
frozenMode: true, //'freeze mode'
sortAndFilter: true, //'Sort and filter'
conditionalFormat: true, //'Conditional Format'
dataVerification: true, // 'Data Verification'
splitColumn: true, //'Split column'
screenshot: true, //'screenshot'
findAndReplace: true, //'Find and Replace'
protection: true, // 'Worksheet protection'
print: true, // 'print'
// link: true, // 'Insert link'(TODO)
}
// false means all false
if(!showtoolbar){
for(let s in config){
config[s] = false;
}
}
// showtoolbarConfig determines the final result
if(JSON.stringify(showtoolbarConfig) !== '{}'){
if(showtoolbarConfig.hasOwnProperty('undoRedo')){
config.undo = config.redo = showtoolbarConfig.undoRedo;
delete showtoolbarConfig.undoRedo;
}
Object.assign(config,showtoolbarConfig);
}
// 1. The button set to false, remove the dom
// 2. Build toobarWidths and toobarElements
for(let s in config){
if(config[s]){
toobarElements.push($.extend(true,{},toobarConfig[s]));
}else{
if(toobarConfig[s].ele instanceof Array){
for(const item of toobarConfig[s].ele){
$(item).remove();
}
}else{
$(toobarConfig[s].ele).remove();
}
}
}
toobarElements.sort(sortToolbar);
function sortToolbar(a,b) {
if(a.index > b.index){
return 1;
}else{
return -1;
}
}
toobarElements.forEach((curr,index,arr)=>{
arr[index] = curr.ele;
if(index !== toobarElements.length - 1){
if(curr.ele instanceof Array){
toobarWidths.push($(curr.ele[0]).offset().left);
}else{
toobarWidths.push($(curr.ele).offset().left);
}
}else{
if(curr.ele instanceof Array){
toobarWidths.push($(curr.ele[0]).offset().left);
toobarWidths.push($(curr.ele[0]).offset().left + $(curr.ele[0]).outerWidth() + 5);
}else{
toobarWidths.push($(curr.ele).offset().left);
toobarWidths.push($(curr.ele).offset().left + $(curr.ele).outerWidth() + 5);
}
}
});
}

10
src/core.js

@ -47,6 +47,15 @@ luckysheet = common_extend(api,luckysheet);
//创建luckysheet表格
luckysheet.create = function (setting) {
// Store original parameters for api: toJson
Store.toJsonOptions = {}
for(let c in setting){
if(c !== 'data'){
Store.toJsonOptions[c] = setting[c];
}
}
let extendsetting = common_extend(defaultSetting, setting);
let loadurl = extendsetting.loadUrl,
@ -77,6 +86,7 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.allowCopy = extendsetting.allowCopy;
luckysheetConfigsetting.showtoolbar = extendsetting.showtoolbar;
luckysheetConfigsetting.showtoolbarConfig = extendsetting.showtoolbarConfig;
luckysheetConfigsetting.showinfobar = extendsetting.showinfobar;
luckysheetConfigsetting.showsheetbar = extendsetting.showsheetbar;
luckysheetConfigsetting.showstatisticBar = extendsetting.showstatisticBar;

24
src/global/api.js

@ -5844,3 +5844,27 @@ export function transToData(celldata, options = {}){
celldata: celldata
})
}
/**
* 导出的json字符串可以直接当作`luckysheet.create(options)`初始化工作簿时的参数`options`使用
*
*/
export function toJson(){
const toJsonOptions = Store.toJsonOptions;
// Workbook name
toJsonOptions.title = $("#luckysheet_info_detail_input").val();
toJsonOptions.data = getAllSheets();
// row and column
getluckysheetfile().forEach((file,index)=>{
toJsonOptions.data[index].row = file.data.length;
toJsonOptions.data[index].column = file.data[0].length;
})
return toJsonOptions;
}

Loading…
Cancel
Save