diff --git a/docs/guide/api.md b/docs/guide/api.md index 434c4d1..d2f6f9a 100644 --- a/docs/guide/api.md +++ b/docs/guide/api.md @@ -2076,9 +2076,6 @@ Use note: ### getConfig([setting]) -[todo] - - - **Parameter**: - {PlainObject} [setting]: optional parameters @@ -2092,9 +2089,6 @@ Use note: ### setConfig([setting]) -[todo] - - - **Parameter**: - {PlainObject} [setting]: optional parameters @@ -2105,6 +2099,19 @@ Use note: Quickly set the current worksheet config configuration +------------ +### updataSheet([setting]) + +- **参数**: + + - {PlainObject} [setting]: optional parameters + + {Array} [data]: Worksheet Configuration + + {Function} [success]: callback function for the end of the operation + +- **说明**: + + Update the corresponding sheet according to the set sheet configuration + ------------ ### setSheetAdd([setting]) diff --git a/docs/zh/guide/api.md b/docs/zh/guide/api.md index c7ba4db..2ed04e6 100644 --- a/docs/zh/guide/api.md +++ b/docs/zh/guide/api.md @@ -2062,7 +2062,20 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开 快捷设置指定工作表config配置 ------------ +### updataSheet([setting]) +- **参数**: + + - {PlainObject} [setting]: 可选参数 + + {Array} [data]: 需要更新的工作表配置,参考create这个API的option.data + + {Function} [success]: 操作结束的回调函数 + +- **说明**: + + 根据所传的工作表配置,更新相应的工作表 + + +------------ ### setSheetAdd([setting]) - **参数**: diff --git a/src/global/api.js b/src/global/api.js index bce289e..9844d1f 100644 --- a/src/global/api.js +++ b/src/global/api.js @@ -21,7 +21,7 @@ import { isRealNull, valueIsError, isRealNum, isEditMode, hasPartMC } from "./va import { isdatetime, diff } from "./datecontroll"; import { getBorderInfoCompute } from './border'; import { luckysheetDrawMain } from './draw'; - +import pivotTable from '../controllers/pivotTable'; import server from "../controllers/server"; import menuButton from '../controllers/menuButton'; import selection from "../controllers/selection"; @@ -6615,6 +6615,53 @@ export function refreshFormula (success) { }) } +/** + * 更新sheet数据 + * @param {Array} data 工作簿配置,可以包含多个表 + * @param {Object} options 可选参数 + * @param {Function} options.success 操作结束的回调函数 + * + */ +export function updataSheet (options = {}) { + let {data, success} = options + let files = Store.luckysheetfile + for (let i = 0; i < data.length; i++) { + for (let j = 0; j < files.length; j++) { + if (files[j].index === data[i].index) { + files[j] = data[i] + } + } + } + let file = files[sheetmanage.getSheetIndex(Store.currentSheetIndex)], + sheetData = sheetmanage.buildGridData(file); + file.data = sheetData + + if (!!file.isPivotTable) { + Store.luckysheetcurrentisPivotTable = true; + if (!isPivotInitial) { + pivotTable.changePivotTable(index); + } + } + else{ + Store.luckysheetcurrentisPivotTable = false; + $("#luckysheet-modal-dialog-slider-pivot").hide(); + luckysheetsizeauto(false); + } + sheetmanage.mergeCalculation(file["index"]); + sheetmanage.setSheetParam(); + setTimeout(function () { + sheetmanage.showSheet(); + sheetmanage.restoreCache(); + formula.execFunctionGroupForce(luckysheetConfigsetting.forceCalculation); + sheetmanage.restoreSheetAll(Store.currentSheetIndex); + luckysheetrefreshgrid(); + if (success && typeof success === 'function') { + success(); + } + }, 1); + server.saveParam("shs", null, Store.currentSheetIndex); +} + /** * 刷新状态栏的状态 * @param {Array} data 操作数据 diff --git a/src/global/format.js b/src/global/format.js index 1fed643..1e46277 100644 --- a/src/global/format.js +++ b/src/global/format.js @@ -1764,7 +1764,18 @@ export function genarate(value) {//万 单位格式增加!!! return null; } - if(value.toString().substr(0, 1) === "'"){ + if (/^-?[0-9]{1,}[,][0-9]{3}(.[0-9]{1,2})?$/.test(value)) { // 表述金额的字符串,如:12,000.00 或者 -12,000.00 + m = value + v = Number(value.split('.')[0].replace(',', '')) + let fa = "#,##0" + if (value.split('.')[1]) { + fa = "#,##0." + for (let i = 0; i < value.split('.')[1].length; i++) { + fa += 0 + } + } + ct= {fa, t: "n"} + } else if(value.toString().substr(0, 1) === "'"){ m = value.toString().substr(1); ct = { "fa": "@", "t": "s" }; }