Browse Source

2021.1.6

master
CN\wuwx26 5 years ago
parent
commit
201bbc330c
  1. 12
      README-zh.md
  2. 2
      deploy.bat
  3. 152
      docs/guide/FAQ.md
  4. 10
      docs/guide/api.md
  5. 30
      docs/guide/config.md
  6. 158
      docs/zh/guide/FAQ.md
  7. 12
      docs/zh/guide/api.md
  8. 43
      docs/zh/guide/config.md
  9. 45
      src/controllers/handler.js
  10. 6
      src/controllers/menuButton.js
  11. 34
      src/controllers/sheetmanage.js
  12. 4
      src/css/luckysheet-core.css
  13. 24
      src/expendPlugins/chart/plugin.js
  14. 68
      src/global/api.js
  15. 24
      src/global/formula.js
  16. 29
      src/global/getRowlen.js
  17. 15
      src/index.html

12
README-zh.md

@ -10,6 +10,18 @@
## 介绍
🚀Luckysheet ,一款纯前端类似excel的在线表格,功能强大、配置简单、完全开源。
## 招聘
字节跳动靠谱内推 - 前端工程师(上海 · 飞书)
30 – 60K · 15薪
1. 简历优先筛选
2. 面试过程及时跟进
3. 凭实力说话,薪资在行业有很强竞争力
4. 包三餐和下午茶
5. 有意向可以先咨询
6. 框架: React、Electron
<img src="https://minio.cnbabylon.com/public/luckysheet/feishu_jd.jpg" width = "250" alt="微信群" align="center" />
## 相关链接
| 源码 | 文档 | Demo | 插件Demo | 论坛 |
| ------ | -------- | ------ | ------ | ------ |

2
deploy.bat

@ -3,6 +3,8 @@ npm run build
cd dist
git init
git remote add origin https://github.com/mengshukeji/LuckysheetDemo.git
git config --local user.email "1414556676@qq.com"
git config --local user.name "Dushusir"
git add .
git commit -m 'deploy Luckysheet demo'
git push -f origin master:gh-pages

152
docs/guide/FAQ.md

@ -1,6 +1,8 @@
# FAQ
## **<span style="font-size:20px;">Q</span>** What is the difference between data and celldata in luckysheetfile?
The content of this chapter collects the common problems that everyone has feedback. If the official documents and this list can’t answer your questions, I recommend you to [Official Forum](https://github.com/mengshukeji/Luckysheet/discussions)
## What is the difference between data and celldata in luckysheetfile?
**<span style="font-size:20px;">A</span>**: Use one-dimensional array format [celldata](/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.
@ -18,41 +20,41 @@ luckysheet.transToData(celldata)
------------
## **<span style="font-size:20px;">Q</span>** What are the cell types?
## What are the cell types?
**<span style="font-size:20px;">A</span>**: Refer to [Cell Format List](/guide/cell.html), with examples of available cell formats
------------
## **<span style="font-size:20px;">Q</span>** How to use Luckysheet in Vue/React project?
## How to use Luckysheet in Vue/React project?
**<span style="font-size:20px;">A</span>**:
**<span style="font-size:20px;">A</span>**: Check
- Vue case: [luckysheet-vue](https://github.com/mengshukeji/luckysheet-vue)
- React case: [luckysheet-react](https://github.com/mengshukeji/luckysheet-react)
------------
## **<span style="font-size:20px;">Q</span>** Why will the formula in the table not be triggered after initialization?
## Why will the formula in the table not be triggered after initialization?
**<span style="font-size:20px;">A</span>** : Refer to [Table data format](/guide/sheet.html#calcchain) ,just set the calcChain corresponding to the cell data.
**<span style="font-size:20px;">A</span>**: Refer to [Table data format](/guide/sheet.html#calcchain) ,just set the calcChain corresponding to the cell data.
------------
## **<span style="font-size:20px;">Q</span>** Is the remote loading data loadUrl or updateUrl?
## Is the remote loading data loadUrl or updateUrl?
**<span style="font-size:20px;">A</span>**: [loadUrl](/guide/config.html#loadurl). Configure loadUrl, Luckysheet will request the entire table data through ajax, and updateUrl will be used as the interface address for collaborative editing in real-time saving.
Note: Initial data needs to be configured with loadUrl parameter, while for collaborative editing, the four parameters of loadUrl, updateUrl and allowUpdate can be configured to take effect.
------------
## **<span style="font-size:20px;">Q</span>** What is the difference between `index` and `order` for each sheet page?
## What is the difference between `index` and `order` for each sheet page?
**<span style="font-size:20px;">A</span>**: 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...`.
------------
## **<span style="font-size:20px;">Q</span>** Why can’t I run the project directly under the dist folder?
## Why can’t I run the project directly under the dist folder?
**<span style="font-size:20px;">A</span>**: Need to start the local server
@ -61,7 +63,7 @@ Note: Initial data needs to be configured with loadUrl parameter, while for coll
------------
## **<span style="font-size:20px;">Q</span>** How to import and export excel?
## 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 these 2 blog posts for excel export at this stage:
@ -70,77 +72,77 @@ Note: Initial data needs to be configured with loadUrl parameter, while for coll
------------
## **<span style="font-size:20px;">Q</span>** How to merge cells during initialization?
## How to merge cells during initialization?
**<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)
------------
## **<span style="font-size:20px;">Q</span>** How does 'Luckysheet' save the data from the table to the database? Is there a soulution for storage and collaboration?
## How does 'Luckysheet' save the data from the table to the database? Is there a soulution for storage and collaboration?
**<span style="font-size:20px;">A</span>** :There are two options:
**<span style="font-size:20px;">A</span>**: There are two options:
- 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
refer this article:
[How Luckysheet saves the data in the table to the database](https://www.cnblogs.com/DuShuSir/p/13857874.html)
------------
## **<span style="font-size:20px;">Q</span>** How to monitor cell hover or click events? how to monitor `cellRenderAfter` in real-time?
## How to monitor cell hover or click events? how to monitor `cellRenderAfter` in real-time?
**<span style="font-size:20px;">A</span>** :我们搜集到需要针对单元格事件的二次开发需求,规划了单元格相关的钩子函数,参考[单元格钩子函数](/guide/config.html#cellrenderafter)(显示的TODO的暂未开放)
**<span style="font-size:20px;">A</span>**: We have collected the secondary development requirements for cell events, and planned the cell-related hook functions, refer to [cell hook function](/guide/config.html#cellrenderafter) (the TODO displayed is not yet open)
------------
## **<span style="font-size:20px;">Q</span>** How to customize the top toolbar?
## How to customize the top toolbar?
**<span style="font-size:20px;">A</span>**
**<span style="font-size:20px;">A</span>**:
reference: [options.showtoolbarconfig](/guide/config.html#showtoolbarconfig)(TODO means waiting to developed)
------------
## **<span style="font-size:20px;">Q</span>** Does the project use jQuery?
## Does the project use jQuery?
**<span style="font-size:20px;">A</span>** yes. At the beginning, Luckysheet uses jQuery。The packaging tool will package the jQuery to this file `./plugins/js/plugin.js`
**<span style="font-size:20px;">A</span>**: yes. At the beginning, Luckysheet uses jQuery。The packaging tool will package the jQuery to this file `./plugins/js/plugin.js`
If your project (such as react / Vue) also references jQuery globally and causes conflicts, you can try to remove a jQuery.
if you want to remove jQuery in `Luckysheet`, you can find `jQuery` in source code folder `gulpfile.js`:[src/plugins/js/jquery.min.js](https://github.com/mengshukeji/Luckysheet/blob/master/gulpfile.js),then delete information related to jQuery.
if you want to remove jQuery in `Luckysheet`, you can find `jQuery` in source code folder `gulpfile.js`: [src/plugins/js/jquery.min.js](https://github.com/mengshukeji/Luckysheet/blob/master/gulpfile.js),then delete information related to jQuery.
------------
## **<span style="font-size:20px;">Q</span>** How to add a field to a cell object?
## How to add a field to a cell object?
**<span style="font-size:20px;">A</span>** reference [cell object format](/guide/cell.html),then read this annotation[src/controllers/postil.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/postil.js)。the annotation is a configuration in a cell object.
**<span style="font-size:20px;">A</span>**: reference [cell object format](/guide/cell.html),then read this annotation[src/controllers/postil.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/postil.js)。the annotation is a configuration in a cell object.
------------
## **<span style="font-size:20px;">Q</span>** The toolbar icon is on the loading stage all the time.
## The toolbar icon is on the loading stage all the time.
**<span style="font-size:20px;">A</span>** The luckysheet use iconfont icon in this project, if any icon cannot be loaded ,plz check your iconfont.css. we are so sorry that we did not describe it clearly in the old version documents.
**<span style="font-size:20px;">A</span>**: The luckysheet use iconfont icon in this project, if any icon cannot be loaded ,plz check your iconfont.css. we are so sorry that we did not describe it clearly in the old version documents.
Now the documents have been updated.[official documents](/guide/#steps-for-usage)
------------
## **<span style="font-size:20px;">Q</span>** Can't run Luckyexcel after package.
## Can't run Luckyexcel after package.
**<span style="font-size:20px;">A</span>** Terminal does not show `end`, but if the `dist` folder has this file `luckyexcel.js`, it is normal.
**<span style="font-size:20px;">A</span>**: Terminal does not show `end`, but if the `dist` folder has this file `luckyexcel.js`, it is normal.
Lucky excel is an excel import and export library. The project uses `gulp` as a packaging tool. There is a problem with the old version of the packaging tool, but it is fixed now. if this problem still troubles you, plz check the following steps
Lucky excel is an excel import and export library. The project uses `gulp` as a packaging tool. There is a problem with the old version of the packaging tool, but it is fixed now. if this problem still troubles you, plz check the following steps:
1. pull the latest code.
2. `npm i`
3. `npm run build`
more information:[Luckyexcel](https://github.com/mengshukeji/Luckyexcel/)
more information: [Luckyexcel](https://github.com/mengshukeji/Luckyexcel/)
------------
## **<span style="font-size:20px;">Q</span>** How to disable editing of cells?How to open sheet protection?
## How to disable editing of cells?How to open sheet protection?
**<span style="font-size:20px;">A</span>** Sheet protection includes disable editing of cells that you need to make some configurations on each sheets. `config.authority`, the latest configurations[sheet protection](/guide/sheet.html#config-authority)。
**<span style="font-size:20px;">A</span>**: Sheet protection includes disable editing of cells that you need to make some configurations on each sheets. `config.authority`, the latest configurations[sheet protection](/guide/sheet.html#config-authority)。
In order to make it easier for you to understand the function of sheet protection, the following video shows how to make the whole sheet uneditable, but allow a column of cells to be edited:
@ -150,21 +152,21 @@ In you local browser, you can open the control pannel, use `luckysheet.getLuckys
------------
## **<span style="font-size:20px;">Q</span>** How to configure data validation?
## How to configure data validation?
**<span style="font-size:20px;">A</span>** there is the configuration of data validation,[data validation](/guide/sheet.html#dataVerification)。Also there is the API that you can use `data validation` in any time. [setDataVerification](/guide/api.html#setdataverification-optionitem-setting).
**<span style="font-size:20px;">A</span>**: there is the configuration of data validation,[data validation](/guide/sheet.html#dataVerification)。Also there is the API that you can use `data validation` in any time. [setDataVerification](/guide/api.html#setdataverification-optionitem-setting).
------------
## **<span style="font-size:20px;">Q</span>** Is there a case for using Luckysheet with CDN?
## Is there a case for using Luckysheet with CDN?
**<span style="font-size:20px;">A</span>** Luckysheet supports CDN. reference:[The case of using luckysheet by CDN](https://www.cnblogs.com/DuShuSir/p/13859103.html)
**<span style="font-size:20px;">A</span>**: Luckysheet supports CDN. reference: [The case of using luckysheet by CDN](https://www.cnblogs.com/DuShuSir/p/13859103.html)
------------
## **<span style="font-size:20px;">Q</span>** how to limit the adaptive height of a picture in a cell?
## how to limit the adaptive height of a picture in a cell?
**<span style="font-size:20px;">A</span>** First of all, you need to move the picture and adjust the cell size, and then there are the following situations:
**<span style="font-size:20px;">A</span>**: First of all, you need to move the picture and adjust the cell size, and then there are the following situations:
- if the cell contains a picture and you expand the cell, the picure will not be expanded.
- if the cell contains a picture and you shorten the cell to the edge of the picture, the picture will shrink.
@ -176,43 +178,43 @@ if you want to get the position of the picture, you can overlap the picture with
------------
## **<span style="font-size:20px;">Q</span>** How to get the default row height and column width of the worksheet?
## How to get the default row height and column width of the worksheet?
**<span style="font-size:20px;">A</span>** There are two ways to get it
**<span style="font-size:20px;">A</span>**: There are two ways to get it
- 1. use `luckysheet.getLuckysheetfile()` to get all configuration data, so you can get the `defaultRowHeight` and `defaultColWidth` in the sheet configuration data。
- 2. use API to get the default row height [getDefaultRowHeight](/guide/api.html#getdefaultrowheight-setting) and column width.[getDefaultColWidth](/guide/api.html#getdefaultcolwidth-setting)
------------
## **<span style="font-size:20px;">Q</span>** How to hide the add row button and the back to top button below the worksheet?
## How to hide the add row button and the back to top button below the worksheet?
**<span style="font-size:20px;">A</span>** Configuration is open
**<span style="font-size:20px;">A</span>**: Configuration is open
- Allow adding rows [enableAddRow](/guide/config.html#enableaddrow)
- Allow back to top [enableAddBackTop](/guide/config.html#enableAddBackTop)
------------
## **<span style="font-size:20px;">Q</span>** How to hide the row and column headings of the worksheet?
## How to hide the row and column headings of the worksheet?
**<span style="font-size:20px;">A</span>** Configuration is open
**<span style="font-size:20px;">A</span>**: Configuration is open
- The width of the row header area [rowHeaderWidth](/guide/config.html#rowheaderwidth)
- The height of the column header area [columnHeaderHeight](/guide/config.html#columnHeaderHeight)
------------
## **<span style="font-size:20px;">Q</span>** What method can be called to set `config.merge`?
## What method can be called to set `config.merge`?
**<span style="font-size:20px;">A</span>** Three methods
**<span style="font-size:20px;">A</span>**: Three methods
- Interface operation
- Use API: [setRangeMerge](/guide/api.html#setrangemerge-type-setting)
- Manually assemble merge parameters
------------
## **<span style="font-size:20px;">Q</span>** Why is the official new feature ineffective?
## Why is the official new feature ineffective?
**<span style="font-size:20px;">A</span>** The first step is to check whether you have used CDN to import,
**<span style="font-size:20px;">A</span>**: The first step is to check whether you have used CDN to import,
The CDN link used in the Luckysheet tutorial is the service provided by [jsdelivr](https://www.jsdelivr.com/package/npm/luckysheet), and the code is from [npmjs.com](https://www.npmjs.com/) automatically sync the past, not from [Github](https://github.com/mengshukeji/Luckysheet/). Because our newly submitted code still needs to be tested for a period of time, it will not be released to npm immediately, causing the npm code to lag behind Github.
@ -222,9 +224,9 @@ The second step, if it is to import the packaged code of the github repository,
------------
## **<span style="font-size:20px;">Q</span>** `npm run dev` reported an error: ʻError: Cannot find module'rollup'`?
## `npm run dev` reported an error: ʻError: Cannot find module'rollup'`?
**<span style="font-size:20px;">A</span>** It may be a problem with the npm package installation, try the following steps:
**<span style="font-size:20px;">A</span>**: It may be a problem with the npm package installation, try the following steps:
1. `npm cache clean --force`
2. `npm i rimraf -g`
3. `rimraf node_modules`
@ -236,9 +238,9 @@ Tip: Most other npm installation problems can also be solved by trying above ste
------------
## **<span style="font-size:20px;">Q</span>**How to carry out secondary development of Luckysheet in Vue project?
## How to carry out secondary development of Luckysheet in Vue project?
**<span style="font-size:20px;">A</span>** The [luckysheet-vue](https://github.com/mengshukeji/luckysheet-vue) case is to provide an application integration solution.
**<span style="font-size:20px;">A</span>**: The [luckysheet-vue](https://github.com/mengshukeji/luckysheet-vue) case is to provide an application integration solution.
If directly developed locally:
1. Start both the Luckysheet project and your own Vue project. For example, the Luckysheet project is at http://localhost:3001
@ -248,38 +250,38 @@ In this case, after Luckysheet is modified in real time, the changes can be seen
------------
## **<span style="font-size:20px;">Q</span>** Error reporting `Store.createChart` when creating chart?
## Error reporting `Store.createChart` when creating chart?
**<span style="font-size:20px;">A</span>** You need to introduce a chart plugin to use it. You should configure the chart plugin to use when the workbook is initialized. Refer to
**<span style="font-size:20px;">A</span>**: You need to introduce a chart plugin to use it. You should configure the chart plugin to use when the workbook is initialized. Refer to
- Plugins configuration [plugins](/guide/config.html#plugins)
- 或 官方demo [src/index.html](https://github.com/mengshukeji/Luckysheet/blob/master/src/index.html)
------------
## **<span style="font-size:20px;">Q</span>** Can cells add custom attributes?
## Can cells add custom attributes?
**<span style="font-size:20px;">A</span>** The custom attributes directly assigned to the cell object will be filtered. To make the custom attributes take effect, you need to edit the code to remove the filter attributes.
**<span style="font-size:20px;">A</span>**: The custom attributes directly assigned to the cell object will be filtered. To make the custom attributes take effect, you need to edit the code to remove the filter attributes.
------------
## **<span style="font-size:20px;">Q</span>** How to enter text starting with `'='`? For example, `=currentDate('YYYY-MM-DD')`, it will remove the function by default, how to prohibit the function?
## How to enter text starting with `'='`? For example, `=currentDate('YYYY-MM-DD')`, it will remove the function by default, how to prohibit the function?
**<span style="font-size:20px;">A</span>** Just add a single quotation mark in front of it, and it will be forcibly recognized as a string, which is consistent with excel. For example: `'=currentDate('YYYY-MM-DD')`
**<span style="font-size:20px;">A</span>**: Just add a single quotation mark in front of it, and it will be forcibly recognized as a string, which is consistent with excel. For example: `'=currentDate('YYYY-MM-DD')`
------------
## **<span style="font-size:20px;">Q</span>** Why does the create callback have no effect?
## Why does the create callback have no effect?
**<span style="font-size:20px;">A</span>** The API method `luckysheet.create()` does not have a callback, but Luckysheet provides a hook function to execute the callback method at a specified location, such as:
**<span style="font-size:20px;">A</span>**: The API method `luckysheet.create()` does not have a callback, but Luckysheet provides a hook function to execute the callback method at a specified location, such as:
- Triggered before the workbook is created [workbookCreateBefore](/guide/config.html#workbookcreatebefore)
- Triggered after the workbook is created [workbookCreateAfter](/guide/config.html#workbookcreateafter)
------------
## **<span style="font-size:20px;">Q</span>** When create, the first cell is selected by default, how to remove it?
## When create, the first cell is selected by default, how to remove it?
**<span style="font-size:20px;">A</span>** When the cell is selected, it is highlighted by default, just remove the highlight, use API: [setRangeShow](/guide/api.html#setrangeshow-range-setting)
**<span style="font-size:20px;">A</span>**: When the cell is selected, it is highlighted by default, just remove the highlight, use API: [setRangeShow](/guide/api.html#setrangeshow-range-setting)
```js
luckysheet.setRangeShow("A2",{show:false})
@ -287,17 +289,37 @@ luckysheet.setRangeShow("A2",{show:false})
------------
## **<span style="font-size:20px;">Q</span>** Where is the right-click event bound?
## Where is the right-click event bound?
**<span style="font-size:20px;">A</span>** In the source code [src/controllers/hander.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/handler.js), search for `event.which == "3"` to find the code executed by the right-click event.
**<span style="font-size:20px;">A</span>**: In the source code [src/controllers/hander.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/handler.js), search for `event.which == "3"` to find the code executed by the right-click event.
------------
## **<span style="font-size:20px;">Q</span>** How to add a custom toolbar?
## How to add a custom toolbar?
**<span style="font-size:20px;">A</span>** No configuration is currently provided, you can refer to the implementation of the print button in the toolbar to modify the source code:
**<span style="font-size:20px;">A</span>**: No configuration is currently provided, you can refer to the implementation of the print button in the toolbar to modify the source code:
1. Search for `luckysheet-icon-print` globally to find the implementation of the print button, in [src/controllers/constant.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/constant.js) add a similar template string, you need to customize a unique id
2. Modify [src/controllers/resize.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/resize.js) and add a new record in the toobarConfig object
3. Modify [src/controllers/menuButton.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/menuButton.js) to add an event listener
------------
## How to add custom formulas?
**<span style="font-size:20px;">A</span>**: Two source codes need to be modified:
1. Add a formula to the `functionImplementation` object in the [src/function/functionImplementation.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/function/functionImplementation.js) file, format refer to formulas such as `SUM`/`AVERAGE`
2. Modify all the language packs in the [src/locale](https://github.com/mengshukeji/Luckysheet/blob/master/src/locale) file directory, and add the new formula description to the `functionlist` array in. Among them, `t` is the category of the function, `m` is the number of parameters, the minimum number of parameters and the maximum number of parameters.
------------
## Is there a similar loadData interface, I want to load 10 records first, and then dynamically load the data, these data are appended to the table?
**<span style="font-size:20px;">A</span>**: Yes. Our `loadSheetUrl` provides this function, which can be turned on by initializing `options.enablePage = true`.
Searching for `enablePage` in the source code, you can see that there is a `method.addDataAjax` method, which contains an ajax request to dynamically load data, which will be appended to the worksheet.
This function is now hidden in the document, because when we made this interface, the interface parameters were matched according to our actual business, which may not be universal. We are going to abstract and release it for everyone to use. If you want to use it yourself you can change it based on this.
It is recommended that you consider writing your own interface to load the data, and then use `setRangeValue` to append the data at the specified location, which has a higher degree of customization.
------------

10
docs/guide/api.md

@ -585,7 +585,7 @@ Use note:
- **Parameter**
- {Number} [columnInfo]: Correspondence between the number of columns and the width
- {Object} [columnInfo]: Correspondence between the number of columns and the width
- {PlainObject} [setting]: optional parameters
+ {Number} [order]: Worksheet subscript; the default value is the current worksheet subscript
@ -2560,17 +2560,13 @@ Use note:
### refreshFormula([setting])
[todo]
- **Parameter**
- {PlainObject} [setting]: optional parameters
+ {Object | String} [range]: Set the target selection range of the parameter. The supported selection format is `"A1:B2"`, `"sheetName!A1:B2"` or `{row:[0,1], column:[0,1]}`, allows an array of multiple selections; the default is the current selection ;The default is the entire current worksheet
+ {Function} [success]: callback function for the end of the operation
- {Function} [success]: callback function for the end of the operation
- **Explanation**
Force refresh formula. When you directly modify the values of multiple cells without triggering a refresh, and these cells are associated with formulas, you can use this API to force a formula refresh to be triggered at the end. It is generally recommended to specify the affected cell range to prevent For performance issues, if you can't determine it, leave it blank to keep the entire worksheet traversed and refreshed.
Force refresh formula. When you directly modify the values of multiple cells without triggering a refresh, and these cells are associated with formulas, you can use this API to force a formula refresh to be triggered at the end.
------------

30
docs/guide/config.md

@ -73,6 +73,7 @@ The following are all supported setting parameters
- The height of the column header area [columnHeaderHeight](#columnHeaderHeight)
- Whether to show the formula bar [sheetFormulaBar](#sheetFormulaBar)
- Initialize the default font size [defaultFontSize](#defaultFontSize)
- Pager [pager](#pager)
### container
- Type: String
@ -567,6 +568,21 @@ Note that you also need to configure `loadUrl` and `loadSheetUrl` to take effect
------------
### pager
- Type:Object
- Default:null
- Usage:Pager button settings, the first version of the solution is directly used jquery plug-in [sPage](https://github.com/jvbei/sPage)
Clicking the paging button will trigger the hook function `onTogglePager`, which returns the current page number, which is the same as the `backFun` method of `sPage`. This pager setting is only responsible for the UI part. For the specific data request and data rendering after switching paging, please enter the `onTogglePager` custom processing in the number of hook lines.
```js
pager: {
pageIndex: 1, //Current page number
pageSize: 10, //How many rows of data are displayed on each page
total: 50, //Total number of rows of data
selectOption: [10, 20] //Options that allow setting the number of rows per page
}
```
------------
## Hook Function (TODO)
@ -1071,7 +1087,7 @@ The hook functions are uniformly configured under ʻoptions.hook`, and configura
### updated
- Type: Function
- Default: null
- Usage: The method executed after each operation is updated is executed after the canvas rendering, that is, every time the client performs a workbook operation, Luckysheet saves the operation in the history and triggers it. When undoing and redoing, it is also an operation, of course, the hook function will be triggered.
- Usage: The method executed after each operation is updated is executed after the canvas rendering, monitor changes in worksheet content, that is, every time the client performs a workbook operation, Luckysheet saves the operation in the history and triggers it. When undoing and redoing, it is also an operation, of course, the hook function will be triggered.
- Parameter:
- {Object} [operate]: The history information of this operation will have different history records according to different operations. Refer to the source code [History](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/controlHistory.js )
@ -1251,4 +1267,16 @@ The hook functions are uniformly configured under ʻoptions.hook`, and configura
- Default: null
- Usage: Customized method of drilling down cell data, note that this hook function is mounted under options: `options.fireMousedown`
------------
## Pager
### onTogglePager
- Type: Function
- Default: null
- Usage: Click the page button to call back the function, return the current page number, refer to [sPage backFun](https://github.com/jvbei/sPage)
- Parameter:
- {Object} [page]: Return the current page object
------------

158
docs/zh/guide/FAQ.md

@ -1,10 +1,10 @@
# 常见问题
本章内容搜集了大家反馈的常见问题,如果官方文档和此列表都不能解答您的疑问,推荐到[官方论坛](https://support.qq.com/product/288322)反馈
本章内容搜集了大家反馈的常见问题,如果官方文档和此列表都不能解答您的疑问,推荐到[官方论坛](https://github.com/mengshukeji/Luckysheet/discussions)反馈
## **<span style="font-size:20px;">Q</span>** luckysheetfile中的data和celldata有什么区别?
## luckysheetfile中的data和celldata有什么区别?
**<span style="font-size:20px;">A</span>** : 表格初始化时使用一维数组格式的 [celldata](/zh/guide/sheet.html#celldata),初始化完成后转化为二维数组格式的data作为存储更新使用,celldata不再使用。
**<span style="font-size:20px;">A</span>**表格初始化时使用一维数组格式的 [celldata](/zh/guide/sheet.html#celldata),初始化完成后转化为二维数组格式的data作为存储更新使用,celldata不再使用。
如果需要将`data`拿出来作为初始化数据,则需要执行 [transToCellData(data)](/zh/guide/api.html#transtocelldata-data-setting)转换为celldata数据。
其中`{ r, c, v }`格式的celldata转换为二维数组使用的是[transToData(celldata)](/zh/guide/api.html#transtodata-celldata-setting)
@ -20,68 +20,68 @@ luckysheet.transToData(celldata)
------------
## **<span style="font-size:20px;">Q</span>** 单元格的类型有哪些?
## 单元格的类型有哪些?
**<span style="font-size:20px;">A</span>** : 参考[单元格格式列表](/zh/guide/cell.html),例举了可用的单元格格式
**<span style="font-size:20px;">A</span>**参考[单元格格式列表](/zh/guide/cell.html),例举了可用的单元格格式
------------
## **<span style="font-size:20px;">Q</span>** 如何在Vue/React项目中使用Luckysheet?
## 如何在Vue/React项目中使用Luckysheet?
**<span style="font-size:20px;">A</span>** : 
**<span style="font-size:20px;">A</span>**:参考
- Vue案例:[luckysheet-vue](https://github.com/mengshukeji/luckysheet-vue)
- React案例:[luckysheet-react](https://github.com/mengshukeji/luckysheet-react)
------------
## **<span style="font-size:20px;">Q</span>** 为什么初始化后表格里面的公式不会被触发?
## 为什么初始化后表格里面的公式不会被触发?
**<span style="font-size:20px;">A</span>** : 参考 [表格数据格式](/zh/guide/sheet.html#calcchain) ,设置单元格数据对应的calcChain即可。
**<span style="font-size:20px;">A</span>**参考 [表格数据格式](/zh/guide/sheet.html#calcchain) ,设置单元格数据对应的calcChain即可。
------------
## **<span style="font-size:20px;">Q</span>** 远端加载数据是loadUrl还是updateUrl?
## 远端加载数据是loadUrl还是updateUrl?
**<span style="font-size:20px;">A</span>** : [loadUrl](/zh/guide/config.html#loadurl)。配置了loadUrl,Luckysheet会通过ajax请求整个表格数据,而updateUrl会作为协同编辑实时保存的接口地址。
**<span style="font-size:20px;">A</span>**:[loadUrl](/zh/guide/config.html#loadurl)。配置了loadUrl,Luckysheet会通过ajax请求整个表格数据,而updateUrl会作为协同编辑实时保存的接口地址。
注意:初始化数据需要配置loadUrl参数,而协同编辑则在配置loadUrl、updateUrl和allowUpdate四个参数才能生效。
------------
## **<span style="font-size:20px;">Q</span>** 每个sheet页的`index`和`order`有什么区别?
## 每个sheet页的`index`和`order`有什么区别?
**<span style="font-size:20px;">A</span>** : 每个sheet页都有一个唯一id,就是`index`,可以用数字递增,也可以使用随机字符串,而`order`是所有的sheet的排序情况,从0开始,只能为数字`0,1,2...`。
**<span style="font-size:20px;">A</span>**每个sheet页都有一个唯一id,就是`index`,可以用数字递增,也可以使用随机字符串,而`order`是所有的sheet的排序情况,从0开始,只能为数字`0,1,2...`。
------------
## **<span style="font-size:20px;">Q</span>** dist文件夹下为什么不能直接运行项目?
## dist文件夹下为什么不能直接运行项目?
**<span style="font-size:20px;">A</span>** :需要启动本地服务器
**<span style="font-size:20px;">A</span>**需要启动本地服务器
- [Node搭建本地服务器](https://github.com/JacksonTian/anywhere)
- [Python搭建本地服务器](https://developer.mozilla.org/zh-CN/docs/Learn/Common_questions/set_up_a_local_testing_server)
------------
## **<span style="font-size:20px;">Q</span>** excel导入导出怎么做?
## excel导入导出怎么做?
**<span style="font-size:20px;">A</span>** :配合Luckysheet开发的excel导入导出库-[Luckyexcel](https://github.com/mengshukeji/Luckyexcel)已经实现了excel导入功能,导出功能正在开发当中。现阶段excel导出可以参考这2篇博文:
**<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>** :参考以下案例
**<span style="font-size:20px;">A</span>**参考以下案例
- [Luckysheet如何初始化含合并单元格的数据](https://www.cnblogs.com/DuShuSir/p/13272397.html)
------------
## **<span style="font-size:20px;">Q</span>** Luckysheet如何把表格里的数据保存到数据库?有没有服务端存储和协作的解决方案?
## Luckysheet如何把表格里的数据保存到数据库?有没有服务端存储和协作的解决方案?
**<span style="font-size:20px;">A</span>** :有两个方案:
**<span style="font-size:20px;">A</span>**有两个方案:
- 一是表格操作完成后,使用`luckysheet.getAllSheets()`方法获取到全部的工作表数据,全部发送到后台存储。
- 二是开启协同编辑功能,实时传输数据给后端。
@ -89,22 +89,22 @@ luckysheet.transToData(celldata)
------------
## **<span style="font-size:20px;">Q</span>** 如何监听单元格hover或者点击事件?`cellRenderAfter`如何实时监听变化?
## 如何监听单元格hover或者点击事件?`cellRenderAfter`如何实时监听变化?
**<span style="font-size:20px;">A</span>** :我们搜集到需要针对单元格事件的二次开发需求,规划了单元格相关的钩子函数,参考[单元格钩子函数](/zh/guide/config.html#cellrenderafter)(显示的TODO的暂未开放)
**<span style="font-size:20px;">A</span>**:我们搜集到需要针对单元格事件的二次开发需求,规划了单元格相关的钩子函数,参考[单元格钩子函数](/zh/guide/config.html#cellrenderafter)(显示的TODO的暂未开放)
------------
## **<span style="font-size:20px;">Q</span>** 顶部的工具栏不支持自定义配置?
## 顶部的工具栏不支持自定义配置?
**<span style="font-size:20px;">A</span>**
**<span style="font-size:20px;">A</span>**:
顶部工具栏的自定义配置使用初始[options.showtoolbarconfig](/zh/guide/config.html#showtoolbarconfig)(如果标注TODO表示暂未开发)
------------
## **<span style="font-size:20px;">Q</span>** 项目使用了jQuery吗?
## 项目使用了jQuery吗?
**<span style="font-size:20px;">A</span>** :是的。Luckysheet内部启动时间比开源的时间早很多,所以用到了jQuery。打包工具会把jQuery集成到打包目录的`./plugins/js/plugin.js`文件中。
**<span style="font-size:20px;">A</span>**:是的。Luckysheet内部启动时间比开源的时间早很多,所以用到了jQuery。打包工具会把jQuery集成到打包目录的`./plugins/js/plugin.js`文件中。
如果您的项目中(比如React/Vue)也自己全局引用了jQuery,且造成了冲突,可以尝试去掉一个jQuery。
@ -112,23 +112,23 @@ luckysheet.transToData(celldata)
------------
## **<span style="font-size:20px;">Q</span>** 如何为单元格对象新增字段?
## 如何为单元格对象新增字段?
**<span style="font-size:20px;">A</span>** 首先参考[单元格对象格式](/zh/guide/cell.html),然后参照源码批注的部分[src/controllers/postil.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/postil.js)。批注是一个加在单元格对象上的一个配置。
**<span style="font-size:20px;">A</span>**首先参考[单元格对象格式](/zh/guide/cell.html),然后参照源码批注的部分[src/controllers/postil.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/postil.js)。批注是一个加在单元格对象上的一个配置。
------------
## **<span style="font-size:20px;">Q</span>** 工具栏图标加载不出来?
## 工具栏图标加载不出来?
**<span style="font-size:20px;">A</span>** 工具栏及其他部分图标采用了iconfont图标,加载不出来是因为缺少了iconfont.css的引入,之前旧版官方文档未写清楚这一点对大家造成误导,很抱歉。
**<span style="font-size:20px;">A</span>**工具栏及其他部分图标采用了iconfont图标,加载不出来是因为缺少了iconfont.css的引入,之前旧版官方文档未写清楚这一点对大家造成误导,很抱歉。
详细的Luckysheet使用教程参考已经更新的[官方文档](/zh/guide/#使用步骤)
------------
## **<span style="font-size:20px;">Q</span>** Luckyexcel打包后不动?
## Luckyexcel打包后不动?
**<span style="font-size:20px;">A</span>** 打包的终端命令行不显示结束,但是如果`dist`文件夹内已经有了结果文件`luckyexcel.js`,则表明是正常的。
**<span style="font-size:20px;">A</span>**打包的终端命令行不显示结束,但是如果`dist`文件夹内已经有了结果文件`luckyexcel.js`,则表明是正常的。
Luckyexcel是excel导入导出库,项目采用了gulp作为打包工具,旧版打包工具有点问题在命令行显示这块有些问题,问题已经修复。请还出现此问题的小伙伴做如下更新操作:
1. pull最新代码
@ -139,9 +139,9 @@ Luckyexcel是excel导入导出库,项目采用了gulp作为打包工具,旧
------------
## **<span style="font-size:20px;">Q</span>** 单元格不可编辑如何控制?表格保护怎么操作?
## 单元格不可编辑如何控制?表格保护怎么操作?
**<span style="font-size:20px;">A</span>** 单元格不可编辑属于工作表保护的功能范畴,需要配置在每个sheet页中`config.authority`,最新的设置参数请参考[工作表保护](/zh/guide/sheet.html#config-authority)。
**<span style="font-size:20px;">A</span>**单元格不可编辑属于工作表保护的功能范畴,需要配置在每个sheet页中`config.authority`,最新的设置参数请参考[工作表保护](/zh/guide/sheet.html#config-authority)。
为了大家便于理解工作表保护的功能使用,下方的视频演示了如何让当前整个工作表不可编辑,但是允许某一列单元格可编辑的功能:
@ -151,21 +151,21 @@ Luckyexcel是excel导入导出库,项目采用了gulp作为打包工具,旧
------------
## **<span style="font-size:20px;">Q</span>** 数据验证怎么配置?
## 数据验证怎么配置?
**<span style="font-size:20px;">A</span>** 最新文档已经提供了数据验证的配置信息,参考[数据验证配置](/zh/guide/sheet.html#dataVerification)。官方也提供了API方法 [setDataVerification](/zh/guide/api.html#setdataverification-optionitem-setting),用于动态设置数据验证功能。
**<span style="font-size:20px;">A</span>**最新文档已经提供了数据验证的配置信息,参考[数据验证配置](/zh/guide/sheet.html#dataVerification)。官方也提供了API方法 [setDataVerification](/zh/guide/api.html#setdataverification-optionitem-setting),用于动态设置数据验证功能。
------------
## **<span style="font-size:20px;">Q</span>** Luckysheet通过引入CDN有案例吗?
## Luckysheet通过引入CDN有案例吗?
**<span style="font-size:20px;">A</span>** Luckysheet支持CDN方式引入,参考:[本地HTML采用cdn加载方式引入Luckysheet的案例](https://www.cnblogs.com/DuShuSir/p/13859103.html)
**<span style="font-size:20px;">A</span>**Luckysheet支持CDN方式引入,参考:[本地HTML采用cdn加载方式引入Luckysheet的案例](https://www.cnblogs.com/DuShuSir/p/13859103.html)
------------
## **<span style="font-size:20px;">Q</span>** 请问一下图片怎么限制在单元格里面自适应高度?
## 请问一下图片怎么限制在单元格里面自适应高度?
**<span style="font-size:20px;">A</span>** 首先需要对图片设置移动并调整单元格大小,然后有以下几种情况:
**<span style="font-size:20px;">A</span>**首先需要对图片设置移动并调整单元格大小,然后有以下几种情况:
- 如果图片位置完全在单元格内部时,当拉长单元格的宽度或高度的时候,图片不会随着单元格的变大而伸缩变大
- 如果图片位置完全在单元格内部时,当拉短单元格的宽度或高度,贴到图片的边时,图片会随着单元格的变小而伸缩变小
@ -177,43 +177,43 @@ Luckyexcel是excel导入导出库,项目采用了gulp作为打包工具,旧
------------
## **<span style="font-size:20px;">Q</span>** 如何获取工作表默认的行高列宽?
## 如何获取工作表默认的行高列宽?
**<span style="font-size:20px;">A</span>** 有两种方式可以获取
**<span style="font-size:20px;">A</span>**有两种方式可以获取
- 一是使用`luckysheet.getLuckysheetfile()`获取到所有工作表配置后,在各个工作表的配置中直接取得默认行高`defaultRowHeight`和默认列宽`defaultColWidth`。
- 二是开放了API可以获取到工作表默认的行高[getDefaultRowHeight](/zh/guide/api.html#getdefaultrowheight-setting)和列宽[getDefaultColWidth](/zh/guide/api.html#getdefaultcolwidth-setting)
------------
## **<span style="font-size:20px;">Q</span>** 如何隐藏工作表下方的添加行按钮和回到顶部按钮?
## 如何隐藏工作表下方的添加行按钮和回到顶部按钮?
**<span style="font-size:20px;">A</span>** 已开放配置
**<span style="font-size:20px;">A</span>**已开放配置
- 允许添加行 [enableAddRow](/zh/guide/config.html#enableaddrow)
- 允许回到顶部 [enableAddBackTop](/zh/guide/config.html#enableAddBackTop)
------------
## **<span style="font-size:20px;">Q</span>** 如何隐藏工作表的行标题和列标题?
## 如何隐藏工作表的行标题和列标题?
**<span style="font-size:20px;">A</span>** 已开放配置
**<span style="font-size:20px;">A</span>**已开放配置
- 行标题区域的宽度 [rowHeaderWidth](/zh/guide/config.html#rowheaderwidth)
- 列标题区域的高度 [columnHeaderHeight](/zh/guide/config.html#columnHeaderHeight)
------------
## **<span style="font-size:20px;">Q</span>** 调用什么方法能设置`config.merge`?
## 调用什么方法能设置`config.merge`?
**<span style="font-size:20px;">A</span>** 三个方法
**<span style="font-size:20px;">A</span>**三个方法
- 界面操作
- 用API:[setRangeMerge](/zh/guide/api.html#setrangemerge-type-setting)
- 手动组装merge参数
------------
## **<span style="font-size:20px;">Q</span>** 为什么官方公布的新功能没有效果?
## 为什么官方公布的新功能没有效果?
**<span style="font-size:20px;">A</span>** 第一步,检查下您是否使用了CDN的方式引入,
**<span style="font-size:20px;">A</span>**第一步,检查下您是否使用了CDN的方式引入,
Luckysheet教程里采用的CDN链接是 [jsdelivr](https://www.jsdelivr.com/package/npm/luckysheet) 提供的服务,代码是从 [npmjs.com](https://www.npmjs.com/) 自动同步过去的,不是从 [Github](https://github.com/mengshukeji/Luckysheet/) 同步过去的。因为我们新提交的代码,还需要经过一段时间的测试,所以不会立即发布到npm使用,导致了npm的代码稍滞后于Github。
@ -223,9 +223,9 @@ Luckysheet教程里采用的CDN链接是 [jsdelivr](https://www.jsdelivr.com/pac
------------
## **<span style="font-size:20px;">Q</span>** `npm run dev`报错:`Error: Cannot find module 'rollup'`?
## `npm run dev`报错:`Error: Cannot find module 'rollup'`?
**<span style="font-size:20px;">A</span>** 可能是npm包安装问题,尝试以下步骤:
**<span style="font-size:20px;">A</span>**可能是npm包安装问题,尝试以下步骤:
1. `npm cache clean --force`
2. `npm i rimraf -g`
3. `rimraf node_modules`
@ -237,9 +237,9 @@ Luckysheet教程里采用的CDN链接是 [jsdelivr](https://www.jsdelivr.com/pac
------------
## **<span style="font-size:20px;">Q</span>** 怎样在vue工程里对Luckysheet进行二次开发?
## 怎样在vue工程里对Luckysheet进行二次开发?
**<span style="font-size:20px;">A</span>** [luckysheet-vue](https://github.com/mengshukeji/luckysheet-vue) 案例是提供一个应用集成的方案。
**<span style="font-size:20px;">A</span>**:[luckysheet-vue](https://github.com/mengshukeji/luckysheet-vue) 案例是提供一个应用集成的方案。
如果本地直接开发的话:
1. 把Luckysheet的工程和自己的Vue工程都启动起来,比如Luckysheet的工程在 `http://localhost:3001`
@ -249,9 +249,9 @@ Luckysheet教程里采用的CDN链接是 [jsdelivr](https://www.jsdelivr.com/pac
------------
## **<span style="font-size:20px;">Q</span>** 创建图表时候报错`Store.createChart`?
## 创建图表时候报错`Store.createChart`?
**<span style="font-size:20px;">A</span>** 需要引入图表插件才能使用,工作簿初始化的时候应该配置图表插件使用,参考
**<span style="font-size:20px;">A</span>**需要引入图表插件才能使用,工作簿初始化的时候应该配置图表插件使用,参考
- 插件配置 [plugins](/zh/guide/config.html#配置项)
- 或 官方demo [src/index.html](https://github.com/mengshukeji/Luckysheet/blob/master/src/index.html)
@ -260,29 +260,29 @@ Luckysheet教程里采用的CDN链接是 [jsdelivr](https://www.jsdelivr.com/pac
------------
## **<span style="font-size:20px;">Q</span>** 单元格能增加自定义属性吗?
## 单元格能增加自定义属性吗?
**<span style="font-size:20px;">A</span>** 直接赋值到单元格对象上的自定义属性会被过滤,要想使得自定义属性生效,需要二开去除过滤属性的代码。
**<span style="font-size:20px;">A</span>**直接赋值到单元格对象上的自定义属性会被过滤,要想使得自定义属性生效,需要二开去除过滤属性的代码。
------------
## **<span style="font-size:20px;">Q</span>** 如何输入以`'='`开头的文本?例如`=currentDate('YYYY-MM-DD')`,它默认会去掉函数,函数怎么禁止?
## 如何输入以`'='`开头的文本?例如`=currentDate('YYYY-MM-DD')`,它默认会去掉函数,函数怎么禁止?
**<span style="font-size:20px;">A</span>** 前面加一个单引号就行,会强制识别为字符串,和excel表现一致的。比如:`'=currentDate('YYYY-MM-DD')`
**<span style="font-size:20px;">A</span>**前面加一个单引号就行,会强制识别为字符串,和excel表现一致的。比如:`'=currentDate('YYYY-MM-DD')`
------------
## **<span style="font-size:20px;">Q</span>** create回调为什么没有效果?
## create回调为什么没有效果?
**<span style="font-size:20px;">A</span>** API 方法`luckysheet.create()`这个方法没有回调,但是Luckysheet提供了钩子函数用于在指定位置执行回调方法,比如:
**<span style="font-size:20px;">A</span>**API 方法`luckysheet.create()`这个方法没有回调,但是Luckysheet提供了钩子函数用于在指定位置执行回调方法,比如:
- 表格创建之前触发 [workbookCreateBefore](/zh/guide/config.html#workbookcreatebefore)
- 表格创建之后触发 [workbookCreateAfter](/zh/guide/config.html#workbookcreateafter)
------------
## **<span style="font-size:20px;">Q</span>** create的时候默认选中第一个单元格,怎么去除?
## create的时候默认选中第一个单元格,怎么去除?
**<span style="font-size:20px;">A</span>** 选中单元格时默认是高亮,把高亮去除即可,使用API: [setRangeShow](/zh/guide/api.html#setrangeshow-range-setting)
**<span style="font-size:20px;">A</span>**选中单元格时默认是高亮,把高亮去除即可,使用API: [setRangeShow](/zh/guide/api.html#setrangeshow-range-setting)
```js
luckysheet.setRangeShow("A2",{show:false})
@ -290,17 +290,37 @@ luckysheet.setRangeShow("A2",{show:false})
------------
## **<span style="font-size:20px;">Q</span>** 右键事件绑定在哪?
## 右键事件绑定在哪?
**<span style="font-size:20px;">A</span>** 在源码的 [src/controllers/hander.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/handler.js) 搜索`event.which == "3"`即可找到右键事件触发执行的代码。
**<span style="font-size:20px;">A</span>**在源码的 [src/controllers/hander.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/handler.js) 搜索`event.which == "3"`即可找到右键事件触发执行的代码。
------------
## **<span style="font-size:20px;">Q</span>** 如何添加自定义工具栏?
## 如何添加自定义工具栏?
**<span style="font-size:20px;">A</span>** 暂未提供配置,可以参照工具栏打印按钮的实现来修改源码:
**<span style="font-size:20px;">A</span>**暂未提供配置,可以参照工具栏打印按钮的实现来修改源码:
1. 全局搜索 `luckysheet-icon-print`即可找到打印按钮的实现,在 [src/controllers/constant.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/constant.js) 中增加一个类似的模板字符串,需要自定义一个唯一id
2. 修改 [src/controllers/resize.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/resize.js) ,在toobarConfig对象中新增一条记录
3. 修改 [src/controllers/menuButton.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/menuButton.js) ,新增一个事件监听
------------
## 如何添加自定义公式?
**<span style="font-size:20px;">A</span>**:需要修改两处源码:
1. 在 [src/function/functionImplementation.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/function/functionImplementation.js) 文件中的`functionImplementation`对象中增加一个公式,格式参考`SUM`/`AVERAGE`等公式
2. 修改 [src/locale](https://github.com/mengshukeji/Luckysheet/blob/master/src/locale) 文件目录下所有的语言包,将自己新增的公式说明加到`functionlist`数组中。其中,`t`是函数的类别,`m`是参数的个数,最小参数个数和最大参数个数。
------------
## 有没有类似loadData接口,我想实现先加载10条记录,然后再动态加载数据,这些数据都追加到表格中?
**<span style="font-size:20px;">A</span>**:有的。我们`loadSheetUrl`提供了这个功能,初始化`options.enablePage = true`可以开启。
源码里搜索`enablePage`可以看到,有个`method.addDataAjax`方法,里面就有一个ajax请求,用来动态加载数据,这些数据会追加到表格中。
这个功能现在在文档上是隐藏的,是因为这个接口我们做的时候,接口参数是根据我们实际业务匹配的,可能不太通用,我们准备抽象后再放出来给大家用,如果您想自己用可以依据这个改下。
推荐您考虑自己写接口来加载数据,然后使用`setRangeValue`来在指定位置追加数据,这样的自定义程度更高。
------------

12
docs/zh/guide/api.md

@ -584,7 +584,7 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
- **参数**
- {Number} [columnInfo]: 列数和宽度对应关系
- {Object} [columnInfo]: 列数和宽度对应关系
- {PlainObject} [setting]: 可选参数
+ {Number} [order]: 工作表下标;默认值为当前工作表下标
@ -2474,19 +2474,15 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
------------
### refreshFormula([setting])
[todo]
### refreshFormula([success])
- **参数**
- {PlainObject} [setting]: 可选参数
+ {Object | String} [range]: 选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,只能为单个选区;默认为整个当前工作表
+ {Function} [success]: 操作结束的回调函数
- {Function} [success]: 操作结束的回调函数
- **说明**
强制刷新公式。当你直接修改了多个单元格的值,且没有触发刷新,且这些单元格跟公式相关联,则可以使用这个api最后强制触发一次公式刷新,一般是建议指定受影响的单元格范围便于防止性能问题,如果无法确定,则留空保持整个工作表遍历刷新
强制刷新公式。当你直接修改了多个单元格的值,且没有触发刷新,且这些单元格跟公式相关联,则可以使用这个api最后强制触发一次公式刷新。
------------

43
docs/zh/guide/config.md

@ -76,6 +76,7 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 初始化默认字体大小 [defaultFontSize](#defaultFontSize)
- 是否限制工作表名长度 [limitSheetNameLength](#limitSheetNameLength)
- 默认允许工作表名的最大长度 [defaultSheetNameMaxLength](#defaultSheetNameMaxLength)
- 分页器 [pager](#pager)
### container
- 类型:String
@ -661,6 +662,22 @@ Luckysheet开放了更细致的自定义配置选项,分别有
------------
### pager
- 类型:Object
- 默认值:null
- 作用:分页器按钮设置,初版方案是直接使用的jquery插件 [sPage](https://github.com/jvbei/sPage)
点击分页按钮会触发钩子函数 `onTogglePager`,返回当前页码,同`sPage`的`backFun`方法,此分页器设置只负责UI部分,具体切换分页后的数据请求和数据渲染,请在`onTogglePager`钩子行数里自定义处理。
```js
pager: {
pageIndex: 1, //当前的页码
pageSize: 10, //每页显示多少行数据
total: 50, //数据总行数
selectOption: [10, 20] //允许设置每页行数的选项
}
```
------------
## 钩子函数
钩子函数应用于二次开发时,会在各个常用鼠标或者键盘操作时植入钩子,调用开发者传入的函数,起到扩展Luckysheet功能的作用。
@ -932,6 +949,18 @@ Luckysheet开放了更细致的自定义配置选项,分别有
+ {Boolean} [hyperlinkClick]:点击超链接
- {Object} [ctx]: 当前画布的context
------------
### scroll
- 类型:Function
- 默认值:null
- 作用:鼠标滚动事件
- 参数:{, , }
- {Object} [position]:
+ {Number} [scrollLeft]:横向滚动条的位置
+ {Number} [scrollTop]:垂直滚动条的位置
+ {Number} [canvasHeight]:canvas高度
------------
## 选区操作(包括单元格)
@ -1298,7 +1327,7 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 类型:Function
- 默认值:null
- 作用:协同编辑中的每次操作后执行的方法,即客户端每执行一次表格操作,Luckysheet将这次操作存到历史记录中后触发,撤销重做时因为也算一次操作,也会触发此钩子函数。
- 作用:协同编辑中的每次操作后执行的方法,监听表格内容变化,即客户端每执行一次表格操作,Luckysheet将这次操作存到历史记录中后触发,撤销重做时因为也算一次操作,也会触发此钩子函数。
- 参数:
- {Object} [operate]: 本次操作的历史记录信息,根据不同的操作,会有不同的历史记录,参考源码 [历史记录](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/controlHistory.js)
@ -1519,4 +1548,16 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 默认值:null
- 作用:单元格数据下钻自定义方法,注意此钩子函数是挂载在options下:`options.fireMousedown`
------------
## 分页器
### onTogglePager
- 类型:Function
- 默认值:null
- 作用:点击分页按钮回调函数,返回当前页码,具体参数参照[sPage backFun](https://github.com/jvbei/sPage)
- 参数:
- {Object} [page]: 返回当前分页对象
------------

45
src/controllers/handler.js

@ -1465,12 +1465,57 @@ export default function luckysheetHandler() {
imageCtrl.inserImg(src);
}
}
handleCellDragStopEvent(e);
}, false);
document.getElementById('luckysheet-cell-main').addEventListener('dragover', function(e){
e.preventDefault();
e.stopPropagation();
}, false);
/**
* 处理单元格上鼠标拖拽停止事件
* @param {DragEvent} event
*/
function handleCellDragStopEvent(event) {
if (luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.cellDragStop) {
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();
let row_location = rowLocation(y),
row = row_location[1],
row_pre = row_location[0],
row_index = row_location[2];
let col_location = colLocation(x),
col = col_location[1],
col_pre = col_location[0],
col_index = col_location[2];
let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index);
if (!!margeset) {
row = margeset.row[1];
row_pre = margeset.row[0];
row_index = margeset.row[2];
col = margeset.column[1];
col_pre = margeset.column[0];
col_index = margeset.column[2];
}
let sheetFile = sheetmanage.getSheetByIndex();
let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");
method.createHookFunction("cellDragStop", Store.flowdata[row_index][col_index], {
r: row_index,
c: col_index,
"start_r": row_pre,
"start_c": col_pre,
"end_r": row,
"end_c": col
}, sheetFile, luckysheetTableContent, event);
}
}
//表格mousemove
$(document).on("mousemove.luckysheetEvent",function (event) {
luckysheetPostil.overshow(event); //有批注显示

6
src/controllers/menuButton.js

@ -3204,7 +3204,8 @@ const menuButton = {
fv[mc_r + "_" + mc_c] = $.extend(true, {}, cell);
}
else{
let cell_clone = fv[mc_r + "_" + mc_c];
// let cell_clone = fv[mc_r + "_" + mc_c];
let cell_clone = JSON.parse(JSON.stringify(fv[mc_r + "_" + mc_c]));
delete cell_clone.v;
delete cell_clone.m;
@ -3265,7 +3266,8 @@ const menuButton = {
fv[mc_r + "_" + mc_c] = $.extend(true, {}, cell);
}
else{
let cell_clone = fv[mc_r + "_" + mc_c];
// let cell_clone = fv[mc_r + "_" + mc_c];
let cell_clone = JSON.parse(JSON.stringify(fv[mc_r + "_" + mc_c]));
delete cell_clone.v;
delete cell_clone.m;

34
src/controllers/sheetmanage.js

@ -822,26 +822,26 @@ const sheetmanage = {
else {
Store.luckysheetcurrentisPivotTable = false;
$("#luckysheet-modal-dialog-slider-pivot").hide();
}
// Store toolbar button width value
menuToolBarWidth();
// Store toolbar button width value
menuToolBarWidth();
luckysheetsizeauto();
luckysheetsizeauto();
//等待滚动条dom宽高加载完成后 初始化滚动位置
if(file["scrollLeft"] != null && file["scrollLeft"] > 0){
$("#luckysheet-scrollbar-x").scrollLeft(file["scrollLeft"]);
}
else{
$("#luckysheet-scrollbar-x").scrollLeft(0);
}
if(file["scrollTop"] != null && file["scrollTop"] > 0){
$("#luckysheet-scrollbar-y").scrollTop(file["scrollTop"]);
}
else{
$("#luckysheet-scrollbar-y").scrollTop(0);
}
//等待滚动条dom宽高加载完成后 初始化滚动位置
if(file["scrollLeft"] != null && file["scrollLeft"] > 0){
$("#luckysheet-scrollbar-x").scrollLeft(file["scrollLeft"]);
}
else{
$("#luckysheet-scrollbar-x").scrollLeft(0);
}
if(file["scrollTop"] != null && file["scrollTop"] > 0){
$("#luckysheet-scrollbar-y").scrollTop(file["scrollTop"]);
}
else{
$("#luckysheet-scrollbar-y").scrollTop(0);
}
// 此处已经渲染完成表格,应该挪到前面

4
src/css/luckysheet-core.css

@ -18,6 +18,10 @@
user-select: none;
}
.chart-moveable{
cursor: move;
}
.luckysheet {
position: absolute;
/* width: 100%;

24
src/expendPlugins/chart/plugin.js

@ -9,7 +9,7 @@ import { rowLocation, colLocation, mouseposition } from '../../global/location'
import { setluckysheet_scroll_status } from '../../methods/set'
import {
luckysheetMoveHighlightCell,
luckysheetMoveHighlightCell2,
luckysheetMoveHighlightCell2,
luckysheetMoveHighlightRange,
luckysheetMoveHighlightRange2,
luckysheetMoveEndCell
@ -132,6 +132,8 @@ function renderCharts(chartLists, isDemo) {
})
).appendTo($('.luckysheet-cell-main'))
setChartMoveableEffect($t);
$(`#${chart_id_c}`).children('.luckysheet-modal-dialog-content')[0].id = chart_id
let container = document.getElementById(chart_id_c)
@ -1217,6 +1219,8 @@ function createLuckyChart(width, height, left, top) {
delChart(chart_id)
})
setChartMoveableEffect($t);
// edit current chart
$(`#${chart_id}_c .luckysheet-modal-controll-update`).click(function (e) {
showChartSettingComponent()
@ -1329,6 +1333,24 @@ function createLuckyChart(width, height, left, top) {
})
}
/**
* 设置图表可拖动区域高亮效果鼠标经过可拖动区域时鼠标显示十字不可拖动区域显示箭头
* @param {JQuery} $container 图表的容器DIV
*/
function setChartMoveableEffect($container) {
$container.find('.luckysheet-modal-dialog-content').hover(function () {
$container.removeClass("chart-moveable");
}, function () {
$container.addClass("chart-moveable");
});
$container.hover(function () {
$container.addClass("chart-moveable");
}, function () {
$container.removeClass("chart-moveable");
});
}
// delete chart
function delChart(chart_id) {
// delete container

68
src/global/api.js

@ -2260,7 +2260,13 @@ export function getRangeArray(dimensional, options = {}) {
for(let r = r1; r <= r2; r++){
for(let c = c1; c <= c2; c++){
let cell = data[r][c];
dataArr.push(cell);
if(cell == null || cell.v == null){
dataArr.push(null);
}
else{
dataArr.push(cell.v);
}
}
}
}
@ -2270,7 +2276,13 @@ export function getRangeArray(dimensional, options = {}) {
for(let c = c1; c <= c2; c++){
let cell = data[r][c];
row.push(cell);
if(cell == null || cell.v == null){
row.push(null);
}
else{
row.push(cell.v);
}
}
dataArr.push(row);
@ -2732,18 +2744,9 @@ export function setSingleRangeFormat(attr, value, options = {}) {
range = formula.getcellrange(range)
}
let rowCount = range.row[1] - range.row[0] + 1,
columnCount = range.column[1] - range.column[0] + 1;
if (data.length !== rowCount || data[0].length !== columnCount) {
return tooltip.info('The data to be set does not match the selection', '')
}
for (let i = 0; i < rowCount; i++) {
for (let j = 0; j < columnCount; j++) {
let row = range.row[0] + i,
column = range.column[0] + j;
setCellFormat(row, column, attr, value, {order: order})
for (let r = range.row[0]; r <= range.row[1]; r++) {
for (let c = range.column[0]; c <= range.column[1]; c++) {
setCellFormat(r, c, attr, value, {order: order})
}
}
}
@ -2766,10 +2769,34 @@ export function setRangeFormat(attr, value, options = {}) {
success
} = {...options}
if (range instanceof Array) {
for (let i = 0; i < range.length; i++) {
setSingleRangeFormat(range[i])
if(getObjType(range) == 'string'){
if(!formula.iscelldata(range)){
return tooltip.info("The range parameter is invalid.", "");
}
let cellrange = formula.getcellrange(range);
range = [{
"row": cellrange.row,
"column": cellrange.column
}]
}
else if(getObjType(range) == 'object'){
if(range.row == null || range.column == null){
return tooltip.info("The range parameter is invalid.", "");
}
range = [{
"row": range.row,
"column": range.column
}];
}
if(getObjType(range) != 'array'){
return tooltip.info("The range parameter is invalid.", "");
}
for (let i = 0; i < range.length; i++) {
setSingleRangeFormat(attr, value, { range: range[i], order: order });
}
if (success && typeof success === 'function') {
@ -3163,7 +3190,8 @@ export function cancelRangeMerge(options = {}) {
fv[mc_r + "_" + mc_c] = $.extend(true, {}, cell);
}
else{
let cell_clone = fv[mc_r + "_" + mc_c];
// let cell_clone = fv[mc_r + "_" + mc_c];
let cell_clone = JSON.parse(JSON.stringify(fv[mc_r + "_" + mc_c]));
delete cell_clone.v;
delete cell_clone.m;
@ -4764,6 +4792,10 @@ export function setSheetDelete(options = {}) {
return tooltip.info("The order parameter is invalid.", "");
}
if(Store.luckysheetfile.length === 1){
return tooltip.info(locale().sheetconfig.noMoreSheet, "");
}
sheetmanage.deleteSheet(file.index);
setTimeout(() => {

24
src/global/formula.js

@ -380,7 +380,7 @@ const luckysheetformula = {
return offsetRange;
},
parseDatetoNum: function (date) { //函数中获取到时间格式或者数字形式统一转化为数字进行运算
parseDatetoNum: function (date) { //函数中获取到时间格式或者数字形式统一转化为数字进行运算
let _this = this;
if (typeof (date) == "object" && typeof date.v == "number") {
@ -1263,6 +1263,17 @@ const luckysheetformula = {
let isPrevInline = isInlineStringCell(curv);
let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.substr(0, 5) == "<span");
let isCopyVal = false;
if(!isCurInline && inputText && inputText.length > 0) {
let splitArr = inputText.replace(/\r\n/g, "_x000D_").replace(/&#13;&#10;/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_").split("_x000D_");
if(splitArr.length > 1) {
isCopyVal = true;
isCurInline = true;
inputText = splitArr.join('\r\n');
}
}
if (!value && !isCurInline && isPrevInline) {
delete curv.ct.s;
curv.ct.t = "g";
@ -1284,6 +1295,13 @@ const luckysheetformula = {
curv.ct.t = "inlineStr";
curv.ct.s = convertSpanToShareString($input.find("span"));
if(isCopyVal) {
curv.ct.s = [
{
v: inputText,
}
];
}
}
// API, we get value from user
@ -1448,7 +1466,7 @@ const luckysheetformula = {
delete curv.f;
delete curv.spl;
if (curv.qp == 1 && ('' + value).substr(0, 1) != "'") {//if quotePrefix is 1, cell is force string, cell clear quotePrefix when it is updated
if (curv.qp == 1 && ('' + value).substr(0, 1) != "'") {//if quotePrefix is 1, cell is force string, cell clear quotePrefix when it is updated
curv.qp = 0;
if (curv.ct != null) {
curv.ct.fa = "General";
@ -5269,7 +5287,7 @@ const luckysheetformula = {
// if(key in updateValueOjects){
// updateValueArray.push(item);
// }
// });
// });
// }
}

29
src/global/getRowlen.js

@ -314,7 +314,7 @@ function getCellTextInfo(cell , ctx, option){
let scfontset = luckysheetfontformat(shareCell);
let fc = shareCell.fc, cl=shareCell.cl,un = shareCell.un, v = shareCell.v, fs=shareCell.fs;
v = v.replace(/\r\n/g, "_x000D_").replace(/&#13;&#10;/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_");
let splitArr = v.split("_x000D_"), preNewValue=null;
let splitArr = v.split("_x000D_");
for(let x=0;x<splitArr.length;x++){
let newValue = splitArr[x];
@ -346,7 +346,7 @@ function getCellTextInfo(cell , ctx, option){
}
if(x!=splitArr.length-1 && preNewValue!="" ){
if(x!=splitArr.length-1 ){
inlineStringArr.push({
fontset:scfontset,
fc:fc==null?"#000":fc,
@ -359,8 +359,6 @@ function getCellTextInfo(cell , ctx, option){
}
}
preNewValue = newValue;
}
similarIndex++;
@ -903,10 +901,6 @@ function getCellTextInfo(cell , ctx, option){
let height = textWidth * Math.sin(rt*Math.PI/180) + textHeight * Math.cos(rt*Math.PI/180);//consider text box wdith and line height
let lastWord = str.substr(str.length-1,1);
let isSpace = false;
if(checkWordByteLength(lastWord)===1 && lastWord !== ' ' && !/^.$/.test(lastWord) && !/^.$/u.test(lastWord)) {
isSpace = lastWord.replace(/\r\n/g, "_x000D_").replace(/&#13;&#10;/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_") === '_x000D_';
}
if(lastWord==" " || checkWordByteLength(lastWord)==2){
if(preMeasureText!=null){
spaceOrTwoByte = {
@ -1058,25 +1052,6 @@ function getCellTextInfo(cell , ctx, option){
splitIndex +=1;
}
}
else if(isSpace && text_all_split[splitIndex]!=null && i!= value.length) {
spaceOrTwoByte = null;
anchor = i;
text_all_split[splitIndex].push({
content:str,
style:fontset,
width:preTextWidth,
height:preTextHeight,
left:0,
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
}
else if(i== value.length){
if(text_all_split[splitIndex]==null){
text_all_split[splitIndex]= [];

15
src/index.html

@ -76,12 +76,12 @@
options = {
container: 'luckysheet',
lang: lang,
pager: {
pageIndex: 1,
pageSize: 10,
total: 50,
selectOption: [10, 20]
},
// pager: {
// pageIndex: 1,
// pageSize: 10,
// total: 50,
// selectOption: [10, 20]
// },
forceCalculation:false,
plugins: ['chart'],
fontList:[
@ -99,6 +99,9 @@
}
],
hook:{
cellDragStop: function (cell, postion, sheetFile, moveState, ctx, event) {
console.info(cell, postion, sheetFile, ctx, event);
},
rowTitleCellRenderBefore:function(rowNum,postion,ctx){
// console.log(rowNum);
},

Loading…
Cancel
Save