Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
chore(core): remove unused module (#34)
Dushusircdd7dfc3eacf
diff --git a/.github/contributing-zh.md b/.github/contributing-zh.mdindex 34c45af8af..a0a6082f2c 100644--- a/.github/contributing-zh.md+++ b/.github/contributing-zh.md@@ -118,6 +118,29 @@ npm run cleanpnpm install```+### PR流程++1. 新建分支,进行开发+```sh+git checkout -b my-dev+```+2. 提交分支+```sh+git pull origin my-dev --rebase+git add .+git commit -m "new"+git push origin my-dev+```+3. commit中间执行rebase,不定期从dev同步最新代码到你的分支+```sh+git rebase dev+```+4. [可选]如果有冲突,解决冲突并继续+```sh+git add .+git rebase --continue+```+## 风格指南我们严格参照 [Google 开源项目风格指南 - TypeScript 风格指南](https://zh-google-styleguide.readthedocs.io/en/latest/google-typescript-styleguide/contents/#),本文档的风格指南,主要列出不同的地方和需要重点强调的部分。@@ -892,7 +915,7 @@ export class AlternatingColorsPlugin extends Plugin {一个简单的设置 worksheet 切换按钮 color 的 API [setTabColor](../packages/core/src/Sheets/Domain/Worksheet.ts) 的案例-1. 在[ACTION_NAMES](../packages/core/src/Const/ACTION_NAMES.ts)中预先定义一个`Action`名称 `SET_TAB_COLOR_ACTION`+1. 在[ACTION_NAMES](../packages/core/src/Types/Const/ACTION_NAMES.ts)中预先定义一个`Action`名称 `SET_TAB_COLOR_ACTION`2. 将 `Action` 注册到[CommandManager](../packages/core/src/Command/RegisterAction.ts)diff --git a/packages/core/src/Basics/Context.ts b/packages/core/src/Basics/Context.tsindex 213c74b42f..ae3814a0aa 100644--- a/packages/core/src/Basics/Context.ts+++ b/packages/core/src/Basics/Context.ts@@ -1,4 +1,4 @@-import { IUniverData } from '../Interfaces/IUniverData';+import { IUniverData } from '../Types/Interfaces/IUniverData';import { Locale } from '../Shared/Locale';import { Tools } from '../Shared/Tools';import { ContextBase } from './ContextBase';diff --git a/packages/core/src/Basics/DocContext.ts b/packages/core/src/Basics/DocContext.tsindex 21d6f9054b..1714f7d575 100644--- a/packages/core/src/Basics/DocContext.ts+++ b/packages/core/src/Basics/DocContext.ts@@ -1,4 +1,4 @@-import { IDocumentData } from '../Interfaces';+import { IDocumentData } from '../Types/Interfaces';import { ContextBase } from './ContextBase';import { DocumentModel } from '../Docs/Domain/DocumentModel';diff --git a/packages/core/src/Basics/SheetContext.ts b/packages/core/src/Basics/SheetContext.tsindex 11c388ee9b..b8127f3449 100644--- a/packages/core/src/Basics/SheetContext.ts+++ b/packages/core/src/Basics/SheetContext.ts@@ -5,7 +5,7 @@ import { Observable } from '../Observer';import { GenName, PropsFrom } from '../Shared';import { Univer } from './Univer';import { WorkBookObserver } from './WorkBookObserver';-import { IWorkbookConfig } from '../Interfaces';+import { IWorkbookConfig } from '../Types/Interfaces';/*** Core context, mount important instances, managersdiff --git a/packages/core/src/Basics/SlideContext.ts b/packages/core/src/Basics/SlideContext.tsindex 6dd52c8338..4155404f69 100644--- a/packages/core/src/Basics/SlideContext.ts+++ b/packages/core/src/Basics/SlideContext.ts@@ -1,4 +1,4 @@-import { ISlideData } from '../Interfaces/ISlideData';+import { ISlideData } from '../Types/Interfaces/ISlideData';import { SlideModel } from '../Slides/Domain/SlideModel';import { ContextBase } from './ContextBase';diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.tsindex dbe622c310..8c445d16ed 100644--- a/packages/core/src/Basics/Univer.ts+++ b/packages/core/src/Basics/Univer.ts@@ -4,7 +4,7 @@ import { UniverSlide } from './UniverSlide';import { Nullable } from '../Shared';import { Context } from './Context';import { Plugin } from '../Plugin';-import { IUniverData } from '../Interfaces';+import { IUniverData } from '../Types/Interfaces';import { UniverObserverImpl } from './UniverObserverImpl';export class Univer {diff --git a/packages/core/src/Basics/UniverDoc.ts b/packages/core/src/Basics/UniverDoc.tsindex 1458fcc88d..fa237c5025 100644--- a/packages/core/src/Basics/UniverDoc.ts+++ b/packages/core/src/Basics/UniverDoc.ts@@ -1,4 +1,4 @@-import { IDocumentData } from '../Interfaces';+import { IDocumentData } from '../Types/Interfaces';import { Plugin } from '../Plugin';import { IOHttp, IOHttpConfig, Logger } from '../Shared';import { DocContext } from './DocContext';diff --git a/packages/core/src/Basics/UniverObserver.ts b/packages/core/src/Basics/UniverObserver.tsindex 81f8895329..4b31f292b1 100644--- a/packages/core/src/Basics/UniverObserver.ts+++ b/packages/core/src/Basics/UniverObserver.ts@@ -1,10 +1,10 @@-import { UIObserver } from '../Interfaces';-import { Observable } from '../Observer/Observable';--export type UniverObserver<T> = {- onUIChangeObservable: Observable<UIObserver<T>>;- onUIDidMountObservable: Observable<boolean>;- onAfterChangeUISkinObservable: Observable<string>;- onAfterChangeUILocaleObservable: Observable<string>;- onViewComponentFocusChange: Observable<void>;-};+import { UIObserver } from '../Types/Interfaces';+import { Observable } from '../Observer/Observable';++export type UniverObserver<T> = {+ onUIChangeObservable: Observable<UIObserver<T>>;+ onUIDidMountObservable: Observable<boolean>;+ onAfterChangeUISkinObservable: Observable<string>;+ onAfterChangeUILocaleObservable: Observable<string>;+ onViewComponentFocusChange: Observable<void>;+};diff --git a/packages/core/src/Basics/UniverSheet.ts b/packages/core/src/Basics/UniverSheet.tsindex d117433f96..8f94bf7b8d 100644--- a/packages/core/src/Basics/UniverSheet.ts+++ b/packages/core/src/Basics/UniverSheet.ts@@ -1,5 +1,5 @@import { Workbook, ColorBuilder } from '../Sheets/Domain';-import { IWorkbookConfig } from '../Interfaces';+import { IWorkbookConfig } from '../Types/Interfaces';import { BasePlugin, Plugin } from '../Plugin';import { IOHttp, IOHttpConfig, Logger } from '../Shared';import { SheetContext } from './SheetContext';diff --git a/packages/core/src/Basics/UniverSlide.ts b/packages/core/src/Basics/UniverSlide.tsindex b9d2b3609e..8f2d54cfb9 100644--- a/packages/core/src/Basics/UniverSlide.ts+++ b/packages/core/src/Basics/UniverSlide.ts@@ -1,4 +1,4 @@-import { ISlideData } from '../Interfaces';+import { ISlideData } from '../Types/Interfaces';import { Plugin } from '../Plugin';import { IOHttp, IOHttpConfig, Logger } from '../Shared';import { SlideContext } from './SlideContext';diff --git a/packages/core/src/Command/RegisterAction.ts b/packages/core/src/Command/RegisterAction.tsindex c7f63ad823..80920bf7fe 100644--- a/packages/core/src/Command/RegisterAction.ts+++ b/packages/core/src/Command/RegisterAction.ts@@ -39,7 +39,7 @@ import {SetZoomRatioAction,} from '../Sheets/Action';import { CommandManager } from './CommandManager';-import { DOC_ACTION_NAMES } from '../Const/DOC_ACTION_NAMES';+import { DOC_ACTION_NAMES } from '../Types/Const/DOC_ACTION_NAMES';import {InsertTextAction,DeleteTextAction,diff --git a/packages/core/src/Docs/Action/ActionDataInterface.ts b/packages/core/src/Docs/Action/ActionDataInterface.tsindex eb81733c8c..5b50de6d8b 100644--- a/packages/core/src/Docs/Action/ActionDataInterface.ts+++ b/packages/core/src/Docs/Action/ActionDataInterface.ts@@ -1,5 +1,5 @@import { IDocActionData } from '../../Command/DocActionBase';-import { IDocumentBody } from '../../Interfaces/IDocumentData';+import { IDocumentBody } from '../../Types/Interfaces/IDocumentData';import { Nullable } from '../../Shared';import { UpdateDocsAttributeType } from '../../Shared/CommandEnum';diff --git a/packages/core/src/Docs/Action/DeleteAction.ts b/packages/core/src/Docs/Action/DeleteAction.tsindex d2f64944a4..3f06875062 100644--- a/packages/core/src/Docs/Action/DeleteAction.ts+++ b/packages/core/src/Docs/Action/DeleteAction.ts@@ -1,8 +1,8 @@import { DocActionBase } from '../../Command/DocActionBase';import { ActionObservers, ActionType, CommandManager, CommandUnit, CommonParameter } from '../../Command';-import { DOC_ACTION_NAMES } from '../../Const/DOC_ACTION_NAMES';-import { IDocumentBody } from '../../Interfaces';+import { DOC_ACTION_NAMES } from '../../Types/Const/DOC_ACTION_NAMES';+import { IDocumentBody } from '../../Types/Interfaces';import { DeleteApply } from '../Apply/DeleteApply';import { InsertApply } from '../Apply/InsertApply';import { IDeleteActionData, IInsertActionData } from './ActionDataInterface';diff --git a/packages/core/src/Docs/Action/InsertAction.ts b/packages/core/src/Docs/Action/InsertAction.tsindex e1b14cc28d..c823de809d 100644--- a/packages/core/src/Docs/Action/InsertAction.ts+++ b/packages/core/src/Docs/Action/InsertAction.ts@@ -1,6 +1,6 @@import { DocActionBase } from '../../Command/DocActionBase';import { ActionObservers, ActionType, CommandManager, CommandUnit, CommonParameter } from '../../Command';-import { DOC_ACTION_NAMES } from '../../Const/DOC_ACTION_NAMES';+import { DOC_ACTION_NAMES } from '../../Types/Const/DOC_ACTION_NAMES';import { InsertApply } from '../Apply/InsertApply';import { DeleteApply } from '../Apply/DeleteApply';import { IInsertActionData, IDeleteActionData } from './ActionDataInterface';diff --git a/packages/core/src/Docs/Action/RetainAction.ts b/packages/core/src/Docs/Action/RetainAction.tsindex d6da8486e2..af3337f43b 100644--- a/packages/core/src/Docs/Action/RetainAction.ts+++ b/packages/core/src/Docs/Action/RetainAction.ts@@ -3,7 +3,7 @@ import { ActionObservers, CommandManager, CommandUnit, CommonParameter } from '.import { IRetainActionData } from './ActionDataInterface';import { UpdateDocsAttributeType } from '../../Shared/CommandEnum';import { UpdateAttributeApply } from '../Apply/UpdateAttributeApply';-import { IDocumentBody } from '../../Interfaces';+import { IDocumentBody } from '../../Types/Interfaces';import { Nullable } from '../../Shared';export class RetainAction extends DocActionBase<IRetainActionData, IRetainActionData> {diff --git a/packages/core/src/Docs/Apply/DeleteApply.ts b/packages/core/src/Docs/Apply/DeleteApply.tsindex 3e84839b26..1a4e6ad78f 100644--- a/packages/core/src/Docs/Apply/DeleteApply.ts+++ b/packages/core/src/Docs/Apply/DeleteApply.ts@@ -1,7 +1,6 @@import { DocumentModel } from '../Domain/DocumentModel';import { deleteContent, getDocsUpdateBody } from '../../Shared/Common';-import { IDocumentBody } from '../../Interfaces/IDocumentData';-import { deleteCustomBlocks, deleteCustomRanges, deleteParagraphs, deleteSectionBreaks, deleteTables, deleteTextRuns } from './Common';+import { IDocumentBody } from '../../Types/Interfaces/IDocumentData';export function DeleteApply(document: DocumentModel, textLength: number, currentIndex: number, segmentId?: string) {const doc = document.snapshot;diff --git a/packages/core/src/Docs/Apply/InsertApply.ts b/packages/core/src/Docs/Apply/InsertApply.tsindex 158da15e6d..3066732aa2 100644--- a/packages/core/src/Docs/Apply/InsertApply.ts+++ b/packages/core/src/Docs/Apply/InsertApply.ts@@ -1,4 +1,4 @@-import { IDocumentBody } from '../../Interfaces/IDocumentData';+import { IDocumentBody } from '../../Types/Interfaces/IDocumentData';import { DocumentModel } from '../Domain/DocumentModel';import { getDocsUpdateBody } from '../../Shared/Common';import { insertCustomBlocks, insertCustomRanges, insertParagraphs, insertSectionBreaks, insertTables, insertTextRuns } from './Common';diff --git a/packages/core/src/Docs/Domain/DocumentBodyModel.ts b/packages/core/src/Docs/Domain/DocumentBodyModel.tsindex 77964bc1c0..6488042b29 100644--- a/packages/core/src/Docs/Domain/DocumentBodyModel.ts+++ b/packages/core/src/Docs/Domain/DocumentBodyModel.ts@@ -1,4 +1,4 @@-import { IDocumentBody, ITextRun } from '../../Interfaces/IDocumentData';+import { IDocumentBody, ITextRun } from '../../Types/Interfaces/IDocumentData';import { Nullable } from '../../Shared/Types';import { DataStreamTreeNode } from './DataStreamTreeNode';diff --git a/packages/core/src/Docs/Domain/DocumentModel.ts b/packages/core/src/Docs/Domain/DocumentModel.tsindex 64a3d52158..7dc88f9b81 100644--- a/packages/core/src/Docs/Domain/DocumentModel.ts+++ b/packages/core/src/Docs/Domain/DocumentModel.ts@@ -4,12 +4,12 @@ import {CommonParameterAttribute,IDocumentBody,IDocumentData,-} from '../../Interfaces/IDocumentData';-import { ITextSelectionRange } from '../../Interfaces/ISelectionData';-import { DOC_ACTION_NAMES } from '../../Const/DOC_ACTION_NAMES';+} from '../../Types/Interfaces/IDocumentData';+import { ITextSelectionRange } from '../../Types/Interfaces/ISelectionData';+import { DOC_ACTION_NAMES } from '../../Types/Const/DOC_ACTION_NAMES';import { Tools, getTextIndexByCursor } from '../../Shared';import { DocumentBodyModel } from './DocumentBodyModel';-import { DEFAULT_DOC } from '../../Const';+import { DEFAULT_DOC } from '../../Types/Const';interface IDrawingUpdateConfig {left: number;diff --git a/packages/core/src/Hook/Hook.ts b/packages/core/src/Hook/Hook.tsdeleted file mode 100644index 52450fc439..0000000000--- a/packages/core/src/Hook/Hook.ts+++ /dev/null@@ -1,26 +0,0 @@-import { Nullable } from '../Shared';--export type HookResponse<T, R> = (data: T) => R;--export class Hook<T = void, R = void> {- private _response: Nullable<HookResponse<T, R>>;-- constructor(response: Nullable<HookResponse<T, R>>) {- this._response = response;- }-- invoke(data: T, defaultValue: R): R {- if (this._response) {- return this._response(data);- }- return defaultValue;- }-- getResponse(): Nullable<HookResponse<T, R>> {- return this._response;- }-- setResponse(response: HookResponse<T, R>): void {- this._response = response;- }-}diff --git a/packages/core/src/Hook/WorkBookHook.ts b/packages/core/src/Hook/WorkBookHook.tsdeleted file mode 100644index 01edc7518f..0000000000--- a/packages/core/src/Hook/WorkBookHook.ts+++ /dev/null@@ -1,5 +0,0 @@-import { Hook } from './Hook';--export class WorkSheetHook {- setSheetOrder = new Hook<{ sheetId: string; order: number }, boolean>();-}diff --git a/packages/core/src/Hook/WorkSheetHook.ts b/packages/core/src/Hook/WorkSheetHook.tsdeleted file mode 100644index 3d3b7aa04d..0000000000--- a/packages/core/src/Hook/WorkSheetHook.ts+++ /dev/null@@ -1,12 +0,0 @@-// import { Hook } from './Hook';-// import {IWorksheetConfig} from "../Interfaces";--// export class WorkSheetHook {-// setNameHook = new Hook<string, boolean>();--// constructor(sheet: IWorksheetConfig) {-// if (sheet.hooks.setNameHook) {-// this.setNameHook.setResponse(sheet.hooks.setNameHook);-// }-// }-// }diff --git a/packages/core/src/Server/ServerSocket.ts b/packages/core/src/Server/ServerSocket.tsindex a38669f7af..b2b00d0eae 100644--- a/packages/core/src/Server/ServerSocket.ts+++ b/packages/core/src/Server/ServerSocket.ts@@ -1,6 +1,6 @@import { ISheetActionData } from '../Command';import { ICreatable, createIdentifier } from '../DI';-import { IWorkbookConfig, IWorksheetConfig } from '../Interfaces';+import { IWorkbookConfig, IWorksheetConfig } from '../Types/Interfaces';import { IOSocket, IOSocketListenType } from '../Shared';import { MessageQueue } from './MessageQueue';import { IOServerMessage, IOServerReceive, ServerBase } from './ServerBase';diff --git a/packages/core/src/Shared/Common.ts b/packages/core/src/Shared/Common.tsindex 7911d6bfd3..6804f6c081 100644--- a/packages/core/src/Shared/Common.ts+++ b/packages/core/src/Shared/Common.ts@@ -1,564 +1,564 @@-import { Tools } from './Tools';-import { Nullable } from '.';-import {- ICellInfo,- ISelection,- ICellData,- IColorStyle,- IDocumentData,- IStyleData,-} from '../Interfaces';-import { ColorBuilder } from '../Sheets/Domain';-import {- BaselineOffset,- TextDirection,- HorizontalAlign,- VerticalAlign,- WrapStrategy,- BorderStyleTypes,-} from '../Enum';--export function makeCellToSelection(- cellInfo: Nullable<ICellInfo>-): Nullable<ISelection> {- if (!cellInfo) {- return;- }- let { row, column, startY, endY, startX, endX, isMerged, mergeInfo } = cellInfo;- let startRow = row;- let startColumn = column;- let endRow = row;- let endColumn = column;- if (isMerged && mergeInfo) {- const {- startRow: mergeStartRow,- startColumn: mergeStartColumn,- endRow: mergeEndRow,- endColumn: mergeEndColumn,- startY: mergeStartY,- endY: mergeEndY,- startX: mergeStartX,- endX: mergeEndX,- } = mergeInfo;- startRow = mergeStartRow;- startColumn = mergeStartColumn;- endRow = mergeEndRow;- endColumn = mergeEndColumn;- startY = mergeStartY;- endY = mergeEndY;- startX = mergeStartX;- endX = mergeEndX;- }-- return {- startRow,- startColumn,- endRow,- endColumn,- startY,- endY,- startX,- endX,- };-}--export function isEmptyCell(cell: Nullable<ICellData>) {- if (!cell) {- return true;- }-- const content = cell?.m || '';- if (content.length === 0 && !cell.p) {- return true;- }- return false;-}--export function getColorStyle(color: Nullable<IColorStyle>): Nullable<string> {- if (color) {- if (color.rgb) {- return color.rgb;- }- if (color.th) {- return new ColorBuilder()- .setThemeColor(color.th)- .asThemeColor()- .asRgbColor()- .getCssString();- }- }- return null;-}--export function isFormulaString(value: any): boolean {- return Tools.isString(value) && value.indexOf('=') === 0 && value.length > 1;-}--/**- * move to Styles.getStyleByCell- */-// export function getStyle(-// styles: Nullable<Styles>,-// cell: Nullable<ICellData>-// ): Nullable<IStyleData> {-// let style;-// if (cell && Tools.isObject(cell.s)) {-// style = cell.s as IStyleData;-// } else {-// style = cell?.s && styles?.get(cell.s);-// }--// return style as IStyleData;-// }--/**- * Convert rich text json to DOM- * @param p- */-export function handleJsonToDom(p: IDocumentData): string {- // let span = '';- // // let span = `<span id="${p.id}">`;- // if (p.body?.blockElements) {- // for (let k in p.body.blockElements) {- // const section = p.body.blockElements[k];- // if (- // section.blockType !== BlockType.PARAGRAPH &&- // section.blockType !== BlockType.SECTION_BREAK- // ) {- // continue;- // }- // if (section.blockType === BlockType.PARAGRAPH) {- // for (let i in section.paragraph) {- // const element = section.paragraph[i];- // for (let j in element) {- // const item = element[j];- // if (item.et === ParagraphElementType.TEXT_RUN) {- // let style = `display:inline-block;${handleStyleToString(- // item.tr.ts- // )}`;- // span += `<span id='${item.eId}' ${- // style.length ? `style="${style}"` : ''- // } >${item.tr.ct}</span>`;- // }- // }- // }- // }- // // else if (section.blockType === BlockType.SECTION_BREAK) {- // // span += '<br/>';- // // }- // }- // }-- // // span += '</span>';- // return span;- return '';-}--/**- * transform style object to string- * @param style- * @returns- */-export function handleStyleToString(style: IStyleData, isCell: boolean = false) {- let str = '';- const styleMap = new Map([- [- 'ff',- () => {- if (style.ff) {- str += `font-family: ${style.ff}; `;- }- },- ],- [- 'fs',- () => {- if (style.fs) {- let fs = style.fs;-- // subscript / superscript, Font size for superscripts and subscripts is halved- if (style.va) {- fs /= 2;- }- str += `font-size: ${fs}pt; `;- }-- // const fs = isCss ? `${style.fs}px` : `${pxToPt(style.fs || 14)}pt`;- // str += `font-size: ${fs}; `;- },- ],- [- 'it',- () => {- if (style.it) {- str += `font-style: italic; `;- } else {- str += `font-style: normal; `;- }- },- ],- [- 'bl',- () => {- if (style.bl) {- str += `font-weight: bold; `;- } else {- str += `font-weight: normal; `;- }- },- ],- [- 'ul',- () => {- if (style.ul?.s) {- // If there are existing lines, add new lines- if (str.indexOf('text-decoration-line') > -1) {- str = str.replace(- /(?<=text-decoration-line:.*)\b(?=;)/g,- ' underline'- );- } else {- str += `text-decoration-line: underline; `;- }- if (style.ul.cl && str.indexOf('text-decoration-color') === -1) {- str += `text-decoration-color: ${getColorStyle(- style.ul.cl- )}; `;- }- if (style.ul.t && str.indexOf('text-decoration-style') === -1) {- str += `text-decoration-style: ${style.ul.t} `;- }- }- },- ],- [- 'st',- () => {- if (style.st?.s) {- if (str.indexOf('text-decoration-line') > -1) {- str = str.replace(- /(?<=text-decoration-line:.*)\b(?=;)/g,- ' line-through'- );- } else {- str += `text-decoration-line: line-through; `;- }- if (style.st.cl && str.indexOf('text-decoration-color') === -1) {- str += `text-decoration-color: ${getColorStyle(- style.st.cl- )}; `;- }- if (style.st.t && str.indexOf('text-decoration-style') === -1) {- str += `text-decoration-style: ${style.st.t} `;- }- }- },- ],- [- 'ol',- () => {- if (style.ol?.s) {- if (str.indexOf('text-decoration-line') > -1) {- str = str.replace(- /(?<=text-decoration-line:.*)\b(?=;)/g,- ' overline'- );- } else {- str += `text-decoration-line: overline; `;- }- if (style.ol.cl && str.indexOf('text-decoration-color') === -1) {- str += `text-decoration-color: ${getColorStyle(- style.ol.cl- )}; `;- }- if (style.ol.t && str.indexOf('text-decoration-style') === -1) {- str += `text-decoration-style: ${style.ol.t} `;- }- }- },- ],- [- 'bg',- () => {- str += `background: ${getColorStyle(style.bg)}; `;- },- ],- [- 'bd',- () => {- if (style.bd?.b) {- str += `border-bottom: ${getBorderStyle(style.bd?.b.s)} ${- getColorStyle(style.bd.b.cl) ?? ''- }; `;- }- if (style.bd?.t) {- str += `border-top: ${getBorderStyle(style.bd?.t.s)} ${- getColorStyle(style.bd.t.cl) ?? ''- }; `;- }- if (style.bd?.r) {- str += `border-right: ${getBorderStyle(style.bd?.r.s)} ${- getColorStyle(style.bd.r.cl) ?? ''- }; `;- }- if (style.bd?.l) {- str += `border-left: ${getBorderStyle(style.bd?.l.s)} ${- getColorStyle(style.bd.l.cl) ?? ''- }; `;- }- },- ],- [- 'cl',- () => {- str += `color: ${getColorStyle(style.cl)}; `;- },- ],- [- 'va',- () => {- if (style.va === BaselineOffset.NORMAL) {- str += `vertical-align: baseline; `;- } else if (style.va === BaselineOffset.SUBSCRIPT) {- str += `vertical-align: sub; `;- } else {- str += `vertical-align: super; `;- }- },- ],- [- 'td',- () => {- if (style.td === TextDirection.UNSPECIFIED) {- str += `direction: inherit; `;- } else if (style.td === TextDirection.LEFT_TO_RIGHT) {- str += `direction: ltr; `;- } else {- str += `direction: rtl; `;- }- },- ],- [- 'tr',- () => {- str += `data-rotate: (${style.tr?.a}deg${- style.tr?.v ? ` ,${style.tr?.v}` : ''- });`;- },- ],- [- 'ht',- () => {- if (style.ht === HorizontalAlign.UNSPECIFIED) {- str += `text-align: inherit; `;- } else if (style.ht === HorizontalAlign.LEFT) {- str += `text-align: left; `;- } else if (style.ht === HorizontalAlign.RIGHT) {- str += `text-align: right; `;- } else if (style.ht === HorizontalAlign.CENTER) {- str += `text-align: center; `;- } else {- str += `text-align: justify; `;- }- },- ],- [- 'vt',- () => {- if (style.vt === VerticalAlign.UNSPECIFIED) {- str += `vertical-align: inherit; `;- } else if (style.vt === VerticalAlign.BOTTOM) {- str += `vertical-align: bottom; `;- } else if (style.vt === VerticalAlign.TOP) {- str += `vertical-align: top; `;- } else {- str += `vertical-align: middle; `;- }- },- ],- [- 'tb',- () => {- if (style.tb === WrapStrategy.CLIP) {- str += `text-overflow: clip; `;- } else if (style.tb === WrapStrategy.OVERFLOW) {- str += `text-break: overflow; `;- } else if (style.tb === WrapStrategy.WRAP) {- str += `word-wrap: break-word; word-break: normal; `;- }- },- ],- [- 'pd',- () => {- // let b = '';- // let t = '';- // let l = '';- // let r = '';-- // if (isCss) {- // b = `${pxToPt(style.pd?.b || 0)}pt`;- // t = `${pxToPt(style.pd?.t || 0)}pt`;- // l = `${pxToPt(style.pd?.l || 0)}pt`;- // r = `${pxToPt(style.pd?.r || 0)}pt`;- // } else {- let b = `${style.pd?.b}pt`;- let t = `${style.pd?.t}pt`;- let l = `${style.pd?.l}pt`;- let r = `${style.pd?.r}pt`;- // }- if (style.pd?.b) {- str += `padding-bottom: ${b}; `;- }- if (style.pd?.t) {- str += `padding-top: ${t}; `;- }- if (style.pd?.l) {- str += `padding-left: ${l}; `;- }- if (style.pd?.r) {- str += `padding-right: ${r}; `;- }- },- ],- ]);- const cellSkip = ['bd', 'tr', 'tb'];- for (let k in style) {- if (isCell && cellSkip.includes(k)) continue; // Cell styles to skip when entering edit mode- styleMap.get(k)?.();- }- return str;-}--function getBorderStyle(type: BorderStyleTypes) {- let str = '';- if (type === BorderStyleTypes.NONE) {- str = 'none';- } else if (type === BorderStyleTypes.THIN) {- str = '0.5pt solid';- } else if (type === BorderStyleTypes.HAIR) {- str = '0.5pt double';- } else if (type === BorderStyleTypes.DOTTED) {- str = '0.5pt dotted';- } else if (type === BorderStyleTypes.DASHED) {- str = '0.5pt dashed';- } else if (type === BorderStyleTypes.DASH_DOT) {- str = '0.5pt dashed';- } else if (type === BorderStyleTypes.DASH_DOT_DOT) {- str = '0.5pt dotted';- } else if (type === BorderStyleTypes.DOUBLE) {- str = '0.5pt double';- } else if (type === BorderStyleTypes.MEDIUM) {- str = '1pt solid';- } else if (type === BorderStyleTypes.MEDIUM_DASHED) {- str = '1pt dashed';- } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT) {- str = '1pt dashed';- } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT_DOT) {- str = '1pt dotted';- } else if (type === BorderStyleTypes.SLANT_DASH_DOT) {- str = '0.5pt dashed';- } else if (type === BorderStyleTypes.THICK) {- str = '1.5pt solid';- }- return str;-}--export function getBorderStyleType(type: string) {- let str = 0;- type = type.trim();- if (type === 'none') {- str = BorderStyleTypes.NONE;- } else if (type === '0.5pt solid') {- str = BorderStyleTypes.THIN;- } else if (type === '0.5pt double') {- str = BorderStyleTypes.HAIR;- } else if (type === '0.5pt dotted') {- str = BorderStyleTypes.DOTTED;- } else if (type === '0.5pt dashed') {- str = BorderStyleTypes.DASHED;- } else if (type === '1pt solid') {- str = BorderStyleTypes.MEDIUM;- } else if (type === '1pt dashed') {- str = BorderStyleTypes.MEDIUM_DASHED;- } else if (type === '1pt dotted') {- str = BorderStyleTypes.MEDIUM_DASH_DOT_DOT;- } else if (type === '1.5pt solid') {- str = BorderStyleTypes.THICK;- } else {- return BorderStyleTypes.NONE;- }- return str;-}--export function getTextIndexByCursor(index: number, isBack: boolean = false) {- return isBack ? index - 1 : index;-}--export function insertTextToContent(content: string, start: number, text: string) {- return content.slice(0, start) + text + content.slice(start);-}--export function deleteContent(content: string, start: number, end: number) {- if (start > end) {- return content;- }-- if (start === end) {- start -= 1;- }-- return content.slice(0, start) + content.slice(end);-}--export function getDocsUpdateBody(model: IDocumentData, segmentId?: string) {- let body = model.body;-- if (segmentId) {- const { headers, footers } = model;- if (headers?.[segmentId]) {- body = headers[segmentId].body;- } else if (footers?.[segmentId]) {- body = footers[segmentId].body;- }- }-- return body;-}--export function horizontalLineSegmentsSubtraction(- A1: number,- A2: number,- B1: number,- B2: number-) {- // 确保A1 < A2, B1 < B2- if (A1 > A2) {- [A1, A2] = [A2, A1];- }- if (B1 > B2) {- [B1, B2] = [B2, B1];- }-- // 检查线段是否重叠- if (A2 < B1 || B2 < A1) {- return [[A1, A2]]; // 无重叠,返回原线段A- }-- const overlapStart = Math.max(A1, B1);- const overlapEnd = Math.min(A2, B2);-- const result = [];-- // 添加重叠之前的线段- if (overlapStart > A1) {- result.push([A1, overlapStart]);- }-- // 添加重叠之后的线段- if (overlapEnd < A2) {- result.push([overlapEnd, A2]);- }-- return result;-}+import { Tools } from './Tools';+import { Nullable } from '.';+import {+ ICellInfo,+ ISelection,+ ICellData,+ IColorStyle,+ IDocumentData,+ IStyleData,+} from '../Types/Interfaces';+import { ColorBuilder } from '../Sheets/Domain';+import {+ BaselineOffset,+ TextDirection,+ HorizontalAlign,+ VerticalAlign,+ WrapStrategy,+ BorderStyleTypes,+} from '../Types/Enum';++export function makeCellToSelection(+ cellInfo: Nullable<ICellInfo>+): Nullable<ISelection> {+ if (!cellInfo) {+ return;+ }+ let { row, column, startY, endY, startX, endX, isMerged, mergeInfo } = cellInfo;+ let startRow = row;+ let startColumn = column;+ let endRow = row;+ let endColumn = column;+ if (isMerged && mergeInfo) {+ const {+ startRow: mergeStartRow,+ startColumn: mergeStartColumn,+ endRow: mergeEndRow,+ endColumn: mergeEndColumn,+ startY: mergeStartY,+ endY: mergeEndY,+ startX: mergeStartX,+ endX: mergeEndX,+ } = mergeInfo;+ startRow = mergeStartRow;+ startColumn = mergeStartColumn;+ endRow = mergeEndRow;+ endColumn = mergeEndColumn;+ startY = mergeStartY;+ endY = mergeEndY;+ startX = mergeStartX;+ endX = mergeEndX;+ }++ return {+ startRow,+ startColumn,+ endRow,+ endColumn,+ startY,+ endY,+ startX,+ endX,+ };+}++export function isEmptyCell(cell: Nullable<ICellData>) {+ if (!cell) {+ return true;+ }++ const content = cell?.m || '';+ if (content.length === 0 && !cell.p) {+ return true;+ }+ return false;+}++export function getColorStyle(color: Nullable<IColorStyle>): Nullable<string> {+ if (color) {+ if (color.rgb) {+ return color.rgb;+ }+ if (color.th) {+ return new ColorBuilder()+ .setThemeColor(color.th)+ .asThemeColor()+ .asRgbColor()+ .getCssString();+ }+ }+ return null;+}++export function isFormulaString(value: any): boolean {+ return Tools.isString(value) && value.indexOf('=') === 0 && value.length > 1;+}++/**+ * move to Styles.getStyleByCell+ */+// export function getStyle(+// styles: Nullable<Styles>,+// cell: Nullable<ICellData>+// ): Nullable<IStyleData> {+// let style;+// if (cell && Tools.isObject(cell.s)) {+// style = cell.s as IStyleData;+// } else {+// style = cell?.s && styles?.get(cell.s);+// }++// return style as IStyleData;+// }++/**+ * Convert rich text json to DOM+ * @param p+ */+export function handleJsonToDom(p: IDocumentData): string {+ // let span = '';+ // // let span = `<span id="${p.id}">`;+ // if (p.body?.blockElements) {+ // for (let k in p.body.blockElements) {+ // const section = p.body.blockElements[k];+ // if (+ // section.blockType !== BlockType.PARAGRAPH &&+ // section.blockType !== BlockType.SECTION_BREAK+ // ) {+ // continue;+ // }+ // if (section.blockType === BlockType.PARAGRAPH) {+ // for (let i in section.paragraph) {+ // const element = section.paragraph[i];+ // for (let j in element) {+ // const item = element[j];+ // if (item.et === ParagraphElementType.TEXT_RUN) {+ // let style = `display:inline-block;${handleStyleToString(+ // item.tr.ts+ // )}`;+ // span += `<span id='${item.eId}' ${+ // style.length ? `style="${style}"` : ''+ // } >${item.tr.ct}</span>`;+ // }+ // }+ // }+ // }+ // // else if (section.blockType === BlockType.SECTION_BREAK) {+ // // span += '<br/>';+ // // }+ // }+ // }++ // // span += '</span>';+ // return span;+ return '';+}++/**+ * transform style object to string+ * @param style+ * @returns+ */+export function handleStyleToString(style: IStyleData, isCell: boolean = false) {+ let str = '';+ const styleMap = new Map([+ [+ 'ff',+ () => {+ if (style.ff) {+ str += `font-family: ${style.ff}; `;+ }+ },+ ],+ [+ 'fs',+ () => {+ if (style.fs) {+ let fs = style.fs;++ // subscript / superscript, Font size for superscripts and subscripts is halved+ if (style.va) {+ fs /= 2;+ }+ str += `font-size: ${fs}pt; `;+ }++ // const fs = isCss ? `${style.fs}px` : `${pxToPt(style.fs || 14)}pt`;+ // str += `font-size: ${fs}; `;+ },+ ],+ [+ 'it',+ () => {+ if (style.it) {+ str += `font-style: italic; `;+ } else {+ str += `font-style: normal; `;+ }+ },+ ],+ [+ 'bl',+ () => {+ if (style.bl) {+ str += `font-weight: bold; `;+ } else {+ str += `font-weight: normal; `;+ }+ },+ ],+ [+ 'ul',+ () => {+ if (style.ul?.s) {+ // If there are existing lines, add new lines+ if (str.indexOf('text-decoration-line') > -1) {+ str = str.replace(+ /(?<=text-decoration-line:.*)\b(?=;)/g,+ ' underline'+ );+ } else {+ str += `text-decoration-line: underline; `;+ }+ if (style.ul.cl && str.indexOf('text-decoration-color') === -1) {+ str += `text-decoration-color: ${getColorStyle(+ style.ul.cl+ )}; `;+ }+ if (style.ul.t && str.indexOf('text-decoration-style') === -1) {+ str += `text-decoration-style: ${style.ul.t} `;+ }+ }+ },+ ],+ [+ 'st',+ () => {+ if (style.st?.s) {+ if (str.indexOf('text-decoration-line') > -1) {+ str = str.replace(+ /(?<=text-decoration-line:.*)\b(?=;)/g,+ ' line-through'+ );+ } else {+ str += `text-decoration-line: line-through; `;+ }+ if (style.st.cl && str.indexOf('text-decoration-color') === -1) {+ str += `text-decoration-color: ${getColorStyle(+ style.st.cl+ )}; `;+ }+ if (style.st.t && str.indexOf('text-decoration-style') === -1) {+ str += `text-decoration-style: ${style.st.t} `;+ }+ }+ },+ ],+ [+ 'ol',+ () => {+ if (style.ol?.s) {+ if (str.indexOf('text-decoration-line') > -1) {+ str = str.replace(+ /(?<=text-decoration-line:.*)\b(?=;)/g,+ ' overline'+ );+ } else {+ str += `text-decoration-line: overline; `;+ }+ if (style.ol.cl && str.indexOf('text-decoration-color') === -1) {+ str += `text-decoration-color: ${getColorStyle(+ style.ol.cl+ )}; `;+ }+ if (style.ol.t && str.indexOf('text-decoration-style') === -1) {+ str += `text-decoration-style: ${style.ol.t} `;+ }+ }+ },+ ],+ [+ 'bg',+ () => {+ str += `background: ${getColorStyle(style.bg)}; `;+ },+ ],+ [+ 'bd',+ () => {+ if (style.bd?.b) {+ str += `border-bottom: ${getBorderStyle(style.bd?.b.s)} ${+ getColorStyle(style.bd.b.cl) ?? ''+ }; `;+ }+ if (style.bd?.t) {+ str += `border-top: ${getBorderStyle(style.bd?.t.s)} ${+ getColorStyle(style.bd.t.cl) ?? ''+ }; `;+ }+ if (style.bd?.r) {+ str += `border-right: ${getBorderStyle(style.bd?.r.s)} ${+ getColorStyle(style.bd.r.cl) ?? ''+ }; `;+ }+ if (style.bd?.l) {+ str += `border-left: ${getBorderStyle(style.bd?.l.s)} ${+ getColorStyle(style.bd.l.cl) ?? ''+ }; `;+ }+ },+ ],+ [+ 'cl',+ () => {+ str += `color: ${getColorStyle(style.cl)}; `;+ },+ ],+ [+ 'va',+ () => {+ if (style.va === BaselineOffset.NORMAL) {+ str += `vertical-align: baseline; `;+ } else if (style.va === BaselineOffset.SUBSCRIPT) {+ str += `vertical-align: sub; `;+ } else {+ str += `vertical-align: super; `;+ }+ },+ ],+ [+ 'td',+ () => {+ if (style.td === TextDirection.UNSPECIFIED) {+ str += `direction: inherit; `;+ } else if (style.td === TextDirection.LEFT_TO_RIGHT) {+ str += `direction: ltr; `;+ } else {+ str += `direction: rtl; `;+ }+ },+ ],+ [+ 'tr',+ () => {+ str += `data-rotate: (${style.tr?.a}deg${+ style.tr?.v ? ` ,${style.tr?.v}` : ''+ });`;+ },+ ],+ [+ 'ht',+ () => {+ if (style.ht === HorizontalAlign.UNSPECIFIED) {+ str += `text-align: inherit; `;+ } else if (style.ht === HorizontalAlign.LEFT) {+ str += `text-align: left; `;+ } else if (style.ht === HorizontalAlign.RIGHT) {+ str += `text-align: right; `;+ } else if (style.ht === HorizontalAlign.CENTER) {+ str += `text-align: center; `;+ } else {+ str += `text-align: justify; `;+ }+ },+ ],+ [+ 'vt',+ () => {+ if (style.vt === VerticalAlign.UNSPECIFIED) {+ str += `vertical-align: inherit; `;+ } else if (style.vt === VerticalAlign.BOTTOM) {+ str += `vertical-align: bottom; `;+ } else if (style.vt === VerticalAlign.TOP) {+ str += `vertical-align: top; `;+ } else {+ str += `vertical-align: middle; `;+ }+ },+ ],+ [+ 'tb',+ () => {+ if (style.tb === WrapStrategy.CLIP) {+ str += `text-overflow: clip; `;+ } else if (style.tb === WrapStrategy.OVERFLOW) {+ str += `text-break: overflow; `;+ } else if (style.tb === WrapStrategy.WRAP) {+ str += `word-wrap: break-word; word-break: normal; `;+ }+ },+ ],+ [+ 'pd',+ () => {+ // let b = '';+ // let t = '';+ // let l = '';+ // let r = '';++ // if (isCss) {+ // b = `${pxToPt(style.pd?.b || 0)}pt`;+ // t = `${pxToPt(style.pd?.t || 0)}pt`;+ // l = `${pxToPt(style.pd?.l || 0)}pt`;+ // r = `${pxToPt(style.pd?.r || 0)}pt`;+ // } else {+ let b = `${style.pd?.b}pt`;+ let t = `${style.pd?.t}pt`;+ let l = `${style.pd?.l}pt`;+ let r = `${style.pd?.r}pt`;+ // }+ if (style.pd?.b) {+ str += `padding-bottom: ${b}; `;+ }+ if (style.pd?.t) {+ str += `padding-top: ${t}; `;+ }+ if (style.pd?.l) {+ str += `padding-left: ${l}; `;+ }+ if (style.pd?.r) {+ str += `padding-right: ${r}; `;+ }+ },+ ],+ ]);+ const cellSkip = ['bd', 'tr', 'tb'];+ for (let k in style) {+ if (isCell && cellSkip.includes(k)) continue; // Cell styles to skip when entering edit mode+ styleMap.get(k)?.();+ }+ return str;+}++function getBorderStyle(type: BorderStyleTypes) {+ let str = '';+ if (type === BorderStyleTypes.NONE) {+ str = 'none';+ } else if (type === BorderStyleTypes.THIN) {+ str = '0.5pt solid';+ } else if (type === BorderStyleTypes.HAIR) {+ str = '0.5pt double';+ } else if (type === BorderStyleTypes.DOTTED) {+ str = '0.5pt dotted';+ } else if (type === BorderStyleTypes.DASHED) {+ str = '0.5pt dashed';+ } else if (type === BorderStyleTypes.DASH_DOT) {+ str = '0.5pt dashed';+ } else if (type === BorderStyleTypes.DASH_DOT_DOT) {+ str = '0.5pt dotted';+ } else if (type === BorderStyleTypes.DOUBLE) {+ str = '0.5pt double';+ } else if (type === BorderStyleTypes.MEDIUM) {+ str = '1pt solid';+ } else if (type === BorderStyleTypes.MEDIUM_DASHED) {+ str = '1pt dashed';+ } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT) {+ str = '1pt dashed';+ } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT_DOT) {+ str = '1pt dotted';+ } else if (type === BorderStyleTypes.SLANT_DASH_DOT) {+ str = '0.5pt dashed';+ } else if (type === BorderStyleTypes.THICK) {+ str = '1.5pt solid';+ }+ return str;+}++export function getBorderStyleType(type: string) {+ let str = 0;+ type = type.trim();+ if (type === 'none') {+ str = BorderStyleTypes.NONE;+ } else if (type === '0.5pt solid') {+ str = BorderStyleTypes.THIN;+ } else if (type === '0.5pt double') {+ str = BorderStyleTypes.HAIR;+ } else if (type === '0.5pt dotted') {+ str = BorderStyleTypes.DOTTED;+ } else if (type === '0.5pt dashed') {+ str = BorderStyleTypes.DASHED;+ } else if (type === '1pt solid') {+ str = BorderStyleTypes.MEDIUM;+ } else if (type === '1pt dashed') {+ str = BorderStyleTypes.MEDIUM_DASHED;+ } else if (type === '1pt dotted') {+ str = BorderStyleTypes.MEDIUM_DASH_DOT_DOT;+ } else if (type === '1.5pt solid') {+ str = BorderStyleTypes.THICK;+ } else {+ return BorderStyleTypes.NONE;+ }+ return str;+}++export function getTextIndexByCursor(index: number, isBack: boolean = false) {+ return isBack ? index - 1 : index;+}++export function insertTextToContent(content: string, start: number, text: string) {+ return content.slice(0, start) + text + content.slice(start);+}++export function deleteContent(content: string, start: number, end: number) {+ if (start > end) {+ return content;+ }++ if (start === end) {+ start -= 1;+ }++ return content.slice(0, start) + content.slice(end);+}++export function getDocsUpdateBody(model: IDocumentData, segmentId?: string) {+ let body = model.body;++ if (segmentId) {+ const { headers, footers } = model;+ if (headers?.[segmentId]) {+ body = headers[segmentId].body;+ } else if (footers?.[segmentId]) {+ body = footers[segmentId].body;+ }+ }++ return body;+}++export function horizontalLineSegmentsSubtraction(+ A1: number,+ A2: number,+ B1: number,+ B2: number+) {+ // 确保A1 < A2, B1 < B2+ if (A1 > A2) {+ [A1, A2] = [A2, A1];+ }+ if (B1 > B2) {+ [B1, B2] = [B2, B1];+ }++ // 检查线段是否重叠+ if (A2 < B1 || B2 < A1) {+ return [[A1, A2]]; // 无重叠,返回原线段A+ }++ const overlapStart = Math.max(A1, B1);+ const overlapEnd = Math.min(A2, B2);++ const result = [];++ // 添加重叠之前的线段+ if (overlapStart > A1) {+ result.push([A1, overlapStart]);+ }++ // 添加重叠之后的线段+ if (overlapEnd < A2) {+ result.push([overlapEnd, A2]);+ }++ return result;+}diff --git a/packages/core/src/Shared/Compare.ts b/packages/core/src/Shared/Compare.tsindex 4dbd2ef422..7a527c7291 100644--- a/packages/core/src/Shared/Compare.ts+++ b/packages/core/src/Shared/Compare.ts@@ -1,4 +1,4 @@-import { ITextRun } from '../Interfaces/IDocumentData';+import { ITextRun } from '../Types/Interfaces/IDocumentData';type AnyObject = {[key: number | string]: AnyObject | AnyObject[] | Array<[number | string]> | any;diff --git a/packages/core/src/Shared/KeyboardUtil.ts b/packages/core/src/Shared/KeyboardUtil.tsindex f8ec9ad205..1c9292b690 100644--- a/packages/core/src/Shared/KeyboardUtil.ts+++ b/packages/core/src/Shared/KeyboardUtil.ts@@ -1,15 +1,15 @@-import { KEYBOARD_KEYS } from '../Const/KEYBOARD_KEYS';--const allKeys = Object.keys(KEYBOARD_KEYS).reduce(- (acc, category) => [...acc, ...KEYBOARD_KEYS[category]],- [] as string[]-);--/**- * Reference of non-printable Keyboard Event.key values- *- * https://www.aarongreenlee.com/blog/list-of-non-printable-keys-for-keyboard-events-when-using-event-key/- */-export function isKeyPrintable(key: string) {- return allKeys.indexOf(key) === -1;-}+import { KEYBOARD_KEYS } from '../Types/Const/KEYBOARD_KEYS';++const allKeys = Object.keys(KEYBOARD_KEYS).reduce(+ (acc, category) => [...acc, ...KEYBOARD_KEYS[category]],+ [] as string[]+);++/**+ * Reference of non-printable Keyboard Event.key values+ *+ * https://www.aarongreenlee.com/blog/list-of-non-printable-keys-for-keyboard-events-when-using-event-key/+ */+export function isKeyPrintable(key: string) {+ return allKeys.indexOf(key) === -1;+}diff --git a/packages/core/src/Shared/Locale.ts b/packages/core/src/Shared/Locale.tsindex 098e8b0351..11809a3272 100644--- a/packages/core/src/Shared/Locale.ts+++ b/packages/core/src/Shared/Locale.ts@@ -1,5 +1,5 @@import { Tools } from './Tools';-import { LocaleType } from '../Enum/LocaleType';+import { LocaleType } from '../Types/Enum/LocaleType';import { IKeyValue, Nullable } from './Types';export type ILocales = {diff --git a/packages/core/src/Shared/Migrate/Border.ts b/packages/core/src/Shared/Migrate/Border.tsindex e727769bb0..19545e7325 100644--- a/packages/core/src/Shared/Migrate/Border.ts+++ b/packages/core/src/Shared/Migrate/Border.ts@@ -1,4 +1,4 @@-import { IWorksheetConfig, IBorderData, IStyleData } from '../../Interfaces';+import { IWorksheetConfig, IBorderData, IStyleData } from '../../Types/Interfaces';export function border(newSheet: Partial<IWorksheetConfig>, sheet: any) {newSheet.cellData = {};diff --git a/packages/core/src/Shared/Migrate/Migrate.ts b/packages/core/src/Shared/Migrate/Migrate.tsindex 836a57838b..059c6b0d55 100644--- a/packages/core/src/Shared/Migrate/Migrate.ts+++ b/packages/core/src/Shared/Migrate/Migrate.ts@@ -1,463 +1,463 @@-import {- BooleanNumber,- HorizontalAlign,- VerticalAlign,- WrapStrategy,-} from '../../Enum';-import {- IWorkbookConfig,- IWorksheetConfig,- ICellData,- ITextStyle,- IStyleData,- IRowData,- IColumnData,- ITextRun,-} from '../../Interfaces';-import { ObjectArrayPrimitiveType } from '../ObjectArray';-import { Tools } from '../Tools';-import { IKeyValue } from '../Types';-import { border } from './Border';--export function migrate(config: any): Partial<IWorkbookConfig> {- const newConfig: Partial<IWorkbookConfig> = {};- newConfig.styles = {};- if (config.hasOwnProperty('lang')) {- newConfig.locale = config.lang;- }- if (config.hasOwnProperty('data')) {- newConfig.sheets = {};- for (let sheet of config.data) {- const newSheet: Partial<IWorksheetConfig> = {};-- // id- // if (sheet.hasOwnProperty('index')) {- // newSheet.id = sheet.index as string;- // } else {- newSheet.id = Tools.generateRandomId(6);- // }-- // 缩放比例- if (sheet.hasOwnProperty('zoomRatio')) {- newSheet.zoomRatio = sheet.zoomRatio;- }-- // 最大行号- if (sheet.hasOwnProperty('row')) {- newSheet.rowCount = sheet.row;- }-- // 最大列号- if (sheet.hasOwnProperty('column')) {- newSheet.columnCount = sheet.column;- }-- // 是否激活- if (sheet.hasOwnProperty('status')) {- newSheet.status = parseInt(sheet.status);- }-- // sheet 名称- if (sheet.hasOwnProperty('name')) {- newSheet.name = sheet.name;- }-- // 激活选区- if (sheet.hasOwnProperty('universheet_select_save')) {- newSheet.selections = [];- sheet.universheet_select_save.forEach((selection: IKeyValue) => {- newSheet.selections?.push({- startRow: selection.row[0],- endRow: selection.row[1],- startColumn: selection.column[0],- endColumn: selection.column[1],- });- });- }-- // 横向滚动条位置- if (sheet.hasOwnProperty('scrollLeft')) {- newSheet.scrollLeft = sheet.scrollLeft;- }-- // 竖向滚动条位置- if (sheet.hasOwnProperty('scrollTop')) {- newSheet.scrollTop = sheet.scrollTop;- }-- if (sheet.hasOwnProperty('config')) {- // 合并单元格- if (sheet.config.merge) {- newSheet.mergeData = [];- for (const key of Object.keys(sheet.config.merge)) {- const merge: {- r: number;- c: number;- rs: number;- cs: number;- } = sheet.config.merge[key];- const mergeReact = {- startRow: merge.r,- endRow: merge.r + merge.rs - 1,- startColumn: merge.c,- endColumn: merge.c + merge.cs - 1,- };- newSheet.mergeData.push(mergeReact);- }- }-- // 边框,先按顺序设置到每一个单元格对象中,设置时需要遍历四个方向的相邻单元格做去重,最后单元格样式确定之后,再统一提取到styles上- if (sheet.config.borderInfo) {- border(newSheet, sheet);- }-- // 行高- if (sheet.config.rowlen) {- newSheet.rowData = {};- for (const [rowIndex, height] of Object.entries(- sheet.config.rowlen- )) {- newSheet.rowData[Number(rowIndex)] = {- h: Number(height),- hd: 0,- };- }- }- // 列宽- if (sheet.config.columnlen) {- newSheet.columnData = {};- for (const [colIndex, width] of Object.entries(- sheet.config.columnlen- )) {- newSheet.columnData[Number(colIndex)] = {- w: Number(width),- hd: 0,- };- }- }- // 隐藏行- if (sheet.config.rowhidden) {- if (!newSheet.rowData) newSheet.rowData = {};- let rowData = newSheet.rowData as ObjectArrayPrimitiveType<- Partial<IRowData>- >;- for (const [rowIndex, isHidden] of Object.entries(- sheet.config.rowhidden- )) {- if (!rowData[Number(rowIndex)]) {- rowData[Number(rowIndex)] = {};- }-- rowData[Number(rowIndex)].hd = isHidden as BooleanNumber;- }- }- // 隐藏列- if (sheet.config.colhidden) {- if (!newSheet.columnData) newSheet.columnData = {};- let columnData = newSheet.columnData as ObjectArrayPrimitiveType<- Partial<IColumnData>- >;- for (const [colIndex, isHidden] of Object.entries(- sheet.config.colhidden- )) {- if (!columnData[Number(colIndex)]) {- columnData[Number(colIndex)] = {};- }- columnData[Number(colIndex)].hd = isHidden as BooleanNumber;- }- }- }-- // 单元格数据- if (sheet.hasOwnProperty('celldata')) {- if (!newSheet.cellData) {- newSheet.cellData = {};- }-- for (const cellItem of sheet.celldata) {- if (!newSheet.cellData[cellItem.r]) {- newSheet.cellData[cellItem.r] = {};- }- if (!newSheet.cellData[cellItem.r][cellItem.c]) {- newSheet.cellData[cellItem.r][cellItem.c] = {};- }-- const cell = cellItem.v;-- const newCell: ICellData =- newSheet.cellData[cellItem.r][cellItem.c];-- if (cell?.ct?.t === 'inlineStr') {- const textRuns: ITextRun[] = [];- let dataStream = '';-- cell.ct.s.forEach((element: any) => {- const textStyle: ITextStyle = {};-- // 背景颜色- if (element.hasOwnProperty('bg')) {- textStyle.bg = {- rgb: element.fc,- };- }-- // 字体- if (element.hasOwnProperty('ff')) {- textStyle.ff = element.ff;- }-- // 字体颜色- if (element.hasOwnProperty('fc')) {- textStyle.cl = {- rgb: element.fc,- };- }-- // 字体大小- if (element.hasOwnProperty('fs')) {- textStyle.fs = element.fs;- }-- // 粗体- if (element.hasOwnProperty('bl')) {- textStyle.bl = element.bl;- }-- // 斜体- if (element.hasOwnProperty('it')) {- textStyle.it = element.it;- }-- // 删除线- if (element.hasOwnProperty('cl')) {- textStyle.st = {- s: 1,- };- }-- // 下划线- if (element.hasOwnProperty('un')) {- textStyle.ul = {- s: element.un,- };- }-- const sId = Tools.generateRandomId(6);- dataStream += element.v;- textRuns.push({- sId,- st: 0,- ed: element.v.length - 1,- ts: textStyle,- });- });-- dataStream += '\r\n';-- newCell.p = {- id: Tools.generateRandomId(6),- body: {- dataStream,- textRuns,- },- documentStyle: {},- };- } else {- // 原始值- if (cell.hasOwnProperty('v')) {- newCell.v = cell.v;- }-- // 显示值- if (cell.hasOwnProperty('m')) {- newCell.m = cell.m;- } else {- newCell.m = String(cell.v || '');- }-- const cellStyle: IStyleData = {};-- // 背景颜色- if (cell.hasOwnProperty('bg')) {- cellStyle.bg = {- rgb: cell.bg,- };- }-- // 字体- if (cell.hasOwnProperty('ff')) {- cellStyle.ff = cell.ff;- }-- // 字体颜色- if (cell.hasOwnProperty('fc')) {- cellStyle.cl = {- rgb: cell.fc,- };- }-- // 字体大小- if (cell.hasOwnProperty('fs')) {- cellStyle.fs = cell.fs;- }-- // 粗体- if (cell.hasOwnProperty('bl')) {- cellStyle.bl = cell.bl;- }-- // 斜体- if (cell.hasOwnProperty('it')) {- cellStyle.it = cell.it;- }-- // 删除线- if (cell.hasOwnProperty('cl')) {- cellStyle.st = {- s: cell.cl,- };- }-- // 下划线- if (cell.hasOwnProperty('un')) {- cellStyle.ul = {- s: cell.un,- };- }-- const sMap = {- '0': VerticalAlign.MIDDLE,- '1': VerticalAlign.TOP,- '2': VerticalAlign.BOTTOM,- };- // const sMap = {- // '0': 2,- // '1': 1,- // '2': 3,- // };-- // 垂直对齐- if (cell.hasOwnProperty('vt')) {- switch (String(cell.vt)) {- case '0':- cellStyle.vt = VerticalAlign.MIDDLE;- break;- case '1':- cellStyle.vt = VerticalAlign.TOP;- break;- case '2':- cellStyle.vt = VerticalAlign.BOTTOM;- break;-- default:- break;- }- // cellStyle.vt = sMap[String(cell.vt)];- }-- // 水平对齐- if (cell.hasOwnProperty('ht')) {- switch (String(cell.ht)) {- case '0':- cellStyle.ht = HorizontalAlign.CENTER;- break;- case '1':- cellStyle.ht = HorizontalAlign.LEFT;- break;- case '2':- cellStyle.ht = HorizontalAlign.RIGHT;- break;-- default:- break;- }- // cellStyle.ht = sMap[String(cell.ht)];- }-- // 竖排文字- if (cell.hasOwnProperty('tr')) {- switch (cell.tr) {- case '0':- cellStyle.tr = {- a: 0,- v: 0,- };- break;-- case '1':- cellStyle.tr = {- a: 45,- v: 0,- };- break;-- case '2':- cellStyle.tr = {- a: -45,- v: 0,- };- break;-- case '3':- cellStyle.tr = {- a: 0,- v: 1,- };- break;-- case '4':- cellStyle.tr = {- a: 90,- v: 0,- };- break;-- case '5':- cellStyle.tr = {- a: -90,- v: 0,- };- break;-- default:- break;- }- }-- // 文字旋转角度- if (cell.hasOwnProperty('rt')) {- cellStyle.tr = {- a: cell.tr,- v: 0,- };- }-- // 文本换行- if (cell.hasOwnProperty('tb')) {- switch (String(cell.tb)) {- case '0':- cellStyle.tb = WrapStrategy.CLIP;- break;- case '1':- cellStyle.tb = WrapStrategy.OVERFLOW;- break;- case '2':- cellStyle.tb = WrapStrategy.WRAP;- break;-- default:- break;- }- //cellStyle.tb = sMap[String(cell.tb)];- }-- newCell.s = Object.assign(newCell.s || {}, cellStyle);- }- }- }-- newConfig.sheets[newSheet.id] = newSheet;- }- }- return newConfig;-}+import {+ BooleanNumber,+ HorizontalAlign,+ VerticalAlign,+ WrapStrategy,+} from '../../Types/Enum';+import {+ IWorkbookConfig,+ IWorksheetConfig,+ ICellData,+ ITextStyle,+ IStyleData,+ IRowData,+ IColumnData,+ ITextRun,+} from '../../Types/Interfaces';+import { ObjectArrayPrimitiveType } from '../ObjectArray';+import { Tools } from '../Tools';+import { IKeyValue } from '../Types';+import { border } from './Border';++export function migrate(config: any): Partial<IWorkbookConfig> {+ const newConfig: Partial<IWorkbookConfig> = {};+ newConfig.styles = {};+ if (config.hasOwnProperty('lang')) {+ newConfig.locale = config.lang;+ }+ if (config.hasOwnProperty('data')) {+ newConfig.sheets = {};+ for (let sheet of config.data) {+ const newSheet: Partial<IWorksheetConfig> = {};++ // id+ // if (sheet.hasOwnProperty('index')) {+ // newSheet.id = sheet.index as string;+ // } else {+ newSheet.id = Tools.generateRandomId(6);+ // }++ // 缩放比例+ if (sheet.hasOwnProperty('zoomRatio')) {+ newSheet.zoomRatio = sheet.zoomRatio;+ }++ // 最大行号+ if (sheet.hasOwnProperty('row')) {+ newSheet.rowCount = sheet.row;+ }++ // 最大列号+ if (sheet.hasOwnProperty('column')) {+ newSheet.columnCount = sheet.column;+ }++ // 是否激活+ if (sheet.hasOwnProperty('status')) {+ newSheet.status = parseInt(sheet.status);+ }++ // sheet 名称+ if (sheet.hasOwnProperty('name')) {+ newSheet.name = sheet.name;+ }++ // 激活选区+ if (sheet.hasOwnProperty('universheet_select_save')) {+ newSheet.selections = [];+ sheet.universheet_select_save.forEach((selection: IKeyValue) => {+ newSheet.selections?.push({+ startRow: selection.row[0],+ endRow: selection.row[1],+ startColumn: selection.column[0],+ endColumn: selection.column[1],+ });+ });+ }++ // 横向滚动条位置+ if (sheet.hasOwnProperty('scrollLeft')) {+ newSheet.scrollLeft = sheet.scrollLeft;+ }++ // 竖向滚动条位置+ if (sheet.hasOwnProperty('scrollTop')) {+ newSheet.scrollTop = sheet.scrollTop;+ }++ if (sheet.hasOwnProperty('config')) {+ // 合并单元格+ if (sheet.config.merge) {+ newSheet.mergeData = [];+ for (const key of Object.keys(sheet.config.merge)) {+ const merge: {+ r: number;+ c: number;+ rs: number;+ cs: number;+ } = sheet.config.merge[key];+ const mergeReact = {+ startRow: merge.r,+ endRow: merge.r + merge.rs - 1,+ startColumn: merge.c,+ endColumn: merge.c + merge.cs - 1,+ };+ newSheet.mergeData.push(mergeReact);+ }+ }++ // 边框,先按顺序设置到每一个单元格对象中,设置时需要遍历四个方向的相邻单元格做去重,最后单元格样式确定之后,再统一提取到styles上+ if (sheet.config.borderInfo) {+ border(newSheet, sheet);+ }++ // 行高+ if (sheet.config.rowlen) {+ newSheet.rowData = {};+ for (const [rowIndex, height] of Object.entries(+ sheet.config.rowlen+ )) {+ newSheet.rowData[Number(rowIndex)] = {+ h: Number(height),+ hd: 0,+ };+ }+ }+ // 列宽+ if (sheet.config.columnlen) {+ newSheet.columnData = {};+ for (const [colIndex, width] of Object.entries(+ sheet.config.columnlen+ )) {+ newSheet.columnData[Number(colIndex)] = {+ w: Number(width),+ hd: 0,+ };+ }+ }+ // 隐藏行+ if (sheet.config.rowhidden) {+ if (!newSheet.rowData) newSheet.rowData = {};+ let rowData = newSheet.rowData as ObjectArrayPrimitiveType<+ Partial<IRowData>+ >;+ for (const [rowIndex, isHidden] of Object.entries(+ sheet.config.rowhidden+ )) {+ if (!rowData[Number(rowIndex)]) {+ rowData[Number(rowIndex)] = {};+ }++ rowData[Number(rowIndex)].hd = isHidden as BooleanNumber;+ }+ }+ // 隐藏列+ if (sheet.config.colhidden) {+ if (!newSheet.columnData) newSheet.columnData = {};+ let columnData = newSheet.columnData as ObjectArrayPrimitiveType<+ Partial<IColumnData>+ >;+ for (const [colIndex, isHidden] of Object.entries(+ sheet.config.colhidden+ )) {+ if (!columnData[Number(colIndex)]) {+ columnData[Number(colIndex)] = {};+ }+ columnData[Number(colIndex)].hd = isHidden as BooleanNumber;+ }+ }+ }++ // 单元格数据+ if (sheet.hasOwnProperty('celldata')) {+ if (!newSheet.cellData) {+ newSheet.cellData = {};+ }++ for (const cellItem of sheet.celldata) {+ if (!newSheet.cellData[cellItem.r]) {+ newSheet.cellData[cellItem.r] = {};+ }+ if (!newSheet.cellData[cellItem.r][cellItem.c]) {+ newSheet.cellData[cellItem.r][cellItem.c] = {};+ }++ const cell = cellItem.v;++ const newCell: ICellData =+ newSheet.cellData[cellItem.r][cellItem.c];++ if (cell?.ct?.t === 'inlineStr') {+ const textRuns: ITextRun[] = [];+ let dataStream = '';++ cell.ct.s.forEach((element: any) => {+ const textStyle: ITextStyle = {};++ // 背景颜色+ if (element.hasOwnProperty('bg')) {+ textStyle.bg = {+ rgb: element.fc,+ };+ }++ // 字体+ if (element.hasOwnProperty('ff')) {+ textStyle.ff = element.ff;+ }++ // 字体颜色+ if (element.hasOwnProperty('fc')) {+ textStyle.cl = {+ rgb: element.fc,+ };+ }++ // 字体大小+ if (element.hasOwnProperty('fs')) {+ textStyle.fs = element.fs;+ }++ // 粗体+ if (element.hasOwnProperty('bl')) {+ textStyle.bl = element.bl;+ }++ // 斜体+ if (element.hasOwnProperty('it')) {+ textStyle.it = element.it;+ }++ // 删除线+ if (element.hasOwnProperty('cl')) {+ textStyle.st = {+ s: 1,+ };+ }++ // 下划线+ if (element.hasOwnProperty('un')) {+ textStyle.ul = {+ s: element.un,+ };+ }++ const sId = Tools.generateRandomId(6);+ dataStream += element.v;+ textRuns.push({+ sId,+ st: 0,+ ed: element.v.length - 1,+ ts: textStyle,+ });+ });++ dataStream += '\r\n';++ newCell.p = {+ id: Tools.generateRandomId(6),+ body: {+ dataStream,+ textRuns,+ },+ documentStyle: {},+ };+ } else {+ // 原始值+ if (cell.hasOwnProperty('v')) {+ newCell.v = cell.v;+ }++ // 显示值+ if (cell.hasOwnProperty('m')) {+ newCell.m = cell.m;+ } else {+ newCell.m = String(cell.v || '');+ }++ const cellStyle: IStyleData = {};++ // 背景颜色+ if (cell.hasOwnProperty('bg')) {+ cellStyle.bg = {+ rgb: cell.bg,+ };+ }++ // 字体+ if (cell.hasOwnProperty('ff')) {+ cellStyle.ff = cell.ff;+ }++ // 字体颜色+ if (cell.hasOwnProperty('fc')) {+ cellStyle.cl = {+ rgb: cell.fc,+ };+ }++ // 字体大小+ if (cell.hasOwnProperty('fs')) {+ cellStyle.fs = cell.fs;+ }++ // 粗体+ if (cell.hasOwnProperty('bl')) {+ cellStyle.bl = cell.bl;+ }++ // 斜体+ if (cell.hasOwnProperty('it')) {+ cellStyle.it = cell.it;+ }++ // 删除线+ if (cell.hasOwnProperty('cl')) {+ cellStyle.st = {+ s: cell.cl,+ };+ }++ // 下划线+ if (cell.hasOwnProperty('un')) {+ cellStyle.ul = {+ s: cell.un,+ };+ }++ const sMap = {+ '0': VerticalAlign.MIDDLE,+ '1': VerticalAlign.TOP,+ '2': VerticalAlign.BOTTOM,+ };+ // const sMap = {+ // '0': 2,+ // '1': 1,+ // '2': 3,+ // };++ // 垂直对齐+ if (cell.hasOwnProperty('vt')) {+ switch (String(cell.vt)) {+ case '0':+ cellStyle.vt = VerticalAlign.MIDDLE;+ break;+ case '1':+ cellStyle.vt = VerticalAlign.TOP;+ break;+ case '2':+ cellStyle.vt = VerticalAlign.BOTTOM;+ break;++ default:+ break;+ }+ // cellStyle.vt = sMap[String(cell.vt)];+ }++ // 水平对齐+ if (cell.hasOwnProperty('ht')) {+ switch (String(cell.ht)) {+ case '0':+ cellStyle.ht = HorizontalAlign.CENTER;+ break;+ case '1':+ cellStyle.ht = HorizontalAlign.LEFT;+ break;+ case '2':+ cellStyle.ht = HorizontalAlign.RIGHT;+ break;++ default:+ break;+ }+ // cellStyle.ht = sMap[String(cell.ht)];+ }++ // 竖排文字+ if (cell.hasOwnProperty('tr')) {+ switch (cell.tr) {+ case '0':+ cellStyle.tr = {+ a: 0,+ v: 0,+ };+ break;++ case '1':+ cellStyle.tr = {+ a: 45,+ v: 0,+ };+ break;++ case '2':+ cellStyle.tr = {+ a: -45,+ v: 0,+ };+ break;++ case '3':+ cellStyle.tr = {+ a: 0,+ v: 1,+ };+ break;++ case '4':+ cellStyle.tr = {+ a: 90,+ v: 0,+ };+ break;++ case '5':+ cellStyle.tr = {+ a: -90,+ v: 0,+ };+ break;++ default:+ break;+ }+ }++ // 文字旋转角度+ if (cell.hasOwnProperty('rt')) {+ cellStyle.tr = {+ a: cell.tr,+ v: 0,+ };+ }++ // 文本换行+ if (cell.hasOwnProperty('tb')) {+ switch (String(cell.tb)) {+ case '0':+ cellStyle.tb = WrapStrategy.CLIP;+ break;+ case '1':+ cellStyle.tb = WrapStrategy.OVERFLOW;+ break;+ case '2':+ cellStyle.tb = WrapStrategy.WRAP;+ break;++ default:+ break;+ }+ //cellStyle.tb = sMap[String(cell.tb)];+ }++ newCell.s = Object.assign(newCell.s || {}, cellStyle);+ }+ }+ }++ newConfig.sheets[newSheet.id] = newSheet;+ }+ }+ return newConfig;+}diff --git a/packages/core/src/Shared/ObjectMatrix.ts b/packages/core/src/Shared/ObjectMatrix.tsindex 199b301b7d..1c674dea99 100644--- a/packages/core/src/Shared/ObjectMatrix.ts+++ b/packages/core/src/Shared/ObjectMatrix.ts@@ -1,4 +1,4 @@-import { IRangeData } from '../Interfaces/IRangeData';+import { IRangeData } from '../Types/Interfaces/IRangeData';import {ObjectArray,ObjectArrayPrimitiveType,diff --git a/packages/core/src/Shared/Rectangle.ts b/packages/core/src/Shared/Rectangle.tsindex da6be3824f..c46e389477 100644--- a/packages/core/src/Shared/Rectangle.ts+++ b/packages/core/src/Shared/Rectangle.ts@@ -1,4 +1,4 @@-import { IRangeData } from '../Interfaces';+import { IRangeData } from '../Types/Interfaces';import { Tools } from './Tools';/**diff --git a/packages/core/src/Shared/Reference.ts b/packages/core/src/Shared/Reference.tsindex 3eccea0faa..b800fde774 100644--- a/packages/core/src/Shared/Reference.ts+++ b/packages/core/src/Shared/Reference.ts@@ -1,4 +1,4 @@-import { IRangeData } from '../Interfaces';+import { IRangeData } from '../Types/Interfaces';import { Tools } from './Tools';const COLON_SYMBOL = ':';diff --git a/packages/core/src/Sheets/Action/AddMergeAction.ts b/packages/core/src/Sheets/Action/AddMergeAction.tsindex 38c2b23c98..195f8eef90 100644--- a/packages/core/src/Sheets/Action/AddMergeAction.ts+++ b/packages/core/src/Sheets/Action/AddMergeAction.ts@@ -1,5 +1,5 @@import { CommandManager, CommandUnit } from '../../Command';-import { IRangeData } from '../../Interfaces';+import { IRangeData } from '../../Types/Interfaces';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers } from '../../Command/ActionObservers';import { IRemoveMergeActionData } from './RemoveMergeAction';diff --git a/packages/core/src/Sheets/Action/AddNamedRangeAction.ts b/packages/core/src/Sheets/Action/AddNamedRangeAction.tsindex 18836d001b..258d5fede0 100644--- a/packages/core/src/Sheets/Action/AddNamedRangeAction.ts+++ b/packages/core/src/Sheets/Action/AddNamedRangeAction.ts@@ -6,7 +6,7 @@ import {CommandUnit,CommandManager,} from '../../Command';-import { INamedRange } from '../../Interfaces/INamedRange';+import { INamedRange } from '../../Types/Interfaces/INamedRange';import { AddNamedRangeApply } from '../Apply';import { DeleteNamedRangeApply } from '../Apply/DeleteNamedRange';import {diff --git a/packages/core/src/Sheets/Action/ClearRangeAction.ts b/packages/core/src/Sheets/Action/ClearRangeAction.tsindex dbad5ab509..0bb63e1307 100644--- a/packages/core/src/Sheets/Action/ClearRangeAction.ts+++ b/packages/core/src/Sheets/Action/ClearRangeAction.ts@@ -1,5 +1,5 @@import { ClearRangeApply, SetRangeDataApply } from '../Apply';-import { ICellData, IOptionData, IRangeData } from '../../Interfaces';+import { ICellData, IOptionData, IRangeData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/DeleteNamedRangeAction.ts b/packages/core/src/Sheets/Action/DeleteNamedRangeAction.tsindex d0109e934d..2656db1fef 100644--- a/packages/core/src/Sheets/Action/DeleteNamedRangeAction.ts+++ b/packages/core/src/Sheets/Action/DeleteNamedRangeAction.ts@@ -7,7 +7,7 @@ import {CommandManager,} from '../../Command';import { AddNamedRangeApply, DeleteNamedRangeApply } from '../Apply';-import { INamedRange } from '../../Interfaces';+import { INamedRange } from '../../Types/Interfaces';import {AddNamedRangeAction,IAddNamedRangeActionData,diff --git a/packages/core/src/Sheets/Action/DeleteRangeAction.ts b/packages/core/src/Sheets/Action/DeleteRangeAction.tsindex 96694dec50..2c73c686be 100644--- a/packages/core/src/Sheets/Action/DeleteRangeAction.ts+++ b/packages/core/src/Sheets/Action/DeleteRangeAction.ts@@ -1,5 +1,5 @@-import { Dimension } from '../../Enum/Dimension';-import { ICellData, IRangeData } from '../../Interfaces';+import { Dimension } from '../../Types/Enum/Dimension';+import { ICellData, IRangeData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/InsertColumnDataAction.ts b/packages/core/src/Sheets/Action/InsertColumnDataAction.tsindex 456f8098ec..564c2d83fd 100644--- a/packages/core/src/Sheets/Action/InsertColumnDataAction.ts+++ b/packages/core/src/Sheets/Action/InsertColumnDataAction.ts@@ -3,7 +3,7 @@ import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { ObjectArray } from '../../Shared';import { CommandManager, CommandUnit } from '../../Command';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ActionObservers, ActionType } from '../../Command/ActionObservers';import { IRemoveColumnDataAction } from './RemoveColumnDataAction';diff --git a/packages/core/src/Sheets/Action/InsertRangeAction.ts b/packages/core/src/Sheets/Action/InsertRangeAction.tsindex fd160acb94..2c35d1d390 100644--- a/packages/core/src/Sheets/Action/InsertRangeAction.ts+++ b/packages/core/src/Sheets/Action/InsertRangeAction.ts@@ -1,6 +1,6 @@-import { ICellData, IRangeData } from '../../Interfaces';+import { ICellData, IRangeData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';-import { Dimension } from '../../Enum/Dimension';+import { Dimension } from '../../Types/Enum/Dimension';import { IDeleteRangeActionData } from './DeleteRangeAction';import { CommandManager, CommandUnit } from '../../Command';import { SetRangeDataAction } from './SetRangeDataAction';diff --git a/packages/core/src/Sheets/Action/InsertRowDataAction.ts b/packages/core/src/Sheets/Action/InsertRowDataAction.tsindex ee75518aca..981578722f 100644--- a/packages/core/src/Sheets/Action/InsertRowDataAction.ts+++ b/packages/core/src/Sheets/Action/InsertRowDataAction.ts@@ -1,5 +1,5 @@import { InsertDataRowApply, RemoveRowDataApply } from '../Apply';-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { ObjectArray } from '../../Shared';import { CommandManager, CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Action/InsertSheetAction.ts b/packages/core/src/Sheets/Action/InsertSheetAction.tsindex 4c79146b03..10569857d4 100644--- a/packages/core/src/Sheets/Action/InsertSheetAction.ts+++ b/packages/core/src/Sheets/Action/InsertSheetAction.ts@@ -1,5 +1,5 @@import { InsertSheetApply, RemoveSheetApply } from '../Apply';-import { IWorksheetConfig } from '../../Interfaces';+import { IWorksheetConfig } from '../../Types/Interfaces';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { CommandManager, CommandUnit } from '../../Command';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/RemoveColumnDataAction.ts b/packages/core/src/Sheets/Action/RemoveColumnDataAction.tsindex b32474bf3f..2244b4b51a 100644--- a/packages/core/src/Sheets/Action/RemoveColumnDataAction.ts+++ b/packages/core/src/Sheets/Action/RemoveColumnDataAction.ts@@ -1,5 +1,5 @@import { InsertDataColumnApply, RemoveColumnDataApply } from '../Apply';-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/RemoveMergeAction.ts b/packages/core/src/Sheets/Action/RemoveMergeAction.tsindex ffddd1d4bf..f0fa3658c1 100644--- a/packages/core/src/Sheets/Action/RemoveMergeAction.ts+++ b/packages/core/src/Sheets/Action/RemoveMergeAction.ts@@ -1,5 +1,5 @@import { addMergeApply, RemoveMergeApply } from '../Apply';-import { IRangeData } from '../../Interfaces';+import { IRangeData } from '../../Types/Interfaces';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { CommandManager, CommandUnit } from '../../Command';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/RemoveRowDataAction.ts b/packages/core/src/Sheets/Action/RemoveRowDataAction.tsindex 2d3414f8d8..19d9e16f0e 100644--- a/packages/core/src/Sheets/Action/RemoveRowDataAction.ts+++ b/packages/core/src/Sheets/Action/RemoveRowDataAction.ts@@ -1,5 +1,5 @@import { InsertDataRowApply, RemoveRowDataApply } from '../Apply';-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { CommandManager, CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Action/RemoveSheetAction.ts b/packages/core/src/Sheets/Action/RemoveSheetAction.tsindex fb25fbfba9..0d0e1c7de4 100644--- a/packages/core/src/Sheets/Action/RemoveSheetAction.ts+++ b/packages/core/src/Sheets/Action/RemoveSheetAction.ts@@ -1,5 +1,5 @@import { InsertSheetApply, RemoveSheetApply } from '../Apply';-import { IWorksheetConfig } from '../../Interfaces';+import { IWorksheetConfig } from '../../Types/Interfaces';import { CommandManager, CommandUnit } from '../../Command';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { IInsertSheetActionData } from './InsertSheetAction';diff --git a/packages/core/src/Sheets/Action/SetBorderAction.ts b/packages/core/src/Sheets/Action/SetBorderAction.tsindex 2a8fa41f3f..563d6eb8c3 100644--- a/packages/core/src/Sheets/Action/SetBorderAction.ts+++ b/packages/core/src/Sheets/Action/SetBorderAction.ts@@ -1,7 +1,7 @@import { ObjectMatrixPrimitiveType } from '../../Shared';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { SetBorderApply } from '../Apply';-import { IStyleData } from '../../Interfaces';+import { IStyleData } from '../../Types/Interfaces';import { ActionObservers, ActionType } from '../../Command/ActionObservers';import { CommandManager, CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Action/SetNamedRangeAction.ts b/packages/core/src/Sheets/Action/SetNamedRangeAction.tsindex 78ab38290c..d338ebaf34 100644--- a/packages/core/src/Sheets/Action/SetNamedRangeAction.ts+++ b/packages/core/src/Sheets/Action/SetNamedRangeAction.ts@@ -7,7 +7,7 @@ import {CommandManager,} from '../../Command';import { SetNamedRangeApply } from '../Apply';-import { INamedRange } from '../../Interfaces';+import { INamedRange } from '../../Types/Interfaces';export interface ISetNamedRangeActionData extends ISheetActionData {namedRange: INamedRange;diff --git a/packages/core/src/Sheets/Action/SetRangeDataAction.ts b/packages/core/src/Sheets/Action/SetRangeDataAction.tsindex a6b9b05880..6f838654f6 100644--- a/packages/core/src/Sheets/Action/SetRangeDataAction.ts+++ b/packages/core/src/Sheets/Action/SetRangeDataAction.ts@@ -8,7 +8,7 @@ import {CommandUnit,CommandManager,} from '../../Command';-import { ICopyToOptionsData, ICellData } from '../../Interfaces';+import { ICopyToOptionsData, ICellData } from '../../Types/Interfaces';/*** 设置数据时的类型diff --git a/packages/core/src/Sheets/Action/SetRangeFormattedValueAction.ts b/packages/core/src/Sheets/Action/SetRangeFormattedValueAction.tsindex 1b1f0fa073..1663b5ea86 100644--- a/packages/core/src/Sheets/Action/SetRangeFormattedValueAction.ts+++ b/packages/core/src/Sheets/Action/SetRangeFormattedValueAction.ts@@ -1,5 +1,5 @@import { SetRangeFormattedValue } from '../Apply';-import { ICellV, IRangeData } from '../../Interfaces';+import { ICellV, IRangeData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/SetRangeNoteAction.ts b/packages/core/src/Sheets/Action/SetRangeNoteAction.tsindex 1ddc9b240f..3cdbea16eb 100644--- a/packages/core/src/Sheets/Action/SetRangeNoteAction.ts+++ b/packages/core/src/Sheets/Action/SetRangeNoteAction.ts@@ -1,5 +1,5 @@import { SetRangeNote } from '../Apply';-import { IRangeData } from '../../Interfaces';+import { IRangeData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/SetRangeStyleAction.ts b/packages/core/src/Sheets/Action/SetRangeStyleAction.tsindex d72ac22d06..c8278f9626 100644--- a/packages/core/src/Sheets/Action/SetRangeStyleAction.ts+++ b/packages/core/src/Sheets/Action/SetRangeStyleAction.ts@@ -1,5 +1,5 @@import { SetRangeStyle } from '../Apply';-import { IRangeData, IStyleData } from '../../Interfaces';+import { IRangeData, IStyleData } from '../../Types/Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';diff --git a/packages/core/src/Sheets/Action/SetRightToLeftAction.ts b/packages/core/src/Sheets/Action/SetRightToLeftAction.tsindex 19349968c0..837c0aba14 100644--- a/packages/core/src/Sheets/Action/SetRightToLeftAction.ts+++ b/packages/core/src/Sheets/Action/SetRightToLeftAction.ts@@ -1,5 +1,5 @@import { SetRightToLeft } from '../Apply';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';import { CommandManager, CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Action/SetSelectionActivateAction.ts b/packages/core/src/Sheets/Action/SetSelectionActivateAction.tsindex 3f3ce46b82..76b91dc535 100644--- a/packages/core/src/Sheets/Action/SetSelectionActivateAction.ts+++ b/packages/core/src/Sheets/Action/SetSelectionActivateAction.ts@@ -1,4 +1,4 @@-import { IRangeData } from '../../Interfaces';+import { IRangeData } from '../../Types/Interfaces';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';import { SetSelectionActivate } from '../Apply';diff --git a/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.ts b/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.tsindex 5b6999f8c9..2a1c348452 100644--- a/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.ts+++ b/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.ts@@ -1,7 +1,7 @@import { SetWorkSheetActivate } from '../Apply';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';import { ActionOperationType } from '../../Command/ActionBase';import { CommandManager, CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Action/SetWorkSheetHideAction.ts b/packages/core/src/Sheets/Action/SetWorkSheetHideAction.tsindex 3346963a29..dc0711e0be 100644--- a/packages/core/src/Sheets/Action/SetWorkSheetHideAction.ts+++ b/packages/core/src/Sheets/Action/SetWorkSheetHideAction.ts@@ -1,5 +1,5 @@import { SetWorkSheetHideService } from '../Apply';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';import { CommandManager, CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Action/SetWorkSheetStatusAction.ts b/packages/core/src/Sheets/Action/SetWorkSheetStatusAction.tsindex 94b8c9701b..c34419e76c 100644--- a/packages/core/src/Sheets/Action/SetWorkSheetStatusAction.ts+++ b/packages/core/src/Sheets/Action/SetWorkSheetStatusAction.ts@@ -1,6 +1,6 @@import { SetWorkSheetStatus } from '../Apply';-import { ACTION_NAMES } from '../../Const/ACTION_NAMES';-import { BooleanNumber } from '../../Enum';+import { ACTION_NAMES } from '../../Types/Const/ACTION_NAMES';+import { BooleanNumber } from '../../Types/Enum';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';import { CommandManager, CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Apply/AddMerge.ts b/packages/core/src/Sheets/Apply/AddMerge.tsindex 531b8835c2..08bc0bcd3c 100644--- a/packages/core/src/Sheets/Apply/AddMerge.ts+++ b/packages/core/src/Sheets/Apply/AddMerge.ts@@ -1,5 +1,5 @@import { Merges } from '../Domain/Merges';-import { IRangeData } from '../../Interfaces';+import { IRangeData } from '../../Types/Interfaces';import { CommandUnit } from '../../Command';import { IAddMergeActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/AddNamedRange.ts b/packages/core/src/Sheets/Apply/AddNamedRange.tsindex 9afae29d40..32192a103b 100644--- a/packages/core/src/Sheets/Apply/AddNamedRange.ts+++ b/packages/core/src/Sheets/Apply/AddNamedRange.ts@@ -1,4 +1,4 @@-import { INamedRange } from '../../Interfaces';+import { INamedRange } from '../../Types/Interfaces';import { CommandUnit } from '../../Command';import { IAddNamedRangeActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/ClearRange.ts b/packages/core/src/Sheets/Apply/ClearRange.tsindex 07b3204aa0..35cf32f0ef 100644--- a/packages/core/src/Sheets/Apply/ClearRange.ts+++ b/packages/core/src/Sheets/Apply/ClearRange.ts@@ -1,4 +1,4 @@-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { Tools, ObjectMatrix } from '../../Shared';import { CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Apply/DeleteNamedRange.ts b/packages/core/src/Sheets/Apply/DeleteNamedRange.tsindex 91e2366d5e..4215d7dc42 100644--- a/packages/core/src/Sheets/Apply/DeleteNamedRange.ts+++ b/packages/core/src/Sheets/Apply/DeleteNamedRange.ts@@ -1,4 +1,4 @@-import { INamedRange } from '../../Interfaces';+import { INamedRange } from '../../Types/Interfaces';import { CommandUnit } from '../../Command';import { IDeleteNamedRangeActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/DeleteRange.ts b/packages/core/src/Sheets/Apply/DeleteRange.tsindex 7600deebee..3274299223 100644--- a/packages/core/src/Sheets/Apply/DeleteRange.ts+++ b/packages/core/src/Sheets/Apply/DeleteRange.ts@@ -1,5 +1,5 @@-import { Dimension } from '../../Enum/Dimension';-import { ICellData, IRangeData } from '../../Interfaces';+import { Dimension } from '../../Types/Enum/Dimension';+import { ICellData, IRangeData } from '../../Types/Interfaces';import { Tools } from '../../Shared';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { Nullable } from '../../Shared/Types';diff --git a/packages/core/src/Sheets/Apply/HideSheet.ts b/packages/core/src/Sheets/Apply/HideSheet.tsindex ad8e76f7a1..7b2d5a89ba 100644--- a/packages/core/src/Sheets/Apply/HideSheet.ts+++ b/packages/core/src/Sheets/Apply/HideSheet.ts@@ -1,5 +1,5 @@import { Worksheet } from '../Domain/Worksheet';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';import { CommandUnit } from '../../Command';import { ISetWorkSheetHideActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/InsertColumn.ts b/packages/core/src/Sheets/Apply/InsertColumn.tsindex b2f8c57a73..d4b4c7de36 100644--- a/packages/core/src/Sheets/Apply/InsertColumn.ts+++ b/packages/core/src/Sheets/Apply/InsertColumn.ts@@ -1,4 +1,4 @@-import { IColumnData } from '../../Interfaces';+import { IColumnData } from '../../Types/Interfaces';import { ObjectArray, ObjectArrayPrimitiveType } from '../../Shared/ObjectArray';import { CommandUnit } from '../../Command';import { IRemoveColumnAction } from '../Action';diff --git a/packages/core/src/Sheets/Apply/InsertDataColumn.ts b/packages/core/src/Sheets/Apply/InsertDataColumn.tsindex ea9cc04cf3..3dc77890ec 100644--- a/packages/core/src/Sheets/Apply/InsertDataColumn.ts+++ b/packages/core/src/Sheets/Apply/InsertDataColumn.ts@@ -1,4 +1,4 @@-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { CommandUnit } from '../../Command';import { IInsertColumnDataActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/InsertDataRow.ts b/packages/core/src/Sheets/Apply/InsertDataRow.tsindex 7195177e83..a2fede0c9a 100644--- a/packages/core/src/Sheets/Apply/InsertDataRow.ts+++ b/packages/core/src/Sheets/Apply/InsertDataRow.ts@@ -1,4 +1,4 @@-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { CommandUnit } from '../../Command';import { IInsertRowDataActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/InsertRange.ts b/packages/core/src/Sheets/Apply/InsertRange.tsindex 4be577720e..f7e4e5428c 100644--- a/packages/core/src/Sheets/Apply/InsertRange.ts+++ b/packages/core/src/Sheets/Apply/InsertRange.ts@@ -1,5 +1,5 @@-import { Dimension } from '../../Enum';-import { ICellData, IRangeData } from '../../Interfaces';+import { Dimension } from '../../Types/Enum';+import { ICellData, IRangeData } from '../../Types/Interfaces';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared';import { CommandUnit } from '../../Command';import { IInsertRangeActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/InsertRow.ts b/packages/core/src/Sheets/Apply/InsertRow.tsindex cfd968e3f2..70ed8da008 100644--- a/packages/core/src/Sheets/Apply/InsertRow.ts+++ b/packages/core/src/Sheets/Apply/InsertRow.ts@@ -1,4 +1,4 @@-import { IRowData } from '../../Interfaces';+import { IRowData } from '../../Types/Interfaces';import { ObjectArray, ObjectArrayPrimitiveType } from '../../Shared';import { CommandUnit } from '../../Command';import { IInsertRowActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/InsertSheet.ts b/packages/core/src/Sheets/Apply/InsertSheet.tsindex a496b89d4c..c5b9883114 100644--- a/packages/core/src/Sheets/Apply/InsertSheet.ts+++ b/packages/core/src/Sheets/Apply/InsertSheet.ts@@ -1,5 +1,5 @@import { Workbook, Worksheet } from '../Domain';-import { IWorksheetConfig } from '../../Interfaces';+import { IWorksheetConfig } from '../../Types/Interfaces';import { CommandUnit } from '../../Command';import { IInsertSheetActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/RemoveColumn.ts b/packages/core/src/Sheets/Apply/RemoveColumn.tsindex dac296231d..38d120cf78 100644--- a/packages/core/src/Sheets/Apply/RemoveColumn.ts+++ b/packages/core/src/Sheets/Apply/RemoveColumn.ts@@ -1,4 +1,4 @@-import { IColumnData } from '../../Interfaces';+import { IColumnData } from '../../Types/Interfaces';import { ObjectArray, ObjectArrayPrimitiveType } from '../../Shared';import { CommandUnit } from '../../Command';import { IRemoveColumnAction } from '../Action';diff --git a/packages/core/src/Sheets/Apply/RemoveColumnData.ts b/packages/core/src/Sheets/Apply/RemoveColumnData.tsindex 763f0cd9f5..389bbfb472 100644--- a/packages/core/src/Sheets/Apply/RemoveColumnData.ts+++ b/packages/core/src/Sheets/Apply/RemoveColumnData.ts@@ -1,4 +1,4 @@-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { CommandUnit } from '../../Command';import { IRemoveColumnDataAction } from '../Action';diff --git a/packages/core/src/Sheets/Apply/RemoveMerge.ts b/packages/core/src/Sheets/Apply/RemoveMerge.tsindex 859e9a77f4..0f3eb04843 100644--- a/packages/core/src/Sheets/Apply/RemoveMerge.ts+++ b/packages/core/src/Sheets/Apply/RemoveMerge.ts@@ -1,4 +1,4 @@-import { IRangeData } from '../../Interfaces';+import { IRangeData } from '../../Types/Interfaces';import { CommandUnit } from '../../Command';import { IRemoveMergeActionData } from '../Action';import { Rectangle } from '../../Shared';diff --git a/packages/core/src/Sheets/Apply/RemoveRow.ts b/packages/core/src/Sheets/Apply/RemoveRow.tsindex b84edc8c08..637d35b354 100644--- a/packages/core/src/Sheets/Apply/RemoveRow.ts+++ b/packages/core/src/Sheets/Apply/RemoveRow.ts@@ -1,4 +1,4 @@-import { IRowData } from '../../Interfaces';+import { IRowData } from '../../Types/Interfaces';import { ObjectArray, ObjectArrayPrimitiveType } from '../../Shared';import { CommandUnit } from '../../Command';import { IRemoveRowActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/RemoveRowData.ts b/packages/core/src/Sheets/Apply/RemoveRowData.tsindex 000d3ec018..f09cd01cd2 100644--- a/packages/core/src/Sheets/Apply/RemoveRowData.ts+++ b/packages/core/src/Sheets/Apply/RemoveRowData.ts@@ -1,4 +1,4 @@-import { ICellData } from '../../Interfaces';+import { ICellData } from '../../Types/Interfaces';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { CommandUnit } from '../../Command';import { IRemoveRowDataActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/RemoveSheet.ts b/packages/core/src/Sheets/Apply/RemoveSheet.tsindex 1b649b1a28..0c1db9bed4 100644--- a/packages/core/src/Sheets/Apply/RemoveSheet.ts+++ b/packages/core/src/Sheets/Apply/RemoveSheet.ts@@ -1,5 +1,5 @@import { Workbook } from '../Domain';-import { IWorksheetConfig } from '../../Interfaces';+import { IWorksheetConfig } from '../../Types/Interfaces';import { CommandUnit } from '../../Command';import { IRemoveSheetActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/SetBorder.ts b/packages/core/src/Sheets/Apply/SetBorder.tsindex 516c34f8d2..82e4c7f6b5 100644--- a/packages/core/src/Sheets/Apply/SetBorder.ts+++ b/packages/core/src/Sheets/Apply/SetBorder.ts@@ -1,5 +1,5 @@import { Styles } from '../Domain';-import { ICellData, IStyleData } from '../../Interfaces';+import { ICellData, IStyleData } from '../../Types/Interfaces';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared';import { CommandUnit } from '../../Command';import { BorderStyleData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/SetNamedRange.ts b/packages/core/src/Sheets/Apply/SetNamedRange.tsindex 68de487a47..799a19a067 100644--- a/packages/core/src/Sheets/Apply/SetNamedRange.ts+++ b/packages/core/src/Sheets/Apply/SetNamedRange.ts@@ -1,4 +1,4 @@-import { INamedRange } from '../../Interfaces/INamedRange';+import { INamedRange } from '../../Types/Interfaces/INamedRange';import { CommandUnit } from '../../Command';import { ISetNamedRangeActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/SetRangeData.ts b/packages/core/src/Sheets/Apply/SetRangeData.tsindex 6fee661933..7176f9af2d 100644--- a/packages/core/src/Sheets/Apply/SetRangeData.ts+++ b/packages/core/src/Sheets/Apply/SetRangeData.ts@@ -1,4 +1,4 @@-import { ICellData, IStyleData } from '../../Interfaces';+import { ICellData, IStyleData } from '../../Types/Interfaces';import { Nullable, Tools } from '../../Shared';import { ObjectMatrix } from '../../Shared/ObjectMatrix';import { mergeStyle, transformStyle } from './SetRangeStyle';diff --git a/packages/core/src/Sheets/Apply/SetRangeFormattedValue.ts b/packages/core/src/Sheets/Apply/SetRangeFormattedValue.tsindex 6c4f5978bf..9bca43b946 100644--- a/packages/core/src/Sheets/Apply/SetRangeFormattedValue.ts+++ b/packages/core/src/Sheets/Apply/SetRangeFormattedValue.ts@@ -1,4 +1,4 @@-import { ICellData, ICellV, IRangeData } from '../../Interfaces';+import { ICellData, ICellV, IRangeData } from '../../Types/Interfaces';import { Nullable, Tools } from '../../Shared';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Apply/SetRangeNote.ts b/packages/core/src/Sheets/Apply/SetRangeNote.tsindex 00909ee299..bf5397d375 100644--- a/packages/core/src/Sheets/Apply/SetRangeNote.ts+++ b/packages/core/src/Sheets/Apply/SetRangeNote.ts@@ -1,4 +1,4 @@-import { ICellData, IRangeData } from '../../Interfaces';+import { ICellData, IRangeData } from '../../Types/Interfaces';import { Nullable, Tools } from '../../Shared';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { CommandUnit } from '../../Command';diff --git a/packages/core/src/Sheets/Apply/SetRangeStyle.ts b/packages/core/src/Sheets/Apply/SetRangeStyle.tsindex 58d16f2ba8..2183a7e4c2 100644--- a/packages/core/src/Sheets/Apply/SetRangeStyle.ts+++ b/packages/core/src/Sheets/Apply/SetRangeStyle.ts@@ -1,247 +1,247 @@-import { ITextStyle } from '../../Interfaces/IDocumentData';-import { Styles } from '../Domain';-import { IRangeData, ICellData, IDocumentData } from '../../Interfaces';-import { IBorderData, IStyleData } from '../../Interfaces/IStyleData';-import {- IKeyValue,- Nullable,- ObjectMatrix,- ObjectMatrixPrimitiveType,- Tools,-} from '../../Shared';--/**- * Set the style. The style sent by the user will be merged into the original style object. If you want to delete a style, you need to explicitly set it to null- * @param param0- * @returns- *cellMatrix: ,- addMatrix: ,- rangeData: IRangeData- * @internal- */-export function SetRangeStyle(- cellMatrix: ObjectMatrix<ICellData>,- value: ObjectMatrixPrimitiveType<IStyleData>,- rangeData: IRangeData,- styles: Styles-): ObjectMatrixPrimitiveType<IStyleData> {- const { startRow, endRow, startColumn, endColumn } = rangeData;- const result = new ObjectMatrix<IStyleData>();- for (let r = startRow; r <= endRow; r++) {- const rowResult = [];- for (let c = startColumn; c <= endColumn; c++) {- const cell = cellMatrix.getValue(r, c) || {};- // use null to clear style- const old = styles.getStyleByCell(cell);-- if (old == null) {- // clear- delete cell.s;- }-- // set style- const merge = mergeStyle(- old,- value[r - startRow][c - startColumn] as Nullable<IStyleData>- );-- // then remove null- merge && Tools.removeNull(merge);-- if (Tools.isEmptyObject(merge)) {- delete cell.s;- } else {- cell.s = styles.setValue(merge);- }-- // When the rich text sets the cell style, you need to modify the style of all rich text- // TODO redo/undo use setRangeData to undo rich text setting- if (cell.p) {- mergeRichTextStyle(- cell.p,- value[r - startRow][c - startColumn] as Nullable<IStyleData>- );- }-- cellMatrix.setValue(r, c, cell);-- // store old data- result.setValue(- r - startRow,- c - startColumn,- transformStyle(- old,- value[r - startRow][c - startColumn] as Nullable<IStyleData>- )- );- }-- // result.push(rowResult);- }- return result.getData();-}--/**- * Convert old style data for storage- * @param style- */-export function transformStyle(- oldStyle: Nullable<IStyleData>,- newStyle: Nullable<IStyleData>-): Nullable<IStyleData> {- const backupStyle = transformNormalKey(oldStyle, newStyle);- return backupStyle;-}-/**- * Convert old style normal key for storage- *- * @param style- */-export function transformNormalKey(- oldStyle: Nullable<IStyleData>,- newStyle: Nullable<IStyleData>-): Nullable<IStyleData> {- // If there is no newly set style, directly store the historical style- if (!newStyle || !Object.keys(newStyle).length) {- return oldStyle;- }- const backupStyle = Tools.deepClone(oldStyle) || {};-- for (const k in newStyle) {- if (k === 'bd') {- backupStyle[k] = transformBorders(backupStyle[k] || {}, newStyle[k]);- }- // 1. To modify the existing style,we need original setting to undo- // 2. Newly set the style, we need null to undo- else if (!(k in backupStyle)) {- backupStyle[k] = null;- }- }- return backupStyle;-}-/**- * Convert old style border for storage- *-- * @param style- */-export function transformBorders(- oldBorders: IBorderData,- newBorders: Nullable<IBorderData>-): IBorderData {- // If there is no newly set border, directly store the historical border- if (!newBorders || !Object.keys(newBorders).length) {- return oldBorders;- }-- for (const k in newBorders) {- // 1. To modify the existing border,we need original setting to undo- // 2. Newly set the border, we need null to undo- if (!(k in oldBorders)) {- (oldBorders as IKeyValue)[k] = null;- }- }-- return oldBorders;-}--/**- * merge new style to old style- *- * @param oldStyle- * @param newStyle- */-export function mergeStyle(- oldStyle: Nullable<IStyleData>,- newStyle: Nullable<IStyleData>,- isRichText: boolean = false-): Nullable<IStyleData> {- // clear style- if (newStyle === null) return newStyle;- // don't operate- if (newStyle === undefined) return oldStyle;-- const backupStyle = Tools.deepClone(oldStyle) || {};-- for (const k in newStyle) {- if (isRichText && ['bd', 'tr', 'td', 'ht', 'vt', 'tb', 'pd'].includes(k)) {- continue;- }- // you can only choose one of the themeColor and rgbColor of the border setting- if (k in backupStyle && k === 'bd') {- backupStyle[k] = Object.assign(backupStyle[k], newStyle[k]);- } else {- backupStyle[k] = (newStyle as IKeyValue)[k];-- // overline/strikethrough/underline add color- if ('cl' in backupStyle) {- if (['ul', 'ol', 'st'].includes(k)) {- backupStyle[k].cl = backupStyle.cl;- }- }- }- }- return backupStyle;-}--/**- * Find the text style of all paragraphs and modify it to the new style- * @param p- * @param newStyle- */-export function mergeRichTextStyle(- p: IDocumentData,- newStyle: Nullable<IStyleData>-) {- // p.body?.blockElements.forEach((blockElement) => {- // if (blockElement.blockType === 0) {- // const paragraph = blockElement.paragraph;- // paragraph?.elements.forEach((element) => {- // if (!element.tr) {- // element.tr = {};- // }-- // const textRun = element.tr as ITextRun;-- // if (!textRun.ts) {- // textRun.ts = {};- // }-- // const oldStyle = textRun.ts;-- // const merge = mergeStyle(- // oldStyle as Nullable<IStyleData>,- // newStyle,- // true- // );-- // // then remove null- // merge && Tools.removeNull(merge);-- // if (Tools.isEmptyObject(merge)) {- // delete textRun.ts;- // } else {- // textRun.ts = merge as ITextStyle;- // }- // });- // }- // });- p.body?.textRuns?.forEach((textRun) => {- if (!textRun.ts) {- textRun.ts = {};- }-- const oldStyle = textRun.ts || {};-- const merge = mergeStyle(oldStyle as Nullable<IStyleData>, newStyle, true);-- // then remove null- merge && Tools.removeNull(merge);-- if (Tools.isEmptyObject(merge)) {- delete textRun.ts;- } else {- textRun.ts = merge as ITextStyle;- }- });-}+import { ITextStyle } from '../../Types/Interfaces/IDocumentData';+import { Styles } from '../Domain';+import { IRangeData, ICellData, IDocumentData } from '../../Types/Interfaces';+import { IBorderData, IStyleData } from '../../Types/Interfaces/IStyleData';+import {+ IKeyValue,+ Nullable,+ ObjectMatrix,+ ObjectMatrixPrimitiveType,+ Tools,+} from '../../Shared';++/**+ * Set the style. The style sent by the user will be merged into the original style object. If you want to delete a style, you need to explicitly set it to null+ * @param param0+ * @returns+ *cellMatrix: ,+ addMatrix: ,+ rangeData: IRangeData+ * @internal+ */+export function SetRangeStyle(+ cellMatrix: ObjectMatrix<ICellData>,+ value: ObjectMatrixPrimitiveType<IStyleData>,+ rangeData: IRangeData,+ styles: Styles+): ObjectMatrixPrimitiveType<IStyleData> {+ const { startRow, endRow, startColumn, endColumn } = rangeData;+ const result = new ObjectMatrix<IStyleData>();+ for (let r = startRow; r <= endRow; r++) {+ const rowResult = [];+ for (let c = startColumn; c <= endColumn; c++) {+ const cell = cellMatrix.getValue(r, c) || {};+ // use null to clear style+ const old = styles.getStyleByCell(cell);++ if (old == null) {+ // clear+ delete cell.s;+ }++ // set style+ const merge = mergeStyle(+ old,+ value[r - startRow][c - startColumn] as Nullable<IStyleData>+ );++ // then remove null+ merge && Tools.removeNull(merge);++ if (Tools.isEmptyObject(merge)) {+ delete cell.s;+ } else {+ cell.s = styles.setValue(merge);+ }++ // When the rich text sets the cell style, you need to modify the style of all rich text+ // TODO redo/undo use setRangeData to undo rich text setting+ if (cell.p) {+ mergeRichTextStyle(+ cell.p,+ value[r - startRow][c - startColumn] as Nullable<IStyleData>+ );+ }++ cellMatrix.setValue(r, c, cell);++ // store old data+ result.setValue(+ r - startRow,+ c - startColumn,+ transformStyle(+ old,+ value[r - startRow][c - startColumn] as Nullable<IStyleData>+ )+ );+ }++ // result.push(rowResult);+ }+ return result.getData();+}++/**+ * Convert old style data for storage+ * @param style+ */+export function transformStyle(+ oldStyle: Nullable<IStyleData>,+ newStyle: Nullable<IStyleData>+): Nullable<IStyleData> {+ const backupStyle = transformNormalKey(oldStyle, newStyle);+ return backupStyle;+}+/**+ * Convert old style normal key for storage+ *+ * @param style+ */+export function transformNormalKey(+ oldStyle: Nullable<IStyleData>,+ newStyle: Nullable<IStyleData>+): Nullable<IStyleData> {+ // If there is no newly set style, directly store the historical style+ if (!newStyle || !Object.keys(newStyle).length) {+ return oldStyle;+ }+ const backupStyle = Tools.deepClone(oldStyle) || {};++ for (const k in newStyle) {+ if (k === 'bd') {+ backupStyle[k] = transformBorders(backupStyle[k] || {}, newStyle[k]);+ }+ // 1. To modify the existing style,we need original setting to undo+ // 2. Newly set the style, we need null to undo+ else if (!(k in backupStyle)) {+ backupStyle[k] = null;+ }+ }+ return backupStyle;+}+/**+ * Convert old style border for storage+ *++ * @param style+ */+export function transformBorders(+ oldBorders: IBorderData,+ newBorders: Nullable<IBorderData>+): IBorderData {+ // If there is no newly set border, directly store the historical border+ if (!newBorders || !Object.keys(newBorders).length) {+ return oldBorders;+ }++ for (const k in newBorders) {+ // 1. To modify the existing border,we need original setting to undo+ // 2. Newly set the border, we need null to undo+ if (!(k in oldBorders)) {+ (oldBorders as IKeyValue)[k] = null;+ }+ }++ return oldBorders;+}++/**+ * merge new style to old style+ *+ * @param oldStyle+ * @param newStyle+ */+export function mergeStyle(+ oldStyle: Nullable<IStyleData>,+ newStyle: Nullable<IStyleData>,+ isRichText: boolean = false+): Nullable<IStyleData> {+ // clear style+ if (newStyle === null) return newStyle;+ // don't operate+ if (newStyle === undefined) return oldStyle;++ const backupStyle = Tools.deepClone(oldStyle) || {};++ for (const k in newStyle) {+ if (isRichText && ['bd', 'tr', 'td', 'ht', 'vt', 'tb', 'pd'].includes(k)) {+ continue;+ }+ // you can only choose one of the themeColor and rgbColor of the border setting+ if (k in backupStyle && k === 'bd') {+ backupStyle[k] = Object.assign(backupStyle[k], newStyle[k]);+ } else {+ backupStyle[k] = (newStyle as IKeyValue)[k];++ // overline/strikethrough/underline add color+ if ('cl' in backupStyle) {+ if (['ul', 'ol', 'st'].includes(k)) {+ backupStyle[k].cl = backupStyle.cl;+ }+ }+ }+ }+ return backupStyle;+}++/**+ * Find the text style of all paragraphs and modify it to the new style+ * @param p+ * @param newStyle+ */+export function mergeRichTextStyle(+ p: IDocumentData,+ newStyle: Nullable<IStyleData>+) {+ // p.body?.blockElements.forEach((blockElement) => {+ // if (blockElement.blockType === 0) {+ // const paragraph = blockElement.paragraph;+ // paragraph?.elements.forEach((element) => {+ // if (!element.tr) {+ // element.tr = {};+ // }++ // const textRun = element.tr as ITextRun;++ // if (!textRun.ts) {+ // textRun.ts = {};+ // }++ // const oldStyle = textRun.ts;++ // const merge = mergeStyle(+ // oldStyle as Nullable<IStyleData>,+ // newStyle,+ // true+ // );++ // // then remove null+ // merge && Tools.removeNull(merge);++ // if (Tools.isEmptyObject(merge)) {+ // delete textRun.ts;+ // } else {+ // textRun.ts = merge as ITextStyle;+ // }+ // });+ // }+ // });+ p.body?.textRuns?.forEach((textRun) => {+ if (!textRun.ts) {+ textRun.ts = {};+ }++ const oldStyle = textRun.ts || {};++ const merge = mergeStyle(oldStyle as Nullable<IStyleData>, newStyle, true);++ // then remove null+ merge && Tools.removeNull(merge);++ if (Tools.isEmptyObject(merge)) {+ delete textRun.ts;+ } else {+ textRun.ts = merge as ITextStyle;+ }+ });+}diff --git a/packages/core/src/Sheets/Apply/SetRightToLeft.ts b/packages/core/src/Sheets/Apply/SetRightToLeft.tsindex c021f7df03..a157838626 100644--- a/packages/core/src/Sheets/Apply/SetRightToLeft.ts+++ b/packages/core/src/Sheets/Apply/SetRightToLeft.ts@@ -1,5 +1,5 @@import { Worksheet } from '../Domain';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';import { CommandUnit } from '../../Command';import { ISetRightToLeftActionData } from '../Action';diff --git a/packages/core/src/Sheets/Apply/SetSelectionActivate.ts b/packages/core/src/Sheets/Apply/SetSelectionActivate.tsindex fcd78e7d8b..3d600bd18c 100644--- a/packages/core/src/Sheets/Apply/SetSelectionActivate.ts+++ b/packages/core/src/Sheets/Apply/SetSelectionActivate.ts@@ -1,6 +1,6 @@import { ISetSelectionActivateServiceData } from '../Action';import { Worksheet } from '../Domain/Worksheet';-import { IRangeData } from '../../Interfaces/IRangeData';+import { IRangeData } from '../../Types/Interfaces/IRangeData';/***diff --git a/packages/core/src/Sheets/Apply/SetWorkSheetActivate.ts b/packages/core/src/Sheets/Apply/SetWorkSheetActivate.tsindex 3749e4b247..664e5eb5e1 100644--- a/packages/core/src/Sheets/Apply/SetWorkSheetActivate.ts+++ b/packages/core/src/Sheets/Apply/SetWorkSheetActivate.ts@@ -1,5 +1,5 @@import { Worksheet } from '../Domain/Worksheet';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';import { ISheetStatus } from '../Action';/**diff --git a/packages/core/src/Sheets/Apply/SetWorkSheetStatus.ts b/packages/core/src/Sheets/Apply/SetWorkSheetStatus.tsindex f2bcd34028..4120a67f8e 100644--- a/packages/core/src/Sheets/Apply/SetWorkSheetStatus.ts+++ b/packages/core/src/Sheets/Apply/SetWorkSheetStatus.ts@@ -1,5 +1,5 @@import { Worksheet } from '../Domain/Worksheet';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';/***diff --git a/packages/core/src/Sheets/Domain/Color.ts b/packages/core/src/Sheets/Domain/Color.tsindex cb34fc8d5c..afcdec8f71 100644--- a/packages/core/src/Sheets/Domain/Color.ts+++ b/packages/core/src/Sheets/Domain/Color.ts@@ -1,442 +1,442 @@-import { ThemeColorType, ColorType, ThemeColors } from '../../Enum';-import { Nullable } from '../../Shared';-import { ColorBuilder } from './ColorBuilder';-import { THEME_COLORS } from '../../Const/THEME_COLOR_MAP';--export class Color {- protected _builder: ColorBuilder;-- constructor(builder: ColorBuilder) {- this._builder = builder;- }-- static rgbColorToHexValue(color: RgbColor): string {- return `#${(- (1 << 24) +- (color.getRed() << 16) +- (color.getGreen() << 8) +- color.getBlue()- )- .toString(16)- .slice(1)}`;- }-- static hexValueToRgbColor(hexValue: string): RgbColor {- if (hexValue) {- if (hexValue.indexOf('#') > -1) {- hexValue = hexValue.substring(1);- }- } else {- hexValue = '#000000';- }- let r = +`0x${hexValue[0]}${hexValue[1]}`;- let g = +`0x${hexValue[2]}${hexValue[3]}`;- let b = +`0x${hexValue[4]}${hexValue[5]}`;- return new ColorBuilder().setRgbColor(`rgb(${r},${g},${b})`).asRgbColor();- }-- static hexToRgbString(hex: string): Nullable<string> {- // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")- const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;- hex = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);- let string = null;- if (result) {- const r = parseInt(result[1], 16);- const g = parseInt(result[2], 16);- const b = parseInt(result[3], 16);- string = `rgba(${r},${g},${b})`;- }- return string;- }-- asRgbColor(): RgbColor {- return this._builder.asRgbColor();- }-- asThemeColor(): ThemeColor {- return this._builder.asThemeColor();- }-- getColorType(): ColorType {- return this._builder.getColorType();- }-- clone(): Color {- return new Color(this._builder);- }-- equals(color: Color): boolean {- return false;- }-}--export class HLSColor {- private _saturation: number;-- private _hue: number;-- private _lightness: number;-- private _alpha: number;-- constructor(rgbColor: RgbColor) {- const red = rgbColor.getRed() / 255;- const green = rgbColor.getGreen() / 255;- const blue = rgbColor.getBlue() / 255;- const alpha = rgbColor.getAlpha() / 255;-- const min = Math.min(red, Math.min(green, blue));- const max = Math.max(red, Math.max(green, blue));- const delta = max - min;-- if (max === min) {- this._hue = 0;- this._saturation = 0;- this._lightness = max;- return;- }-- this._lightness = (min + max) / 2;-- if (this._lightness < 0.5) {- this._saturation = delta / (max + min);- } else {- this._saturation = delta / (2.0 - max - min);- }-- if (red === max) {- this._hue = (green - blue) / delta;- }-- if (green === max) {- this._hue = 2.0 + (blue - red) / delta;- }-- if (blue === max) {- this._hue = 4.0 + (red - green) / delta;- }-- this._hue *= 60;-- if (this._hue < 0) {- this._hue += 360;- }-- this._alpha = alpha;- }-- asRgbColor(): RgbColor {- const builder = new ColorBuilder();-- if (this._saturation === 0) {- builder.setRgbColor(- `rgba(${this._lightness * 255},${this._lightness * 255},${- this._lightness * 255- },${this._alpha * 255})`- );- return builder.asRgbColor();- }-- let t1;- if (this._lightness < 0.5) {- t1 = this._lightness * (1.0 + this._saturation);- } else {- t1 =- this._lightness +- this._saturation -- this._lightness * this._saturation;- }-- const t2 = 2.0 * this._lightness - t1;- const hue = this._hue / 360;-- const tR = hue + 1.0 / 3.0;- const red = this.setColor(t1, t2, tR);- const green = this.setColor(t1, t2, hue);- const tB = hue - 1.0 / 3.0;- const blue = this.setColor(t1, t2, tB);-- builder.setRgbColor(- `rgba(${Math.round(red * 255)},${Math.round(green * 255)},${Math.round(- blue * 255- )},${this._alpha * 255})`- );- return builder.asRgbColor();- }-- getLightness() {- return this._lightness;- }-- getHue() {- return this._hue;- }-- getSaturation() {- return this._saturation;- }-- getAlpha() {- return this._alpha;- }-- setColor(t1: number, t2: number, t3: number): number {- if (t3 < 0) {- t3 += 1.0;- }-- if (t3 > 1) {- t3 -= 1.0;- }-- let color: number;-- if (6.0 * t3 < 1) {- color = t2 + (t1 - t2) * 6.0 * t3;- } else if (2.0 * t3 < 1) {- color = t1;- } else if (3.0 * t3 < 2) {- color = t2 + (t1 - t2) * (2.0 / 3.0 - t3) * 6.0;- } else {- color = t2;- }-- return color;- }-- setLightness(lightness: number): void {- this._lightness = lightness;- }-}--export class RgbColor extends Color {- static RGB_COLOR_AMT: number = 0;-- static RGBA_EXTRACT: RegExp = new RegExp(- `\\s*rgba\\s*\\((\\s*\\d+\\s*),(\\s*\\d+\\s*),(\\s*\\d+\\s*),(\\s*\\d.\\d|\\d\\s*)\\)\\s*`- );-- static RGB_EXTRACT: RegExp = new RegExp(- `\\s*rgb\\s*\\((\\s*\\d+\\s*),(\\s*\\d+\\s*),(\\s*\\d+\\s*)\\)\\s*`- );-- private _cssString: string;-- private _red: number;-- private _green: number;-- private _blue: number;-- private _alpha: number;-- constructor(cssString: string, builder: ColorBuilder) {- super(builder);-- let match = cssString.match(RgbColor.RGBA_EXTRACT);-- if (match) {- const red = +match[1];- const green = +match[2];- const blue = +match[3];- const alpha = +match[4];-- this._cssString = cssString;- this._red = red;- this._green = green;- this._blue = blue;- this._alpha = alpha;- return;- }-- match = cssString.match(RgbColor.RGB_EXTRACT);-- if (match) {- const red = +match[1];- const green = +match[2];- const blue = +match[3];-- this._cssString = cssString;- this._red = red;- this._green = green;- this._blue = blue;- this._alpha = 1;- return;- }-- throw new Error('Invalid rgba or rgb color');- }-- asHexString(): string {- return Color.rgbColorToHexValue(this);- }-- getRed(): number {- let r = this._red + RgbColor.RGB_COLOR_AMT;-- if (r > 255) {- r = 255;- } else if (r < 0) {- r = 0;- }-- return r;- }-- getGreen(): number {- let g = this._green + RgbColor.RGB_COLOR_AMT;-- if (g > 255) {- g = 255;- } else if (g < 0) {- g = 0;- }-- return g;- }-- getBlue(): number {- let b = this._blue + RgbColor.RGB_COLOR_AMT;-- if (b > 255) {- b = 255;- } else if (b < 0) {- b = 0;- }-- return b;- }-- getAlpha(): number {- return this._alpha;- }-- getColorType(): ColorType {- return ColorType.RGB;- }-- clone(): RgbColor {- return new RgbColor(this._cssString, this._builder);- }-- asThemeColor(): ThemeColor {- throw new Error('rgb color not support to themeColor');- }-- equals(color: Color): boolean {- if (color instanceof RgbColor) {- return (- color._red === this._red &&- color._blue === this._blue &&- color._green === this._green &&- color._alpha === this._alpha- );- }- return false;- }-- getCssString() {- return this._cssString;- }-}--export class ThemeColor extends Color {- private static _cacheThemeColor = new Map<- ThemeColors,- Map<ThemeColorType, RgbColor>- >();-- private _themeColorType: ThemeColorType;-- private _themeTint: number;-- private _themeColors: ThemeColors;-- constructor(- theme: ThemeColorType,- themeTint: number,- themeColors: ThemeColors,- builder: ColorBuilder- ) {- super(builder);- this._themeColorType = theme;- this._themeTint = themeTint;- this._themeColors = themeColors;- }-- lumValue(tint: number, lum: number) {- if (tint == null) {- return lum;- }-- let value: number;-- if (tint < 0) {- value = lum * (1.0 + tint);- } else {- value = lum * (1.0 - tint) + (255 - 255 * (1.0 - tint));- }-- return value;- }-- asRgbColor(): RgbColor {- const themeColors = THEME_COLORS[this._themeColors];- if (themeColors == null) {- throw new Error('not find themeColors type');- }-- const hexValue = themeColors[this._themeColorType];- if (hexValue == null) {- throw new Error('not find themeColors value');- }-- let themeCache;- if (ThemeColor._cacheThemeColor.has(this._themeColors)) {- themeCache = ThemeColor._cacheThemeColor.get(this._themeColors) as Map<- ThemeColorType,- RgbColor- >;- if (themeCache.has(this._themeColorType)) {- return themeCache.get(this._themeColorType) as RgbColor;- }- } else {- themeCache = new Map<ThemeColorType, RgbColor>();- ThemeColor._cacheThemeColor.set(this._themeColors, themeCache);- }-- const hlsColor = new HLSColor(Color.hexValueToRgbColor(hexValue));- hlsColor.setLightness(- this.lumValue(this._themeTint, hlsColor.getLightness() * 255) / 255- );- const rgbColor = hlsColor.asRgbColor();- themeCache.set(this._themeColorType, rgbColor);-- return rgbColor;- }-- clone(): ThemeColor {- return new ThemeColor(- this._themeColorType,- this._themeTint,- this._themeColors,- this._builder- );- }-- equals(color: Color): boolean {- if (color instanceof ThemeColor) {- return color._themeColorType === this._themeColorType;- }- return false;- }-- getColorType(): ColorType {- return ColorType.THEME;- }-- getThemeColorType(): ThemeColorType {- return this._themeColorType;- }-}+import { ThemeColorType, ColorType, ThemeColors } from '../../Types/Enum';+import { Nullable } from '../../Shared';+import { ColorBuilder } from './ColorBuilder';+import { THEME_COLORS } from '../../Types/Const/THEME_COLOR_MAP';++export class Color {+ protected _builder: ColorBuilder;++ constructor(builder: ColorBuilder) {+ this._builder = builder;+ }++ static rgbColorToHexValue(color: RgbColor): string {+ return `#${(+ (1 << 24) ++ (color.getRed() << 16) ++ (color.getGreen() << 8) ++ color.getBlue()+ )+ .toString(16)+ .slice(1)}`;+ }++ static hexValueToRgbColor(hexValue: string): RgbColor {+ if (hexValue) {+ if (hexValue.indexOf('#') > -1) {+ hexValue = hexValue.substring(1);+ }+ } else {+ hexValue = '#000000';+ }+ let r = +`0x${hexValue[0]}${hexValue[1]}`;+ let g = +`0x${hexValue[2]}${hexValue[3]}`;+ let b = +`0x${hexValue[4]}${hexValue[5]}`;+ return new ColorBuilder().setRgbColor(`rgb(${r},${g},${b})`).asRgbColor();+ }++ static hexToRgbString(hex: string): Nullable<string> {+ // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")+ const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;+ hex = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);+ let string = null;+ if (result) {+ const r = parseInt(result[1], 16);+ const g = parseInt(result[2], 16);+ const b = parseInt(result[3], 16);+ string = `rgba(${r},${g},${b})`;+ }+ return string;+ }++ asRgbColor(): RgbColor {+ return this._builder.asRgbColor();+ }++ asThemeColor(): ThemeColor {+ return this._builder.asThemeColor();+ }++ getColorType(): ColorType {+ return this._builder.getColorType();+ }++ clone(): Color {+ return new Color(this._builder);+ }++ equals(color: Color): boolean {+ return false;+ }+}++export class HLSColor {+ private _saturation: number;++ private _hue: number;++ private _lightness: number;++ private _alpha: number;++ constructor(rgbColor: RgbColor) {+ const red = rgbColor.getRed() / 255;+ const green = rgbColor.getGreen() / 255;+ const blue = rgbColor.getBlue() / 255;+ const alpha = rgbColor.getAlpha() / 255;++ const min = Math.min(red, Math.min(green, blue));+ const max = Math.max(red, Math.max(green, blue));+ const delta = max - min;++ if (max === min) {+ this._hue = 0;+ this._saturation = 0;+ this._lightness = max;+ return;+ }++ this._lightness = (min + max) / 2;++ if (this._lightness < 0.5) {+ this._saturation = delta / (max + min);+ } else {+ this._saturation = delta / (2.0 - max - min);+ }++ if (red === max) {+ this._hue = (green - blue) / delta;+ }++ if (green === max) {+ this._hue = 2.0 + (blue - red) / delta;+ }++ if (blue === max) {+ this._hue = 4.0 + (red - green) / delta;+ }++ this._hue *= 60;++ if (this._hue < 0) {+ this._hue += 360;+ }++ this._alpha = alpha;+ }++ asRgbColor(): RgbColor {+ const builder = new ColorBuilder();++ if (this._saturation === 0) {+ builder.setRgbColor(+ `rgba(${this._lightness * 255},${this._lightness * 255},${+ this._lightness * 255+ },${this._alpha * 255})`+ );+ return builder.asRgbColor();+ }++ let t1;+ if (this._lightness < 0.5) {+ t1 = this._lightness * (1.0 + this._saturation);+ } else {+ t1 =+ this._lightness ++ this._saturation -+ this._lightness * this._saturation;+ }++ const t2 = 2.0 * this._lightness - t1;+ const hue = this._hue / 360;++ const tR = hue + 1.0 / 3.0;+ const red = this.setColor(t1, t2, tR);+ const green = this.setColor(t1, t2, hue);+ const tB = hue - 1.0 / 3.0;+ const blue = this.setColor(t1, t2, tB);++ builder.setRgbColor(+ `rgba(${Math.round(red * 255)},${Math.round(green * 255)},${Math.round(+ blue * 255+ )},${this._alpha * 255})`+ );+ return builder.asRgbColor();+ }++ getLightness() {+ return this._lightness;+ }++ getHue() {+ return this._hue;+ }++ getSaturation() {+ return this._saturation;+ }++ getAlpha() {+ return this._alpha;+ }++ setColor(t1: number, t2: number, t3: number): number {+ if (t3 < 0) {+ t3 += 1.0;+ }++ if (t3 > 1) {+ t3 -= 1.0;+ }++ let color: number;++ if (6.0 * t3 < 1) {+ color = t2 + (t1 - t2) * 6.0 * t3;+ } else if (2.0 * t3 < 1) {+ color = t1;+ } else if (3.0 * t3 < 2) {+ color = t2 + (t1 - t2) * (2.0 / 3.0 - t3) * 6.0;+ } else {+ color = t2;+ }++ return color;+ }++ setLightness(lightness: number): void {+ this._lightness = lightness;+ }+}++export class RgbColor extends Color {+ static RGB_COLOR_AMT: number = 0;++ static RGBA_EXTRACT: RegExp = new RegExp(+ `\\s*rgba\\s*\\((\\s*\\d+\\s*),(\\s*\\d+\\s*),(\\s*\\d+\\s*),(\\s*\\d.\\d|\\d\\s*)\\)\\s*`+ );++ static RGB_EXTRACT: RegExp = new RegExp(+ `\\s*rgb\\s*\\((\\s*\\d+\\s*),(\\s*\\d+\\s*),(\\s*\\d+\\s*)\\)\\s*`+ );++ private _cssString: string;++ private _red: number;++ private _green: number;++ private _blue: number;++ private _alpha: number;++ constructor(cssString: string, builder: ColorBuilder) {+ super(builder);++ let match = cssString.match(RgbColor.RGBA_EXTRACT);++ if (match) {+ const red = +match[1];+ const green = +match[2];+ const blue = +match[3];+ const alpha = +match[4];++ this._cssString = cssString;+ this._red = red;+ this._green = green;+ this._blue = blue;+ this._alpha = alpha;+ return;+ }++ match = cssString.match(RgbColor.RGB_EXTRACT);++ if (match) {+ const red = +match[1];+ const green = +match[2];+ const blue = +match[3];++ this._cssString = cssString;+ this._red = red;+ this._green = green;+ this._blue = blue;+ this._alpha = 1;+ return;+ }++ throw new Error('Invalid rgba or rgb color');+ }++ asHexString(): string {+ return Color.rgbColorToHexValue(this);+ }++ getRed(): number {+ let r = this._red + RgbColor.RGB_COLOR_AMT;++ if (r > 255) {+ r = 255;+ } else if (r < 0) {+ r = 0;+ }++ return r;+ }++ getGreen(): number {+ let g = this._green + RgbColor.RGB_COLOR_AMT;++ if (g > 255) {+ g = 255;+ } else if (g < 0) {+ g = 0;+ }++ return g;+ }++ getBlue(): number {+ let b = this._blue + RgbColor.RGB_COLOR_AMT;++ if (b > 255) {+ b = 255;+ } else if (b < 0) {+ b = 0;+ }++ return b;+ }++ getAlpha(): number {+ return this._alpha;+ }++ getColorType(): ColorType {+ return ColorType.RGB;+ }++ clone(): RgbColor {+ return new RgbColor(this._cssString, this._builder);+ }++ asThemeColor(): ThemeColor {+ throw new Error('rgb color not support to themeColor');+ }++ equals(color: Color): boolean {+ if (color instanceof RgbColor) {+ return (+ color._red === this._red &&+ color._blue === this._blue &&+ color._green === this._green &&+ color._alpha === this._alpha+ );+ }+ return false;+ }++ getCssString() {+ return this._cssString;+ }+}++export class ThemeColor extends Color {+ private static _cacheThemeColor = new Map<+ ThemeColors,+ Map<ThemeColorType, RgbColor>+ >();++ private _themeColorType: ThemeColorType;++ private _themeTint: number;++ private _themeColors: ThemeColors;++ constructor(+ theme: ThemeColorType,+ themeTint: number,+ themeColors: ThemeColors,+ builder: ColorBuilder+ ) {+ super(builder);+ this._themeColorType = theme;+ this._themeTint = themeTint;+ this._themeColors = themeColors;+ }++ lumValue(tint: number, lum: number) {+ if (tint == null) {+ return lum;+ }++ let value: number;++ if (tint < 0) {+ value = lum * (1.0 + tint);+ } else {+ value = lum * (1.0 - tint) + (255 - 255 * (1.0 - tint));+ }++ return value;+ }++ asRgbColor(): RgbColor {+ const themeColors = THEME_COLORS[this._themeColors];+ if (themeColors == null) {+ throw new Error('not find themeColors type');+ }++ const hexValue = themeColors[this._themeColorType];+ if (hexValue == null) {+ throw new Error('not find themeColors value');+ }++ let themeCache;+ if (ThemeColor._cacheThemeColor.has(this._themeColors)) {+ themeCache = ThemeColor._cacheThemeColor.get(this._themeColors) as Map<+ ThemeColorType,+ RgbColor+ >;+ if (themeCache.has(this._themeColorType)) {+ return themeCache.get(this._themeColorType) as RgbColor;+ }+ } else {+ themeCache = new Map<ThemeColorType, RgbColor>();+ ThemeColor._cacheThemeColor.set(this._themeColors, themeCache);+ }++ const hlsColor = new HLSColor(Color.hexValueToRgbColor(hexValue));+ hlsColor.setLightness(+ this.lumValue(this._themeTint, hlsColor.getLightness() * 255) / 255+ );+ const rgbColor = hlsColor.asRgbColor();+ themeCache.set(this._themeColorType, rgbColor);++ return rgbColor;+ }++ clone(): ThemeColor {+ return new ThemeColor(+ this._themeColorType,+ this._themeTint,+ this._themeColors,+ this._builder+ );+ }++ equals(color: Color): boolean {+ if (color instanceof ThemeColor) {+ return color._themeColorType === this._themeColorType;+ }+ return false;+ }++ getColorType(): ColorType {+ return ColorType.THEME;+ }++ getThemeColorType(): ThemeColorType {+ return this._themeColorType;+ }+}diff --git a/packages/core/src/Sheets/Domain/ColorBuilder.ts b/packages/core/src/Sheets/Domain/ColorBuilder.tsindex 48c8d63c46..fd82be6958 100644--- a/packages/core/src/Sheets/Domain/ColorBuilder.ts+++ b/packages/core/src/Sheets/Domain/ColorBuilder.ts@@ -1,4 +1,4 @@-import { ColorType, ThemeColors, ThemeColorType } from '../../Enum';+import { ColorType, ThemeColors, ThemeColorType } from '../../Types/Enum';import { Nullable } from '../../Shared';import { Color, RgbColor, ThemeColor } from './Color';diff --git a/packages/core/src/Sheets/Domain/ColumnManager.ts b/packages/core/src/Sheets/Domain/ColumnManager.tsindex 413cf36646..901af016f2 100644--- a/packages/core/src/Sheets/Domain/ColumnManager.ts+++ b/packages/core/src/Sheets/Domain/ColumnManager.ts@@ -1,8 +1,8 @@import { Command } from '../../Command';import { ISetColumnWidthActionData } from '../Action';-import { ACTION_NAMES } from '../../Const';-import { BooleanNumber } from '../../Enum';-import { IColumnData } from '../../Interfaces';+import { ACTION_NAMES } from '../../Types/Const';+import { BooleanNumber } from '../../Types/Enum';+import { IColumnData } from '../../Types/Interfaces';import { Nullable, Tools } from '../../Shared';import { ObjectArray, ObjectArrayType } from '../../Shared/ObjectArray';import { Worksheet } from './Worksheet';diff --git a/packages/core/src/Sheets/Domain/Freeze.ts b/packages/core/src/Sheets/Domain/Freeze.tsindex 44b2cf9499..144be19f15 100644--- a/packages/core/src/Sheets/Domain/Freeze.ts+++ b/packages/core/src/Sheets/Domain/Freeze.ts@@ -1,7 +1,7 @@import { SheetContext } from '../../Basics';import { Command, CommandManager } from '../../Command';import { Worksheet } from './Worksheet';-import { ACTION_NAMES } from '../../Const';+import { ACTION_NAMES } from '../../Types/Const';export class Freeze {private _commandManager: CommandManager;diff --git a/packages/core/src/Sheets/Domain/Merges.ts b/packages/core/src/Sheets/Domain/Merges.tsindex c76a31fb06..1435834b90 100644--- a/packages/core/src/Sheets/Domain/Merges.ts+++ b/packages/core/src/Sheets/Domain/Merges.ts@@ -17,7 +17,7 @@ import {} from '../Action';import { Nullable, Tools, Rectangle, Tuples } from '../../Shared';import { Worksheet } from './Worksheet';-import { IRangeData } from '../../Interfaces';+import { IRangeData } from '../../Types/Interfaces';/*** Manage merged cellsdiff --git a/packages/core/src/Sheets/Domain/NamedRange.ts b/packages/core/src/Sheets/Domain/NamedRange.tsindex 24c43fd5c6..efbfa05077 100644--- a/packages/core/src/Sheets/Domain/NamedRange.ts+++ b/packages/core/src/Sheets/Domain/NamedRange.ts@@ -6,9 +6,9 @@ import {ISetNamedRangeActionData,AddNamedRangeAction,} from '../Action';-import { ACTION_NAMES } from '../../Const';+import { ACTION_NAMES } from '../../Types/Const';import { Workbook } from './index';-import { INamedRange } from '../../Interfaces';+import { INamedRange } from '../../Types/Interfaces';/*** Create, access and modify named ranges in a spreadsheet. Named ranges are ranges that have associated string aliases.diff --git a/packages/core/src/Sheets/Domain/Range.ts b/packages/core/src/Sheets/Domain/Range.tsindex dd1a1ab5f1..3850fe15db 100644--- a/packages/core/src/Sheets/Domain/Range.ts+++ b/packages/core/src/Sheets/Domain/Range.ts@@ -1,3959 +1,3959 @@-import { SheetContext } from '../../Basics';--import {- IInsertRangeActionData,- IClearRangeActionData,- IAddMergeActionData,- IRemoveMergeActionData,- IDeleteRangeActionData,- ISetRangeDataActionData,- ISetRangeStyleActionData,- ISetRangeFormattedValueActionData,- SetRangeStyleAction,-} from '../Action';--import { CommandManager, ISheetActionData, Command } from '../../Command';--import { DEFAULT_RANGE, DEFAULT_STYLES, ACTION_NAMES } from '../../Const';--import {- BooleanNumber,- BorderStyleTypes,- BorderType,- Dimension,- Direction,- FontItalic,- FontWeight,- HorizontalAlign,- TextDirection,- VerticalAlign,- WrapStrategy,- CopyPasteType,-} from '../../Enum';--import {- IBorderData,- IBorderStyleData,- ICellData,- ICellDataMatrix,- ICellV,- IDocumentData,- IOptionData,- IRangeData,- IRangeType,- IStyleData,- ITextDecoration,-} from '../../Interfaces';--import {- Nullable,- ObjectMatrix,- ObjectMatrixPrimitiveType,- Tools,- Tuples,-} from '../../Shared';--import { Worksheet } from './Worksheet';--/**- * getObjectValues options type- */-type IValueOptionsType = {- /**- * set whether to include style- */- isIncludeStyle?: boolean;-};--/**- * Access and modify spreadsheet ranges.- *- * @remarks- * A range can be a single cell in a sheet or a group of adjacent cells in a sheet.- *- * Reference from: https://developers.google.com/apps-script/reference/spreadsheet/range- *- * @beta- */-export class Range {- private _commandManager: CommandManager;-- private _context: SheetContext;-- private _rangeData: IRangeData;-- private _worksheet: Worksheet;-- constructor(workSheet: Worksheet, range: IRangeType) {- this._context = workSheet.getContext();- this._commandManager = this._context.getCommandManager();-- // Convert the range passed in by the user into a standard format- // this._rangeData = new TransformTool(- // this._context.getWorkBook()- // ).transformRangeType(range);- this._rangeData = this._context- .getWorkBook()- .transformRangeType(range).rangeData;- this._worksheet = workSheet;-- // The user entered an invalid range- if (Object.values(this._rangeData).includes(-1)) {- console.error('Invalid range,default set index -1');- }- }-- static foreach(- rangeData: IRangeData,- action: (row: number, column: number) => void- ): void {- const { startRow, startColumn, endRow, endColumn } = rangeData;- for (let i = startRow; i <= endRow; i++) {- for (let j = startColumn; j <= endColumn; j++) {- action(i, j);- }- }- }-- /**- * get current range data- *- * @returns current range- */- getRangeData(): IRangeData {- return this._rangeData;- }-- /**- * Returns the value of the top-left cell in the range. The value may be of type Number, Boolean, Date, or String depending on the value of the cell. Empty cells return an empty string.- * @returns The value in this cell- */- getValue(): Nullable<ICellData> {- return this.getValues()[0][0];- }-- /**- * Returns the rectangular grid of values for this range.- *- * Returns a two-dimensional array of values, indexed by row, then by column. The values may be of type Number, Boolean, Date, or String, depending on the value of the cell. Empty cells are represented by an empty string in the array. Remember that while a range index starts at 0, 0, same as the JavaScript array is indexed from [0][0].- *- * In web apps, a Date value isn't a legal parameter. getValues() fails to return data to a web app if the range contains a cell with a Date value. Instead, transform all the values retrieved from the sheet to a supported JavaScript primitive like a Number, Boolean, or String.- *- * @returns A two-dimensional array of values.- */- getValues(): Array<Array<Nullable<ICellData>>> {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const range: Array<Array<Nullable<ICellData>>> = [];- for (let r = startRow; r <= endRow; r++) {- const row: Array<Nullable<ICellData>> = [];- for (let c = startColumn; c <= endColumn; c++) {- row.push(this.getMatrix().getValue(r, c) || null);- }- range.push(row);- }- return range;- }-- /**- * get range matrix- *- * @returns range matrix- */- getMatrix(): ObjectMatrix<ICellData> {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const sheetMatrix = this._worksheet.getCellMatrix();- const rangeMatrix = new ObjectMatrix<ICellData>();-- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || null);- }- }-- return rangeMatrix;- }-- /**- * get range matrix object- *- * @returns range matrix object- */- getMatrixObject(): ObjectMatrix<ICellData> {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const sheetMatrix = this._worksheet.getCellMatrix();- const rangeMatrix = new ObjectMatrix<ICellData>();-- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- rangeMatrix.setValue(- r - startRow,- c - startColumn,- sheetMatrix.getValue(r, c) || {}- );- }- }-- return rangeMatrix;- }-- /**- * Returns the displayed value of the top-left cell in the range. The value is a String. The displayed value takes into account date, time and currency formatting formatting, including formats applied automatically by the spreadsheet's Locale setting. Empty cells return an empty string.- *- * @returns The displayed value in this cell.- */- getDisplayValue(): string | IDocumentData {- const value = this.getValue();- if (value && value.p) {- return value.p;- }- if (value && value.m) {- return value.m;- }- return '';- }-- /**- * Returns the rectangular grid of values for this range.- *- * Returns a two-dimensional array of displayed values, indexed by row, then by column. The values are String objects. The displayed value takes into account date, time and currency formatting, including formats applied automatically by the spreadsheet's Locale setting. Empty cells are represented by an empty string in the array. Remember that while a range index starts at 0, 0, same as the JavaScript array is indexed from [0][0].- *- * @returns — A two-dimensional array of values.- */- getDisplayValues(): Array<Array<string | IDocumentData>> {- return this.getValues().map((row) =>- row.map((value: Nullable<ICellData>) => {- if (value && value.p) {- return value.p;- }- if (value && value.m) {- return value.m;- }- return '';- })- );- }-- /**- * Returns a string description of the range, in A1 notation.- *- * @returns The string description of the range in A1 notation.- */- getA1Notation(): string {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- let start;- let end;- if (startColumn < endColumn) {- start = Tools.numToWord(startColumn + 1) + (startRow + 1);- end = Tools.numToWord(endColumn + 1) + (endRow + 1);- } else {- start = Tools.numToWord(endColumn + 1) + (endRow + 1);- end = Tools.numToWord(startColumn + 1) + (startRow + 1);- }-- if (start === end) return `${start}`;- return `${start}:${end}`;- }-- /**- * Returns the background color of the top-left cell in the range (for example, '#ffffff').- *- * @returns — The color code of the background.- */- getBackground(): string {- return this.getBackgrounds()[0][0];- }-- /**- * Returns the background colors of the cells in the range (for example, '#ffffff').- *- * @returns — A two-dimensional array of color codes of the backgrounds.- */- getBackgrounds(): string[][] {- return this.getValues().map((row) =>- row.map((cell: Nullable<ICellData>) => {- const styles = this._context.getWorkBook().getStyles();- let rgbColor: string = DEFAULT_STYLES.bg?.rgb!;- rgbColor = styles.getStyleByCell(cell)?.bg?.rgb!;- return rgbColor;- })- );- }-- /**- * Returns a given cell within a range.- *- * The row and column here are relative to the range- * e.g. "B2:D4", getCell(0,0) in this code returns the cell at B2- * @returns — A range containing a single cell at the specified coordinates.- */- getCell(row: number, column: number): Range {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const cell = {- startRow: startRow + row,- endRow: startRow + row,- startColumn: startColumn + column,- endColumn: startColumn + column,- };-- return new Range(this._worksheet, cell);- }-- /**- * Returns the starting column position for this range- *- * @returns — The range's starting column position in the spreadsheet.- */- getColumn(): number {- return this._rangeData.startColumn;- }-- /**- * Returns the data of the object structure, and can set whether to bring styles- */- getObjectValue(options: IValueOptionsType = {}): ICellData {- return this.getObjectValues(options)[0][0];- }-- /**- * Returns the data of the object structure, and can set whether to bring styles- *- * @param options set whether to include style- * @returns Returns a value in object format- */- getObjectValues(- options: IValueOptionsType = {}- ): ObjectMatrixPrimitiveType<ICellData> {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // get object values from sheet matrix, or use this.getMatrix() create a new matrix then this.getMatrix().getData()- const values = this._worksheet- .getCellMatrix()- .getFragments(startRow, endRow, startColumn, endColumn)- .getData();-- if (options.isIncludeStyle) {- const style = this._context.getWorkBook().getStyles();- for (let r = 0; r <= endRow - startRow; r++) {- for (let c = 0; c <= endColumn - startColumn; c++) {- // handle null- if (!values[r][c]) continue;-- const s = values[r][c].s;-- // make sure value has style- if (s) {- values[r][c].s = style.get(s);- }- }- }- }-- return values;- }-- /**- * Notify other Components- * TODO: 待触发更新测试- */- // notifyUpdated() {- // this._context.onAfterChangeRangeDataObservable.notifyObservers(- // this._worksheet- // );- // }-- /**- * Returns the font color of the cell in the top-left corner of the range, in CSS notation- */- getFontColor(): Nullable<string> {- return this.getFontColors()[0][0];- }-- /**- * Returns the font colors of the cells in the range in CSS notation (such as '#ffffff' or 'white').- */- getFontColors(): Array<Array<Nullable<string>>> {- return this.getValues().map((row) =>- row.map((cell: Nullable<ICellData>) => {- const styles = this._context.getWorkBook().getStyles();- const cellStyle = styles.getStyleByCell(cell);- return cellStyle?.cl?.rgb || DEFAULT_STYLES.cl?.rgb;- })- );- }-- /**- * Returns the font families of the cells in the range.- */- getFontFamilies(): string[][] {- return this._getStyles('ff') as string[][];- }-- /**- * Returns the font family of the cell in the top-left corner of the range.- */- getFontFamily(): string {- return this.getFontFamilies()[0][0];- }-- /**- * Returns the underlines of the cells in the range.- */- getUnderlines(): ITextDecoration[][] {- return this._getStyles('ul') as ITextDecoration[][];- }-- /**- * Returns the underline of the cells in the range.- */- getUnderline(): ITextDecoration {- return this.getUnderlines()[0][0];- }-- /**- * Returns the overlines of the cells in the range.- */- getOverlines(): ITextDecoration[][] {- return this._getStyles('ol') as ITextDecoration[][];- }-- /**- * Returns the overline of the cells in the range.- */- getOverline(): ITextDecoration {- return this.getOverlines()[0][0];- }-- /**- * Returns the strikeThroughs of the cells in the range.- */- getStrikeThroughs(): ITextDecoration[][] {- return this._getStyles('st') as ITextDecoration[][];- }-- /**- * Returns the strikeThrough of the cells in the range.- */- getStrikeThrough(): ITextDecoration {- return this.getStrikeThroughs()[0][0];- }-- /**- * Returns the font size in point size of the cell in the top-left corner of the range.- */- getFontSize(): number {- return this.getFontSizes()[0][0];- }-- /**- * Returns the font sizes of the cells in the range.- */- getFontSizes(): number[][] {- return this._getStyles('fs') as number[][];- }-- /**- * Returns the border info of the cells in the range.- */-- getBorder(): IBorderData {- return this.getBorders()[0][0];- }-- getBorders(): IBorderData[][] {- return this._getStyles('bd') as IBorderData[][];- }-- /**- * Returns the font style ('italic' or 'normal') of the cell in the top-left corner of the range.- */- getFontStyle(): FontItalic {- return this.getFontStyles()[0][0];- }-- /**- * Returns the font styles of the cells in the range.- */- getFontStyles(): FontItalic[][] {- return this._getStyles('it') as FontItalic[][];- }-- /**- * Returns the font weight (normal/bold) of the cell in the top-left corner of the range.- */- getFontWeight(): FontWeight {- return this.getFontWeights()[0][0];- }-- /**- * Returns the font weights of the cells in the range.- */- getFontWeights(): FontWeight[][] {- return this._getStyles('bl') as FontWeight[][];- }-- /**- * Returns the formula (A1 notation) for the top-left cell of the range, or an empty string if the cell is empty or doesn't contain a formula.- */- // getFormula(): string {- // return this.getFormulas()[0][0];- // }-- /**- * Returns the formulas (A1 notation) for the cells in the range.- */- // getFormulas(): string[][] {- // return this.getValues().map((row) =>- // row.map((cell: Nullable<ICellData>) => cell?.f || '')- // );- // }-- /**- * Returns the grid ID of the range's parent sheet.- */- getGridId(): string {- return this._worksheet.getSheetId();- }-- /**- * Returns the height of the range.- */- getHeight(): number {- const { _rangeData, _worksheet } = this;- const { startRow, endRow } = _rangeData;- let h = 0;- for (let i = 0; i <= endRow - startRow; i++) {- const hh = _worksheet.getRowHeight(i);- h += hh;- }- return h;- }-- /**- * Returns the horizontal alignment of the text (left/center/right) of the cell in the top-left corner of the range.- */- getHorizontalAlignment(): HorizontalAlign {- return this.getHorizontalAlignments()[0][0];- }-- /**- *Returns the horizontal alignments of the cells in the range.- */- getHorizontalAlignments(): HorizontalAlign[][] {- return this._getStyles('ht') as HorizontalAlign[][];- }-- /**- * Returns the end column position.- */- getLastColumn(): number {- return this._rangeData.endColumn;- }-- /**- * Returns the end row position.- */- getLastRow(): number {- return this._rangeData.endRow;- }-- /**- * Returns an array of Range objects representing merged cells that either are fully within the current range, or contain at least one cell in the current range.- */- getMergedRanges(): Range[] {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- return this._worksheet- .getMerges()- .getMergedRanges({ startRow, endRow, startColumn, endColumn })- .map((rangeData) => new Range(this._worksheet, rangeData));- }-- /**- * Starting at the cell in the first column and row of the range, returns the next cell in the given direction that is the edge of a contiguous range of cells with data in them or the cell at the edge of the spreadsheet in that direction.- * @param direction- * @returns The data region edge cell or the cell at the edge of the spreadsheet.- */- getNextDataCell(direction: Direction): Range {- const { _worksheet } = this;- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const maxRow = _worksheet.getMaxRows();- const maxColumn = _worksheet.getMaxColumns();- if (direction === Direction.BOTTOM) {- for (let i = 0; i < maxRow - startColumn; i++) {- const value = this._worksheet- .getCellMatrix()- .getValue(startRow + i, startColumn);- if (value)- _worksheet.getRange(- startRow + i,- startColumn,- startRow + i,- startColumn- );- }- return _worksheet.getRange(maxRow, startColumn, maxRow, startColumn);- }- if (direction === Direction.TOP) {- for (let i = 0; i < startRow; i++) {- const value = this._worksheet- .getCellMatrix()- .getValue(startRow - i, startColumn);- if (value)- _worksheet.getRange(- startRow - i,- startColumn,- startRow - i,- startRow- );- }- return _worksheet.getRange(0, startColumn, 0, startColumn);- }- if (direction === Direction.RIGHT) {- for (let i = 0; i < maxColumn - startColumn; i++) {- const value = this._worksheet- .getCellMatrix()- .getValue(startRow, startColumn + i);- if (value)- _worksheet.getRange(- startRow,- startColumn + i,- startRow,- startColumn + i- );- }- return _worksheet.getRange(startRow, maxColumn, startRow, maxColumn);- }- if (direction === Direction.LEFT) {- for (let i = 0; i < maxRow - startColumn; i++) {- const value = this._worksheet- .getCellMatrix()- .getValue(startRow, startColumn - i);- if (value)- _worksheet.getRange(- startRow,- startColumn - i,- startRow,- startColumn - i- );- }- return _worksheet.getRange(startRow, 0, startRow, 0);- }- return _worksheet.getRange(DEFAULT_RANGE);- }-- /**- * Returns the note associated with the given range.- */- // getNote(): string {- // return this.getNotes()[0][0];- // }-- /**- * Returns the notes associated with the cells in the range.- */- // getNotes(): string[][] {- // return this.getValues().map((row) =>- // row.map((cell: Nullable<ICellData>) => cell?.n || '')- // );- // }-- /**- * Returns the number of columns in this range.- */- getNumColumns(): number {- const { startColumn, endColumn } = this._rangeData;- return endColumn - startColumn + 1;- }-- /**- * Returns the number of rows in this range.- */- getNumRows(): number {- const { startRow, endRow } = this._rangeData;- return endRow - startRow + 1;- }-- /**- * Get the number or date formatting of the top-left cell of the given range.- */- // getNumberFormat(): string {- // return this.getNumberFormats()[0][0];- // }-- /**- * Returns the number or date formats for the cells in the range.- */- // getNumberFormats(): string[][] {- // return this.getValues().map((row) =>- // row.map((cell: Nullable<ICellData>) => cell?.fm?.f || '')- // );- // }-- /**- * Returns the Rich Text value for the top left cell of the range, or null if the cell value is not text.- */- getRichTextValue(): Nullable<IDocumentData | ''> {- return this.getRichTextValues()[0][0];- }-- /**- * Returns the Rich Text values for the cells in the range.- */- getRichTextValues(): Array<Array<Nullable<IDocumentData | ''>>> {- return this.getValues().map((row) =>- row.map((cell: Nullable<ICellData>) => cell?.p || '')- );- }-- /**- * Returns the row position for this range.- */- getRowIndex(): number {- return this._rangeData.startRow;- }-- /**- * Returns the sheet this range belongs to.- */- getSheet(): Worksheet {- return this._worksheet;- }-- /**- * Returns the text direction for the top left cell of the range.- */- getTextDirection(): number {- return this.getTextDirections()[0][0];- }-- /**- * Returns the text directions for the cells in the range.- */- getTextDirections(): number[][] {- return this._getStyles('td') as number[][];- }-- /**- * Returns the text rotation settings for the top left cell of the range.- */- // getTextRotation(): number {- getTextRotation() {- return this.getTextRotations()[0][0];- }-- /**- * Returns the text rotation settings for the cells in the range.- */- // getTextRotations(): number[][] {- getTextRotations() {- return this._getStyles('tr');- }-- /**- * Returns the text style for the top left cell of the range.- */- getTextStyle(): Nullable<IStyleData> {- return this.getTextStyles()[0][0];- }-- /**- * Returns the text styles for the cells in the range.- */- getTextStyles(): Array<Array<Nullable<IStyleData>>> {- return this.getValues().map((row) =>- row.map((cell: Nullable<ICellData>) => {- const styles = this._context.getWorkBook().getStyles();- return styles.getStyleByCell(cell);- })- );- }-- /**- * Returns the vertical alignment (top/middle/bottom) of the cell in the top-left corner of the range.- */- getVerticalAlignment(): VerticalAlign {- return this.getVerticalAlignments()[0][0];- }-- /**- * Returns the vertical alignments of the cells in the range.- */- getVerticalAlignments(): VerticalAlign[][] {- return this._getStyles('vt') as VerticalAlign[][];- }-- /**- * Returns the width of the range in columns.- */- getWidth(): number {- const { _rangeData, _worksheet } = this;- const { startColumn, endColumn } = _rangeData;- let w = 0;- for (let i = 0; i <= endColumn - startColumn; i++) {- w += _worksheet.getColumnWidth(i);- }- return w;- }-- /**- * Returns whether the text in the cell wraps.- */- getWrap(): BooleanNumber {- return this.getWraps()[0][0];- }-- /**- * Returns whether the text in the cells wrap.- */- getWraps(): BooleanNumber[][] {- return this._getStyles('tb') as BooleanNumber[][];- }-- /**- * Returns the text wrapping strategies for the cells in the range.- */- getWrapStrategies(): WrapStrategy[][] {- return this._getStyles('tb') as WrapStrategy[][];- }-- /**- * Returns the text wrapping strategy for the top left cell of the range.- */- getWrapStrategy(): WrapStrategy {- return this.getWrapStrategies()[0][0];- }-- /**- * Returns true if the range is totally blank.- */- isBlank(): boolean {- const data = this.getValues();- return data.some((items) => items.some((item) => item?.m === ''));- }-- // isChecked() {}- // isEndColumnBounded() {}- // isEndRowBounded() {}-- /**- * Returns true if the cells in the current range overlap any merged cells.- */- isPartOfMerge(): boolean {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const data = this._worksheet- .getMerges()- .getByRowColumn(startRow, endRow, startColumn, endColumn);- if (data) {- return true;- }-- return false;- }-- /**- * Sets the background color of all cells in the range in CSS notation (such as '#ffffff' or 'white').- *- * @param color Sets the background color of all cells in the range in CSS notation (such as '#ffffff' or 'white').- * @returns This range, for chaining.- */- setBackground(color: string): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array-- const colorObj: IStyleData = {- bg: {- rgb: color,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- colorObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets a rectangular grid of background colors (must match dimensions of this range). The colors are in CSS notation (such as '#ffffff' or 'white').- *- * @param color A two-dimensional array of colors in CSS notation (such as '#ffffff' or 'white'); null values reset the color.- * @returns This range, for chaining.- */- setBackgrounds(color: string[][]): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const matrix = new ObjectMatrix<IStyleData>();- for (let r = 0; r < endRow - startRow + 1; r++) {- for (let c = 0; c < endColumn - startColumn + 1; c++) {- matrix.setValue(r, c, {- bg: {- rgb: color[r][c],- },- });- }- }- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: matrix.getData(),- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets the background to the given color using RGB values (integers between 0 and 255 inclusive).- *- * @param red The red value in RGB notation.- * @param green The green value in RGB notation.- * @param blue The blue value in RGB notation.- * @returns This range, for chaining.- */- setBackgroundRGB(red: number, green: number, blue: number): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const rgbString = `RGB(${red},${green},${blue})`;-- const colorObj: IStyleData = {- bg: {- rgb: rgbString,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- colorObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets a rectangular grid of font colors (must match dimensions of this range). The colors are in CSS notation (such as '#ffffff' or 'white').- *- * @param colors A two-dimensional array of colors in CSS notation (such as '#ffffff' or 'white'); null values reset the color.- * @returns This range, for chaining.- */- setFontColors(colors: string[][]): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const matrix = new ObjectMatrix<IStyleData>();- for (let r = 0; r < endRow - startRow + 1; r++) {- for (let c = 0; c < endColumn - startColumn + 1; c++) {- matrix.setValue(r, c, { cl: { rgb: colors[r][c] } });- }- }- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: matrix.getData(),- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets a rectangular grid of font families (must match dimensions of this range). Examples of font families are "Arial" or "Helvetica".- *- * @param fontFamilies A two-dimensional array of font families; null values reset the font family.- * @returns This range, for chaining.- */- setFontFamilies(fontFamilies: string[][]): Range {- this._setStyles(fontFamilies, 'ff');- return this;- }-- /**- * Sets the font line style of the given range- *- * @param fontLine The font line style; a null value resets the font line style- * @returns This range, for chaining.- */- setUnderline(fontLine: Nullable<ITextDecoration>): Range {- this._setStyle(fontLine, 'ul');- return this;- }-- /**- * Sets the font line style of the given range- *- * @param fontLine The font line style; a null value resets the font line style- * @returns This range, for chaining.- */- setOverline(fontLine: Nullable<ITextDecoration>): Range {- this._setStyle(fontLine, 'ol');- return this;- }-- /**- * Sets a rectangular grid of line styles (must match dimensions of this range).- *- * @param fontLine The font line style; a null value resets the font line style- * @returns This range, for chaining.- */- setStrikeThrough(fontLine: Nullable<ITextDecoration>): Range {- this._setStyle(fontLine, 'st');- return this;- }-- /**- * Sets the font line style of the given range- *- * @param fontLines A two-dimensional array of font line styles ; null values reset the font line style.- * @returns This range, for chaining.- */- setUnderlines(fontLines: Array<Array<Nullable<ITextDecoration>>>): Range {- this._setStyles(fontLines, 'ul');- return this;- }-- /**- * Sets the font line style of the given range- *- * @param fontLines A two-dimensional array of font line styles ; null values reset the font line style.- * @returns This range, for chaining.- */- setOverlines(fontLines: Array<Array<Nullable<ITextDecoration>>>): Range {- this._setStyles(fontLines, 'ol');- return this;- }-- /**- * Sets the font line style of the given range- *- * @param fontLines A two-dimensional array of font line styles ; null values reset the font line style.- * @returns This range, for chaining.- */- setStrikeThroughs(fontLines: Array<Array<Nullable<ITextDecoration>>>): Range {- this._setStyles(fontLines, 'st');- return this;- }-- /**- * Sets a rectangular grid of font sizes (must match dimensions of this range).- *- * @param sizes A two-dimensional array of sizes.- * @returns This range, for chaining.- */- setFontSizes(sizes: number[][]): Range {- this._setStyles(sizes, 'fs');- return this;- }-- /**- * Set the font style for the given range ('italic' or 'normal').- *- * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.- * @returns This range, for chaining.- */- setFontStyle(fontStyle: Nullable<FontItalic>): Range {- this._setStyle(fontStyle, 'it');- return this;- }-- /**- * Sets a rectangular grid of font styles (must match dimensions of this range).- *- * @param fontStyles A two-dimensional array of font styles, either 'italic' or 'normal'; null values reset the font style.- * @returns This range, for chaining.- */- setFontStyles(fontStyles: Array<Array<Nullable<FontItalic>>>): Range {- this._setStyles(fontStyles, 'it');- return this;- }-- /**- * Set the font weight for the given range (normal/bold).- *- * @param fontWeight The font weight, either 'bold' or 'normal'; a null value resets the font weight.- * @returns This range, for chaining.- */- setFontWeight(fontWeight: Nullable<FontWeight>): Range {- this._setStyle(fontWeight, 'bl');- return this;- }-- /**- * Sets a rectangular grid of font weights (must match dimensions of this range).- *- * @param fontWeights A two-dimensional array of font weights, either 'bold' or 'normal'; null values reset the font weight.- * @returns This range, for chaining.- */- setFontWeights(fontWeights: Array<Array<Nullable<FontWeight>>>): Range {- this._setStyles(fontWeights, 'bl');- return this;- }-- /**- * Sets a rectangular grid of horizontal alignments.- *- * @param alignments A two-dimensional array of alignments, either 'left', 'center' or 'normal'; a null value resets the alignment.- * @returns This range, for chaining.- */- setHorizontalAlignments(- alignments: Array<Array<Nullable<HorizontalAlign>>>- ): Range {- this._setStyles(alignments, 'ht');- return this;- }-- /**- * Sets the note to the given value.- *- * @param note The note value to set for the range; a null value removes the note.- * @returns This range, for chaining.- */- // setNote(note: string): Range {- // const { _rangeData, _context, _commandManager, _worksheet } = this;- // const { startRow, startColumn, endRow, endColumn } = _rangeData;- // const cellValue = new ObjectMatrix<string>();- // for (let r = startRow; r <= endRow; r++) {- // for (let c = startColumn; c <= endColumn; c++) {- // cellValue.setValue(r, c, note);- // }- // }- // const setValue: ISetRangeNoteActionData = {- // sheetId: _worksheet.getSheetId(),- // actionName: ACTION_NAMES.SET_RANGE_NOTE_ACTION,- // cellNote: cellValue.getData(),- // rangeData: this._rangeData,- // };- // const command = new Command(_context.getWorkBook(), setValue);- // _commandManager.invoke(command);-- // return this;- // }-- /**- * Sets the note to the given value.- *- * @param notes A two-dimensional array of notes; null values remove the note.- * @returns This range, for chaining.- */- // setNotes(notes: string[][]): Range {- // const { _rangeData, _context, _commandManager, _worksheet } = this;-- // const { startRow, startColumn, endRow, endColumn } = _rangeData;-- // const cellValue = new ObjectMatrix<string>();- // for (let r = 0; r <= endRow - startRow; r++) {- // for (let c = 0; c <= endColumn - startColumn; c++) {- // cellValue.setValue(r + startRow, c + startColumn, notes[r][c]);- // }- // }-- // const setValue: ISetRangeNoteActionData = {- // sheetId: _worksheet.getSheetId(),- // actionName: ACTION_NAMES.SET_RANGE_NOTE_ACTION,- // cellNote: cellValue.getData(),- // rangeData: this._rangeData,- // };- // const command = new Command(_context.getWorkBook(), setValue);- // _commandManager.invoke(command);-- // return this;- // }-- /**- * Sets the number or date format to the given formatting string.- *- * @param numberFormat A number format string.- * @returns This range, for chaining.- */- // setNumberFormat(numberFormat: string): Range {- // const { _rangeData, _context, _commandManager, _worksheet } = this;-- // const { startRow, startColumn, endRow, endColumn } = _rangeData;-- // const cellValue = new ObjectMatrix<string>();- // for (let r = 0; r <= endRow - startRow; r++) {- // for (let c = 0; c <= endColumn - startColumn; c++) {- // const fm = {- // f: numberFormat,- // t: FormatType.NUMBER,- // };- // cellValue.setValue(r + startRow, c + startColumn, JSON.stringify(fm));- // }- // }-- // const setValue: ISetRangeFormatActionData = {- // sheetId: _worksheet.getSheetId(),- // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,- // cellFormat: cellValue.getData(),- // rangeData: this._rangeData,- // };- // const command = new Command(_context.getWorkBook(), setValue);- // _commandManager.invoke(command);-- // return this;- // }-- /**- * Sets a rectangular grid of number or date formats (must match dimensions of this range).- *- * @param numberFormats A two-dimensional array of number formats.- * @returns This range, for chaining.- */- // setNumberFormats(numberFormats: string[][]): Range {- // const { _rangeData, _context, _commandManager, _worksheet } = this;-- // const { startRow, startColumn, endRow, endColumn } = _rangeData;-- // const cellValue = new ObjectMatrix<string>();- // for (let r = 0; r <= endRow - startRow; r++) {- // for (let c = 0; c <= endColumn - startColumn; c++) {- // const fm = {- // f: numberFormats[r][c],- // t: FormatType.NUMBER,- // };- // cellValue.setValue(r + startRow, c + startColumn, JSON.stringify(fm));- // }- // }-- // const setValue: ISetRangeFormatActionData = {- // sheetId: _worksheet.getSheetId(),- // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,- // cellFormat: cellValue.getData(),- // rangeData: this._rangeData,- // };- // const command = new Command(_context.getWorkBook(), setValue);- // _commandManager.invoke(command);-- // return this;- // }-- // setRichTextValue(value) {}- // setRichTextValues(values) {}- // setShowHyperlink(showHyperlink) {}-- /**- * Sets a rectangular grid of text directions.- *- * @param directions The desired text directions; if a specified direction is null it is inferred before setting.- * @returns This range, for chaining.- */- setTextDirections(directions: number[][]): Range {- this._setStyles(directions, 'td');- return this;- }-- /**- * Sets the text rotation settings for the cells in the range.- *- * @param degrees The desired angle between the standard orientation and the desired orientation. For left to right text, positive angles are in the counterclockwise direction.- * @returns This range, for chaining.- */- setTextRotation(degrees: Nullable<number>): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const styleObj: IStyleData = {- tr: {- v: 0,- a: Number(degrees),- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets a rectangular grid of text rotations.- *- * @param rotations The desired text rotation settings.- * @returns This range, for chaining.- */- setTextRotations(rotations: number[][]): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const matrix = new ObjectMatrix<IStyleData>();- for (let r = 0; r < endRow - startRow + 1; r++) {- for (let c = 0; c < endColumn - startColumn + 1; c++) {- matrix.setValue(r, c, {- tr: {- v: 0,- a: rotations[r][c]!,- },- });- }- }- const a = matrix.getData();- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: matrix.getData(),- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets the text style for the cells in the range.- *- * @param style The desired text style.- * @returns This range, for chaining.- */- setTextStyle(style: Nullable<IStyleData>): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const stylesObj = { ...style };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- stylesObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets a rectangular grid of text styles.- *- * @param styles The desired text styles.- * @returns This range, for chaining.- */- setTextStyles(styles: Array<Array<Nullable<IStyleData>>>): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const matrix = new ObjectMatrix<IStyleData>();- for (let r = 0; r < endRow - startRow + 1; r++) {- for (let c = 0; c < endColumn - startColumn + 1; c++) {- matrix.setValue(r, c, { ...styles[r][c] });- }- }- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: matrix.getData(),- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets a rectangular grid of vertical alignments (must match dimensions of this range).- *- * @param alignments A two-dimensional array of alignments, either 'top', 'middle' or 'bottom'; a null value resets the alignment.- * @returns This range, for chaining.- */- setVerticalAlignments(alignments: Array<Array<Nullable<VerticalAlign>>>): Range {- this._setStyles(alignments, 'vt');- return this;- }-- /**- * Sets whether or not to stack the text for the cells in the range.- * @param isVertical Whether or not to stack the text.- * @returns- */- setVerticalText(isVertical: BooleanNumber): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const styleObj = {- tr: {- v: isVertical,- a: 90,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Set the cell wrap of the given range- *- * @param isWrapEnabled Whether to wrap text or not.- * @returns This range, for chaining.- */- setWrap(isWrapEnabled: BooleanNumber): Range {- this._setStyle(isWrapEnabled, 'tb');- return this;- }-- /**- * Sets a rectangular grid of wrap strategies.- *- * @param strategies The desired wrapping strategies.- * @returns This range, for chaining.- */- setWrapStrategies(strategies: Array<Array<Nullable<WrapStrategy>>>): Range {- this._setStyles(strategies, 'tb');- return this;- }-- /**- * Sets a rectangular grid of word wrap policies (must match dimensions of this range).- *- * @param isWrapEnabled A two-dimensional array of wrap variables that determine whether to wrap text in a cell or not.- * @returns This range, for chaining.- */- setWraps(isWrapEnabled: BooleanNumber[][]): Range {- this._setStyles(isWrapEnabled, 'tb');- return this;- }-- /**- * Fills the destinationRange with data based on the data in this range. The new values are also determined by the specified series type. The destination range must contain this range and extend it in only one direction. For example, the following fills A1:A20 with a series of increasing numbers based on the current values in A1:A4:- *- * @param destination The range to be auto-filled with values. The destination range should contain this range and extend it in only one direction (upwards, downwards, left, or right).- * @param series The type of autoFill series that should be used to calculate new values. The effect of this series differs based on the type and amount of source data.- * @returns This range, for chaining.- */- // autoFill(destination: Range, series: AutoFillSeries): Range {- // const { _worksheet, _context, _commandManager } = this;- // const { startRow, endRow, startColumn, endColumn } = this._rangeData;- // const {- // startRow: Dsr,- // endRow: Der,- // startColumn: Dsc,- // endColumn: Dec,- // } = destination._rangeData;- // let direction = Direction.BOTTOM;- // let csLen: number = 0;- // let asLen: number = 0;-- // // 复制范围- // const copy_str_r = startRow;- // const copy_end_r = endRow;- // const copy_str_c = startColumn;- // const copy_end_c = endColumn;-- // // 应用范围- // const apply_str_r = Dsr;- // const apply_end_r = Der;- // const apply_str_c = Dsc;- // const apply_end_c = Dec;-- // const matrix = new ObjectMatrix<ICellData>();-- // if (apply_str_c === copy_str_c && apply_end_c === copy_end_c) {- // if (apply_end_r > copy_end_r) {- // direction = Direction.BOTTOM;- // } else {- // direction = Direction.TOP;- // }- // } else if (apply_end_c > copy_end_c) {- // direction = Direction.RIGHT;- // } else {- // direction = Direction.LEFT;- // }-- // if (direction === Direction.BOTTOM || direction === Direction.TOP) {- // // 列- // csLen = copy_end_r - copy_str_r + 1;- // asLen = apply_end_r - apply_str_r + 1;-- // for (let i = 0; i <= endColumn - startColumn; i++) {- // const sourceRange = this.getColumnMatrix(i).toArray();-- // const copydata = DropCell.getCopyData(- // sourceRange,- // copy_str_r,- // copy_end_r,- // copy_str_c,- // copy_end_c,- // direction- // );- // copydata.forEach((item) => {- // const data = DropCell.getApplyData(- // item,- // csLen,- // asLen,- // series,- // direction- // );- // data.forEach((dataItem, j) => {- // matrix.setValue(j, i, dataItem);- // });- // });- // }- // } else if (direction === Direction.RIGHT || direction === Direction.LEFT) {- // asLen = apply_end_c - apply_str_c;- // csLen = copy_end_c - copy_str_c;- // // 行- // for (let i = 0; i <= endRow - startRow; i++) {- // const sourceRange = this.getRowMatrix(i).toArray();-- // const copydata = DropCell.getCopyData(- // sourceRange,- // copy_str_r,- // copy_end_r,- // copy_str_c,- // copy_end_c,- // direction- // );- // copydata.forEach((item) => {- // const data = DropCell.getApplyData(- // item,- // csLen,- // asLen,- // series,- // direction- // );- // });- // }- // }-- // const setValue: ISetRangeDataActionData = {- // sheetId: _worksheet.getSheetId(),- // actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- // cellValue: matrix.getData(),- // };- // const command = new Command(- // {- // WorkBookUnit: _context.getWorkBook(),- // },- // setValue- // );- // _commandManager.invoke(command);- // return this;- // }-- // TODO- // autoFillToNeighbor(series: AutoFillSeries) {}-- /**- * Returns a copy of the range expanded in the four cardinal Directions to cover all adjacent cells with data in them.- *- * @returns This range, for chaining.- */- getDataRegion(): Range;- /**- * Returns a copy of the range expanded Direction.UP and Direction.DOWN if the specified dimension is Dimension.ROWS, or Direction.NEXT and Direction.PREVIOUS if the dimension is Dimension.COLUMNS.- *- * @returns This range, for chaining.- */- getDataRegion(dimension: Dimension): Range;- getDataRegion(...argument: any): Range {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- let numRows: number;- let numColumns: number;-- const data = this._worksheet.getCellMatrix();- if (Tools.isNumber(argument[0])) {- const dimension = argument[0];-- if (dimension === Dimension.COLUMNS) {- let start: number = startRow;- let end: number = startRow;- const rowMax = this._worksheet.getRowCount();- for (let i = 1; i < startRow; i++) {- const element = data.getValue(startRow - i, startColumn);- if (!element) {- start = startRow - i + 1;- break;- }- }- const j = 0;- while (j < rowMax - startRow) {- const element = data.getValue(startRow + j, startColumn);- if (!element) {- end = startRow - j - 1;- break;- }- }-- numColumns = start - end;- numRows = 0;- return this._worksheet.getRange(- startRow,- start,- numRows,- numColumns- );- }- if (dimension === Dimension.ROWS) {- let start: number = startRow;- let end: number = startRow;- const colMax = this._worksheet.getColumnCount();- for (let i = 1; i < startRow; i++) {- const element = data.getValue(startRow, startColumn - i);- if (!element) {- start = startRow - i + 1;- break;- }- }- const j = 0;- while (j < colMax - startColumn) {- const element = data.getValue(startRow, startColumn + j);- if (!element) {- end = startRow - j - 1;- break;- }- }-- numColumns = 0;- numRows = start - end;- return this._worksheet.getRange(- start,- startColumn,- numRows,- numColumns- );- }- } else {- let rowStart: number = startRow;- let rowEnd: number = startRow;- const rowMax = this._worksheet.getRowCount();- for (let i = 1; i < startRow; i++) {- const element = data.getValue(startRow - i, startColumn);- if (!element) {- rowStart = startRow - i + 1;- break;- }- }- const rj = 0;- while (rj < rowMax - startRow) {- const element = data.getValue(startRow + rj, startColumn);- if (!element) {- rowEnd = startRow - rj - 1;- break;- }- }-- let columnStart: number = startRow;- let columnEnd: number = startRow;- const colMax = this._worksheet.getColumnCount();- for (let i = 1; i < startRow; i++) {- const element = data.getValue(startRow, startColumn - i);- if (!element) {- columnStart = startRow - i + 1;- break;- }- }- const cj = 0;- while (cj < colMax - startColumn) {- const element = data.getValue(startRow, startColumn + cj);- if (!element) {- columnEnd = startRow - cj - 1;- break;- }- }-- numColumns = columnStart - columnEnd;- numColumns = rowStart - rowEnd;- numRows = startRow;- return this._worksheet.getRange(- rowStart,- columnStart,- numRows,- numColumns- );- }- return this;- }-- /**- * Trims the whitespace (such as spaces, tabs, or new lines) in every cell in this range. Removes all whitespace from the start and end of each cell's text, and reduces any subsequence of remaining whitespace characters to a single space.- *- * @returns This range, for chaining.- */- trimWhitespace(): Range {- const { _context, _worksheet, _commandManager } = this;- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const sheetMatrix = this._worksheet.getCellMatrix();- const regx = /\s+/g;-- const cellValue = new ObjectMatrix<ICellV>();- for (let r = 0; r <= endRow - startRow; r++) {- for (let c = 0; c <= endColumn - startColumn; c++) {- const value = sheetMatrix.getValue(r, c)!.m?.replace(regx, '');- cellValue.setValue(r + startRow, c + startColumn, value || '');- }- }-- const setValue: ISetRangeFormattedValueActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,- cellValue: cellValue.getData(),- rangeData: this._rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);-- return this;- }- // uncheck-- /**- * Sets the specified range as the active range, with the top left cell in the range as the current cell.- *- * @returns This range, for chaining.- * @internal- */- activate(): Range {- // const { _context, _commandManager } = this;- // The user entered an invalid range- if (this._rangeData?.startRow === -1) {- console.error('Invalid range,default set startRow -1');- return this;- }-- this._worksheet.getSelection().setSelection({ selection: this });-- // This range, for chaining- return this;- }-- /**- * Sets the specified cell as the current cell.- *- * If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.- *- * If the specified cell is not present in any existing range, then the existing selection is removed and the cell becomes the current cell and the active range.- *- * Note: The specified Range must consist of one cell, otherwise it throws an exception.- *- * @returns This range, for chaining.- */- activateAsCurrentCell(): Range {- this._worksheet.getSelection().setCurrentCell(this);- return this;- }-- /**- * Whether the current range and the incoming range have an intersection- *- * @param range the incoming range- * @returns Intersect or not- */- isIntersection(range: Range): boolean {- const currentStartRow = this._rangeData.startRow;- const currentEndRow = this._rangeData.endRow;- const currentStartColumn = this._rangeData.startColumn;- const currentEndColumn = this._rangeData.endColumn;-- const incomingStartRow = range.getRangeData().startRow;- const incomingEndRow = range.getRangeData().endRow;- const incomingStartColumn = range.getRangeData().startColumn;- const incomingEndColumn = range.getRangeData().endColumn;-- const zx = Math.abs(- currentStartColumn +- currentEndColumn -- incomingStartColumn -- incomingEndColumn- );- const x =- Math.abs(currentStartColumn - currentEndColumn) +- Math.abs(incomingStartColumn - incomingEndColumn);- const zy = Math.abs(- currentStartRow + currentEndRow - incomingStartRow - incomingEndRow- );- const y =- Math.abs(currentStartRow - currentEndRow) +- Math.abs(incomingStartRow - incomingEndRow);- if (zx <= x && zy <= y) {- return true;- }- return false;- }-- /**- * Sets the font color in CSS notation (such as '#ffffff' or 'white').- *- * @param color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.- * @returns- */- setFontColor(color: string): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array-- const colorObj: IStyleData = {- cl: {- rgb: color,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- colorObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Copies the data from a range of cells to another range of cells. Both the values and formatting are copied.- *- * @param destination A destination range to copy to; only the top-left cell position is relevant.- */- copyTo(destination: Range): void;-- /**- * Copies the data from a range of cells to another range of cells..- *- * @param destination A destination range to copy to; only the top-left cell position is relevant.- * @param copyPasteType A type that specifies how the range contents are pasted to the destination.- * @param transposed Whether the range should be pasted in its transposed orientation.- */- copyTo(- destination: Range,- copyPasteType: CopyPasteType,- transposed: boolean- ): void;-- /**- * Copies the data from a range of cells to another range of cells. By default both the values and formatting are copied, but this can be overridden using advanced arguments.- *- * @param destination A destination range to copy to; only the top-left cell position is relevant.- * @param options A JavaScript object that specifies advanced parameters, as listed below.- */- copyTo(destination: Range, options: IOptionData): void;- copyTo(...argument: any): void {- const { _context, _worksheet, _commandManager } = this;- const destination = argument[0];- const [value, range] = this._handleCopyRange(this, destination);- const { startRow, startColumn, endRow, endColumn } = range;-- if (Tuples.checkup(argument, Range, Tuples.BOOLEAN_TYPE)) {- const copyPasteType = argument[1];- const transposed = argument[2];-- if (copyPasteType === CopyPasteType.PASTE_NORMAL) {- const cellValue = new ObjectMatrix<ICellData>();- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(- r + startRow,- c + startColumn,- cell || {}- );- })- );-- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: cellValue.getData(),- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- } else if (copyPasteType === CopyPasteType.PASTE_FORMAT) {- const styles = _context.getWorkBook().getStyles();-- const stylesMatrix = new ObjectMatrix<IStyleData>();- const stylesArray = value.map((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- stylesMatrix.setValue(- r,- c,- styles.getStyleByCell(cell) || {}- );- })- );-- // Organize the style format of the current range into the format of the destination range- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix.getData(),- rangeData: range,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- } else if (copyPasteType === CopyPasteType.PASTE_VALUES) {- const cellValue = new ObjectMatrix<ICellV>();- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(- r + startRow,- c + startColumn,- cell?.v || ''- );- })- );-- const setValue: ISetRangeFormattedValueActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,- cellValue: cellValue.getData(),- rangeData: range,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- } else if (copyPasteType === CopyPasteType.PASTE_COLUMN_WIDTHS) {- const rangeStartColumn = this._rangeData.startColumn;- for (let i = 0; i < endColumn - rangeStartColumn; i++) {- const width = _worksheet.getColumnWidth(rangeStartColumn + i);- _worksheet.setColumnWidth(rangeStartColumn + i, width);- }- }- } else if (Tuples.checkup(argument, Range, Tuples.OBJECT_TYPE)) {- const options = argument[1];-- const cellValue = new ObjectMatrix<ICellData>();- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(r + startRow, c + startColumn, cell || {});- })- );-- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: cellValue.getData(),- options,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- } else if (Tuples.checkup(argument, Range)) {- const cellValue = new ObjectMatrix<ICellData>();- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(r + startRow, c + startColumn, cell || {});- })- );-- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: cellValue.getData(),- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- }- }-- /**- * Copy the formatting of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly. Note that this method copies the formatting only.- *- * @param sheetId The unique ID of the sheet within the spreadsheet, irrespective of position.- * @param startRow The start row of the target range.- * @param endRow The end row of the target range.- * @param startColumn The first column of the target range.- * @param endColumn The end column of the target range.- */- copyFormatToRange(- sheetId: string,- startRow: number,- endRow: number,- startColumn: number,- endColumn: number- ): void;- /**- * Copy the formatting of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly. Note that this method copies the formatting only.- *- * @param sheet The target sheet.- * @param startRow The start row of the target range.- * @param endRow The end row of the target range.- * @param startColumn The first column of the target range.- * @param endColumn The end column of the target range.- */- copyFormatToRange(- sheet: Worksheet,- startRow: number,- endRow: number,- startColumn: number,- endColumn: number- ): void;- copyFormatToRange(...argument: any): void {- const { _context, _commandManager } = this;-- const startRow = argument[1];- const endRow = argument[2];- const startColumn = argument[3];- const endColumn = argument[4];-- const sheetId = Tools.isAssignableFrom(argument[0], Worksheet)- ? argument[0].getSheetId()- : argument[0];-- const [value, range] = this._handleCopyRange(this, {- startRow,- endRow,- startColumn,- endColumn,- });-- const styles = _context.getWorkBook().getStyles();-- const stylesMatrix = new ObjectMatrix<IStyleData>();- value.map((row, r) =>- row.map((cell, c) => {- cell = cell as ICellData;- stylesMatrix.setValue(r, c, styles.getStyleByCell(cell) || {});- return styles.getStyleByCell(cell) || {};- })- );-- // Organize the style format of the current range into the format of the destination range- const setStyle: ISetRangeStyleActionData = {- sheetId,- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix.getData(),- rangeData: range,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- }-- /**- * Copy the content of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly.For a detailed description of the gridId parameter, see getGridId().- * @param sheetId The unique ID of the sheet within the spreadsheet, irrespective of position.- * @param startRow The start row of the target range.- * @param endRow The end row of the target range.- * @param startColumn The first column of the target range.- * @param endColumn The end column of the target range.- * @returns- */- copyValuesToRange(- sheetId: string,- startRow: number,- endRow: number,- startColumn: number,- endColumn: number- ): void;- /**- * Copy the content of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly.- * @param sheet The target sheet.- * @param startRow The start row of the target range.- * @param endRow The end row of the target range.- * @param startColumn The first column of the target range.- * @param endColumn The end column of the target range.- * @returns- */- copyValuesToRange(- sheet: Worksheet,- startRow: number,- endRow: number,- startColumn: number,- endColumn: number- ): void;- copyValuesToRange(...argument: any): void {- const { _context, _commandManager } = this;-- const startRow = argument[1];- const endRow = argument[2];- const startColumn = argument[3];- const endColumn = argument[4];-- const sheetId = Tools.isAssignableFrom(argument[0], Worksheet)- ? argument[0].getSheetId()- : argument[0];-- const [value, range] = this._handleCopyRange(this, {- startRow,- endRow,- startColumn,- endColumn,- });-- const cellValue = new ObjectMatrix<ICellV>();- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(- r + range.startRow,- c + range.startColumn,- cell?.v || ''- );- })- );-- const setValue: ISetRangeFormattedValueActionData = {- sheetId,- actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,- cellValue: cellValue.getData(),- rangeData: range,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- }-- /**- * Cut and paste (both format and values) from this range to the target range.- * @param target A target range to copy this range to; only the top-left cell position is relevant.- * @returns- */- moveTo(target: Range): void {- const { _context, _worksheet, _commandManager, _rangeData } = this;-- // clear current range- const options = {- formatOnly: true,- contentsOnly: true,- commentsOnly: true,- validationsOnly: true,- skipFilteredRows: true,- };- const clearValue: IClearRangeActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.CLEAR_RANGE_ACTION,- options,- rangeData: _rangeData,- };-- // get values from this range- const currentMatrix = this.getMatrix();- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const { startRow: targetStartRow, startColumn: targetStartColumn } =- target.getRangeData();-- const targetMatrix = new ObjectMatrix<ICellData>();-- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- targetMatrix.setValue(- targetStartRow + (r - startRow),- targetStartColumn + (c - startColumn),- currentMatrix.getValue(r, c) || {}- );- }- }-- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: targetMatrix.getData(),- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- clearValue,- setValue- );- _commandManager.invoke(command);- }-- /**- * Returns a new range that is offset from this range by the given number of rows and columns (which can be negative). The new range is the same size as the original range.- * @param rowOffset The number of rows down from the range's top-left cell; negative values represent rows up from the range's top-left cell.- * @param columnOffset The number of columns right from the range's top-left cell; negative values represent columns left from the range's top-left cell.- * @returns Range — This range, for chaining.- */- offset(rowOffset: number, columnOffset: number): Range;-- /**- * Returns a new range that is relative to the current range, whose upper left point is offset from the current range by the given rows and columns, and with the given height in cells.- * @param rowOffset The number of rows down from the range's top-left cell; negative values represent rows up from the range's top-left cell.- * @param columnOffset The number of columns right from the range's top-left cell; negative values represent columns left from the range's top-left cell.- * @param numRows The height in rows of the new range.- * @returns Range — This range, for chaining.- */- offset(rowOffset: number, columnOffset: number, numRows: number): Range;-- /**- * Returns a new range that is relative to the current range, whose upper left point is offset from the current range by the given rows and columns, and with the given height and width in cells.- * @param rowOffset The number of rows down from the range's top-left cell; negative values represent rows up from the range's top-left cell.- * @param columnOffset The number of columns right from the range's top-left cell; negative values represent columns left from the range's top-left cell.- * @param numRows The height in rows of the new range.- * @param numColumns The width in columns of the new range.- * @returns Range — This range, for chaining.- */- offset(- rowOffset: number,- columnOffset: number,- numRows: number,- numColumns: number- ): Range;- offset(...argument: any): Range {- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const rowOffset = argument[0];- const columnOffset = argument[1];- const numRows = argument[2];- const numColumns = argument[3];-- const offset = {- startRow: startRow + rowOffset,- endRow: endRow + rowOffset,- startColumn: startColumn + columnOffset,- endColumn: endColumn + columnOffset,- };-- if (Tools.isNumber(numRows)) {- offset.endRow = offset.startRow + numRows - 1;- }-- if (Tools.isNumber(numColumns)) {- offset.endColumn = offset.endColumn + numColumns - 1;- }-- return new Range(this._worksheet, offset);- }-- /**- * Sets the border property with color and/or style. Valid values are true (on), false (off) and null (no change). For color, use Color in CSS notation (such as '#ffffff' or 'white').- *- * @param top true for border, false for none, null for no change.- * @param left true for border, false for none, null for no change.- * @param bottom true for border, false for none, null for no change.- * @param right true for border, false for none, null for no change.- * @param vertical true for internal vertical borders, false for none, null for no change.- * @param horizontal true for internal horizontal borders, false for none, null for no change.- * @param color A color in CSS notation (such as '#ffffff' or 'white'), null for default color (black).- * @param style A style for the borders, null for default style (solid).- * @returns- */- setBorder(- top: Nullable<boolean>,- left: Nullable<boolean>,- bottom: Nullable<boolean>,- right: Nullable<boolean>,- vertical: Nullable<boolean>,- horizontal: Nullable<boolean>- ): Range;- setBorder(- top: Nullable<boolean>,- left: Nullable<boolean>,- bottom: Nullable<boolean>,- right: Nullable<boolean>,- vertical: Nullable<boolean>,- horizontal: Nullable<boolean>,- color: string,- style: BorderStyleTypes- ): Range;- setBorder(...argument: any): Range {- const top = argument[0];- const left = argument[1];- const bottom = argument[2];- const right = argument[3];-- const vertical = argument[4];- const horizontal = argument[5];-- const color = argument[6] ? argument[6] : 'black';- const style = argument[7] ? argument[7] : BorderStyleTypes.DASH_DOT;-- const { _context, _worksheet, _commandManager } = this;- const _workbook = _context.getWorkBook();-- const rangeData = this._rangeData;- const _sheetId = _worksheet.getSheetId();-- // Cells in the surrounding range may need to clear the border- const topRangeOut = {- startRow: rangeData.startRow - 1,- startColumn: rangeData.startColumn,- endRow: rangeData.startRow - 1,- endColumn: rangeData.endColumn,- };-- const leftRangeOut = {- startRow: rangeData.startRow,- startColumn: rangeData.startColumn - 1,- endRow: rangeData.endRow,- endColumn: rangeData.startColumn - 1,- };-- const bottomRangeOut = {- startRow: rangeData.endRow + 1,- startColumn: rangeData.startColumn,- endRow: rangeData.endRow + 1,- endColumn: rangeData.endColumn,- };-- const rightRangeOut = {- startRow: rangeData.startRow,- startColumn: rangeData.endColumn + 1,- endRow: rangeData.endRow,- endColumn: rangeData.endColumn + 1,- };-- // Cells in the upper, lower, left and right ranges- const topRange = {- startRow: rangeData.startRow,- startColumn: rangeData.startColumn,- endRow: rangeData.startRow,- endColumn: rangeData.endColumn,- };-- const leftRange = {- startRow: rangeData.startRow,- startColumn: rangeData.startColumn,- endRow: rangeData.endRow,- endColumn: rangeData.startColumn,- };-- const bottomRange = {- startRow: rangeData.endRow,- startColumn: rangeData.startColumn,- endRow: rangeData.endRow,- endColumn: rangeData.endColumn,- };-- const rightRange = {- startRow: rangeData.startRow,- startColumn: rangeData.endColumn,- endRow: rangeData.endRow,- endColumn: rangeData.endColumn,- };-- const tr = new Range(_worksheet, topRangeOut);- const lr = new Range(_worksheet, leftRangeOut);- const br = new Range(_worksheet, bottomRangeOut);- const rr = new Range(_worksheet, rightRangeOut);- const t = new Range(_worksheet, topRange);- const l = new Range(_worksheet, leftRange);- const b = new Range(_worksheet, bottomRange);- const r = new Range(_worksheet, rightRange);-- const mtr = new ObjectMatrix<IStyleData>();- const mlr = new ObjectMatrix<IStyleData>();- const mbr = new ObjectMatrix<IStyleData>();- const mrr = new ObjectMatrix<IStyleData>();- const mcr = new ObjectMatrix<IStyleData>();-- const actions: ISheetActionData[] = [];-- const border: IBorderStyleData = {- s: style,- cl: {- rgb: color,- },- };-- if (top === true || top === false) {- // Probably to the border, there are no surrounding cells- if (tr.isValid()) {- // Clear the bottom border of the top range- tr.forEach((row, column) => {- mtr.setValue(row, column, { bd: { b: null } });- });-- const setBottomData: ISetRangeStyleActionData = {- sheetId: _sheetId,- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: mtr.getArrayData(),- rangeData: topRangeOut,- };- actions.push(setBottomData);- }-- // first row- t.forEach((row, column) => {- // update- if (top === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { t: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (top === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { t: null },- });- mcr.setValue(row, column, style);- }- });- }- if (bottom === true || bottom === false) {- // Probably to the border, there are no surrounding cells- if (br.isValid()) {- // Clear the top border of the lower range- br.forEach((row, column) => {- mbr.setValue(row, column, { bd: { t: null } });- });-- const setTopData: ISetRangeStyleActionData = {- sheetId: _sheetId,- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: mbr.getArrayData(),- rangeData: bottomRangeOut,- };- actions.push(setTopData);- }-- // the last row- b.forEach((row, column) => {- // update- if (bottom === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { b: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (bottom === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { b: null },- });- mcr.setValue(row, column, style);- }- });- }- if (left === true || left === false) {- // Probably to the border, there are no surrounding cells- if (lr.isValid()) {- // Clear the right border of the left range- lr.forEach((row, column) => {- mlr.setValue(row, column, { bd: { r: null } });- });-- const setRightData: ISetRangeStyleActionData = {- sheetId: _sheetId,- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: mlr.getArrayData(),- rangeData: leftRangeOut,- };- actions.push(setRightData);- }-- // first column- l.forEach((row, column) => {- // update- if (left === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { l: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (left === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { l: null },- });- mcr.setValue(row, column, style);- }- });- }- if (right === true || right === false) {- // Probably to the border, there are no surrounding cells- if (rr.isValid()) {- // Clear the left border of the right range- rr.forEach((row, column) => {- mrr.setValue(row, column, { bd: { l: null } });- });-- const setLeftData: ISetRangeStyleActionData = {- sheetId: _sheetId,- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: mrr.getArrayData(),- rangeData: rightRangeOut,- };- actions.push(setLeftData);- }-- // last column- r.forEach((row, column) => {- // update- if (right === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { r: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (right === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { r: null },- });- mcr.setValue(row, column, style);- }- });- }-- // inner vertical border- if (vertical === true || vertical === false) {- // current range- this.forEach((row, column) => {- // Set the right border except the last column- if (column !== rangeData.endColumn) {- // update- if (vertical === true) {- const style = Tools.deepMerge(- mcr.getValue(row, column) || {},- {- bd: { r: Tools.deepClone(border) },- }- );- mcr.setValue(row, column, style);- }- // delete- else if (vertical === false) {- const style = Tools.deepMerge(- mcr.getValue(row, column) || {},- {- bd: { r: null },- }- );- mcr.setValue(row, column, style);- }- }-- // Except for the first column, clear the left border- if (column !== rangeData.startColumn) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { l: null },- });- mcr.setValue(row, column, style);- }- });- }- // inner horizontal border- if (horizontal === true || horizontal === false) {- // current range- this.forEach((row, column) => {- // Except for the last row, set the bottom border- if (row !== rangeData.endRow) {- // update- if (horizontal === true) {- const style = Tools.deepMerge(- mcr.getValue(row, column) || {},- {- bd: { b: Tools.deepClone(border) },- }- );- mcr.setValue(row, column, style);- }- // delete- else if (horizontal === false) {- const style = Tools.deepMerge(- mcr.getValue(row, column) || {},- {- bd: { b: null },- }- );- mcr.setValue(row, column, style);- }- }-- // Except for the first row, clear the top border- if (row !== rangeData.startRow) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { t: null },- });- mcr.setValue(row, column, style);- }- });- }-- const setCCData: ISetRangeStyleActionData = {- sheetId: _sheetId,- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: mcr.getArrayData(),- rangeData: mcr.getDataRange(),- };- actions.push(setCCData);-- const commandCC = new Command(- {- WorkBookUnit: _workbook,- },- ...actions- );- _commandManager.invoke(commandCC);-- return this;- }-- /**- * Set Border by tool bar- * @param type border type- * @param color color- * @param style size- */- setBorderByType(type: BorderType, color: string, style: BorderStyleTypes) {- let top = null;- let left = null;- let bottom = null;- let right = null;- let vertical = null;- let horizontal = null;-- switch (type) {- case BorderType.TOP:- top = true;- break;- case BorderType.BOTTOM:- bottom = true;- break;- case BorderType.LEFT:- left = true;- break;- case BorderType.RIGHT:- right = true;- break;- case BorderType.NONE:- top = false;- left = false;- bottom = false;- right = false;- vertical = false;- horizontal = false;- break;- case BorderType.ALL:- top = true;- left = true;- bottom = true;- right = true;- vertical = true;- horizontal = true;- break;- case BorderType.OUTSIDE:- top = true;- left = true;- bottom = true;- right = true;- break;- case BorderType.INSIDE:- vertical = true;- horizontal = true;- break;- case BorderType.HORIZONTAL:- horizontal = true;- break;- case BorderType.VERTICAL:- vertical = true;- break;-- default:- break;- }-- this.setBorder(top, left, bottom, right, vertical, horizontal, color, style);- }-- /**- * Sets the font family, such as "Arial" or "Helvetica".- *- * @param fontFamily The font family to set; a null value resets the font family.- * @returns- */- setFontFamily(fontFamily: Nullable<string>): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const fontFamilyObj: IStyleData = { ff: fontFamily };- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- fontFamilyObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets the font size, with the size being the point size to use.- *- * @param size A font size in point size.- * @returns- */- setFontSize(size: number): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const fontSizeObj = { fs: size };- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- fontSizeObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Set the horizontal (left to right) alignment for the given range (left/center/right).- *- * @param alignment The alignment, either 'left', 'center' or 'normal'; a null value resets the alignment.- * @returns- */- setHorizontalAlignment(alignment: Nullable<HorizontalAlign>): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const horizontalAlignmentObj = { ht: alignment };- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- horizontalAlignmentObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).- *- * @param alignment The alignment, either 'top', 'middle' or 'bottom'; a null value resets the alignment.- * @returns- */- setVerticalAlignment(alignment: Nullable<VerticalAlign>): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const verticalAlignmentObj = { vt: alignment };- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- verticalAlignmentObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).- *- * @param direction The desired text direction; if null the direction is inferred before setting.- * @returns- */- setTextDirection(direction: Nullable<TextDirection>): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const textDirectionObj: IStyleData = { td: direction };- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- textDirectionObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets the text wrapping strategy for the cells in the range.- *- * @param strategy The desired wrapping strategy.- * @returns- */- setWrapStrategy(strategy: WrapStrategy): Range {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const wrapStrategyObj = { tb: strategy };- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- wrapStrategyObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets the value of the range. The value can be numeric, string, boolean or date. If it begins with '=' it is interpreted as a formula.- * @param value The value for the range.- * @returns This range, for chaining.- */- setValue(value: ICellV): Range {- const { _rangeData, _context, _commandManager, _worksheet } = this;- const { startRow, startColumn, endRow, endColumn } = _rangeData;- const cellValue = new ObjectMatrix<ICellV>();- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- cellValue.setValue(r, c, value);- }- }- const setValue: ISetRangeFormattedValueActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,- cellValue: cellValue.getData(),- rangeData: this._rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);-- return this;- }-- /**- * Sets a rectangular grid of values (must match dimensions of this range).- * @param values A two-dimensional array of values.- * @returns Range — This range, for chaining.- */- setValues(values: ICellV[][]): Range;- setValues(values: ObjectMatrix<ICellV>): Range;- setValues(...argument: any): Range {- const { _rangeData, _context, _commandManager, _worksheet } = this;- const values = argument[0];-- if (Tuples.checkup(argument, Array)) {- const { startRow, startColumn, endRow, endColumn } = _rangeData;-- const cellValue = new ObjectMatrix<ICellV>();- for (let r = 0; r <= endRow - startRow; r++) {- for (let c = 0; c <= endColumn - startColumn; c++) {- cellValue.setValue(r + startRow, c + startColumn, values[r][c]);- }- }-- const setValue: ISetRangeFormattedValueActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,- cellValue: cellValue.getData(),- rangeData: this._rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- } else if (Tuples.checkup(argument, ObjectMatrix)) {- const setValue: ISetRangeFormattedValueActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,- cellValue: values,- rangeData: this._rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- }-- return this;- }-- /**- * Sets cell data object for current range- * @param value Cell data object- * @returns- */- setRangeData(value: ICellData): Range {- const { _rangeData, _context, _commandManager, _worksheet } = this;- const { startRow, startColumn } = _rangeData;- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: {- [startRow]: {- [startColumn]: value,- },- },- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);-- return this;- }-- /**- * Sets a rectangular grid of cell obejct data (must match dimensions of this range).- * @param values A two-dimensional array of cell object data.- * @returns Range — This range, for chaining.- */- setRangeDatas(values: ICellData[][]): Range;- setRangeDatas(values: ObjectMatrixPrimitiveType<ICellData>): Range;- setRangeDatas(...argument: any): Range {- const { _rangeData, _context, _commandManager, _worksheet } = this;- const values = argument[0];-- if (Tuples.checkup(argument, Array)) {- const { startRow, startColumn, endRow, endColumn } = _rangeData;-- const cellValue = new ObjectMatrix<ICellData>();- for (let r = 0; r <= endRow - startRow; r++) {- for (let c = 0; c <= endColumn - startColumn; c++) {- cellValue.setValue(r + startRow, c + startColumn, values[r][c]);- }- }-- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: cellValue.getData(),- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- } else if (Tuples.checkup(argument, Tuples.OBJECT_TYPE)) {- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: values,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- }-- return this;- }-- /**- * Clears the range of contents, formats, and data validation rules.- * @returns This range, for chaining.- */- clear(): Range;- /**- * Clears the range of contents and/or format, as specified with the given advanced options. By default all data is cleared.- * @param options A JavaScript object that specifies advanced parameters, as listed below.- * @returns This range, for chaining.- */- clear(options: IOptionData): Range;- clear(...argument: any): Range {- const { _context, _worksheet, _commandManager, _rangeData } = this;-- // default options- let options = {- formatOnly: true,- contentsOnly: true,- };- if (Tuples.checkup(argument, Tuples.OBJECT_TYPE)) {- options = argument[0];- }-- const setValue: IClearRangeActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.CLEAR_RANGE_ACTION,- options,- rangeData: _rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);-- return this;- }-- /**- * Clears formatting for this range.- *- * This clears text formatting for the cell or cells in the range, but does not reset any number formatting rules.- *- * @returns Range This range, for chaining.- */- clearFormat(): Range {- return this.clear({ formatOnly: true });- }-- /**- * Clears the content of the range, leaving the formatting intact.- *- * @returns Range This range, for chaining.- */- clearContent(): Range {- return this.clear({ contentsOnly: true });- }-- /**- * Deletes this range of cells. Existing data in the sheet along the provided dimension is shifted towards the deleted range.- *- * solution: Clear the range to be deleted, and then set the new value of the cell content at the bottom using setValue- * @param {Dimension} shiftDimension The dimension along which to shift existing data.- * @returns void- */- deleteCells(shiftDimension: Dimension): void {- const { _rangeData, _context, _commandManager, _worksheet } = this;-- const setValue: IDeleteRangeActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.DELETE_RANGE_ACTION,- shiftDimension,- rangeData: _rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- }-- /**- * Inserts empty cells into this range. The new cells retain any formatting present in the cells previously occupying this range. Existing data in the sheet along the provided dimension is shifted away from the inserted range.- * @param {Dimension} shiftDimension The dimension along which to shift existing data.- * @returns Range This range, for chaining.- */- insertCells(shiftDimension: Dimension): Range;- insertCells(shiftDimension: Dimension, destination: Range): Range;- insertCells(...argument: any): Range {- const shiftDimension = argument[0];- const destination: Range = argument[1];- const { _rangeData, _context, _commandManager, _worksheet } = this;- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- let rangeData = this._rangeData;-- // TODO 1. 补充另一个方向- // 2. 重载,传入数据,范围根据数据范围变化-- // build blank values- let cellValue = new ObjectMatrix<ICellData>();- if (destination) {- cellValue = destination.getMatrixObject();-- const destinationRangeData = destination.getRangeData();-- rangeData = {- startRow,- endRow:- startRow +- destinationRangeData.endRow -- destinationRangeData.startRow,- startColumn,- endColumn:- startRow +- destinationRangeData.endColumn -- destinationRangeData.startColumn,- };- } else {- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- cellValue.setValue(r, c, { m: '', v: '' });- }- }- }-- const insertValue: IInsertRangeActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.INSERT_RANGE_ACTION,- shiftDimension,- rangeData,- cellValue: cellValue.getData(),- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- insertValue- );- _commandManager.invoke(command);- return this;- }-- /**- * Merges the cells in the range together into a single block.- *- * @returns Range — This range, for chaining.- */- merge(): Range {- const { _worksheet } = this;- const merges = _worksheet.getMerges();- merges.add(this._rangeData);- return this;- }-- /**- * Merge the cells in the range across the columns of the range.- *- * @returns Range — This range, for chaining.- */- mergeAcross(): Range {- const { _worksheet } = this;- const _commandManager = _worksheet.getCommandManager();- const _context = _worksheet.getContext();- const _sheetId = _worksheet.getSheetId();-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const rectangles = [];-- for (let r = startRow; r <= endRow; r++) {- const data = {- startRow: r,- endRow: r,- startColumn,- endColumn,- };- rectangles.push(data);- }- const dataRowInsert: IAddMergeActionData = {- actionName: ACTION_NAMES.ADD_MERGE_ACTION,- sheetId: _sheetId,- rectangles,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- dataRowInsert- );- _commandManager.invoke(command);-- return this;- }-- /**- * Merges the cells in the range together.- *- * @returns Range — This range, for chaining.- */- mergeVertically(): Range {- const { _worksheet } = this;- const _commandManager = _worksheet.getCommandManager();- const _context = _worksheet.getContext();- const _sheetId = _worksheet.getSheetId();-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;- const rectangles = [];-- for (let c = startColumn; c <= endColumn; c++) {- const data = {- startRow,- endRow,- startColumn: c,- endColumn: c,- };- rectangles.push(data);- }- const dataRowInsert: IAddMergeActionData = {- actionName: ACTION_NAMES.ADD_MERGE_ACTION,- sheetId: _sheetId,- rectangles,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- dataRowInsert- );- _commandManager.invoke(command);-- return this;- }-- /**- * Break any multi-column cells in the range into individual cells again.-- Calling this function on a range is equivalent to selecting a range and clicking Format -> Merge -> Unmerge.-- @returns Range — This range, for chaining.- */- breakApart(): Range {- // 您必须选中某个合并范围内的所有单元格才能执行合并或撤消合并。- const { _worksheet } = this;- const _commandManager = _worksheet.getCommandManager();- const _context = _worksheet.getContext();- const _sheetId = _worksheet.getSheetId();-- const rectangles = this._worksheet- .getMerges()- .getMergedRanges(this._rangeData);-- const dataRowInsert: IRemoveMergeActionData = {- actionName: ACTION_NAMES.REMOVE_MERGE_ACTION,- sheetId: _sheetId,- rectangles,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- dataRowInsert- );- _commandManager.invoke(command);-- return this;- }-- /**- * Removes rows within this range that contain values that are duplicates of values in any previous row. Rows with identical values but different letter cases, formatting, or formulas are considered to be duplicates. This method also removes duplicates rows hidden from view (for example, due to a filter). Content outside of this range isn't removed.- *- * @returns Range The resulting range after removing duplicates. The size of the range is reduced by a row for every row removed.- */- removeDuplicates(): Range;-- /**- * Removes rows within this range that contain values in the specified columns that are duplicates of values any previous row. Rows with identical values but different letter cases, formatting, or formulas are considered to be duplicates. This method also removes duplicates rows hidden from view (for example, due to a filter). Content outside of this range isn't removed.- * @param columnsToCompare The columns to analyze for duplicate values. If no columns are provided then all columns are analyzed for duplicates.- * @returns Range The resulting range after removing duplicates. The size of the range is reduced by a row for every row removed.- */- removeDuplicates(columnsToCompare: number[]): Range;- removeDuplicates(...argument: any): Range {- const { _rangeData, _context, _commandManager, _worksheet } = this;- let columnsToCompare = [];- // set columns- if (Array.isArray(argument[0])) {- columnsToCompare = argument[0];- }-- const newCellValue = this.getMatrix().getData();-- const rowList: number[][] = [];-- for (let i = 0; i <= _rangeData.endColumn - _rangeData.startColumn; i++) {- const arr: number[] = [];- const obj: any = {};-- const column = this.getColumnMatrix(i).getData();- for (const key in column) {- // if (column.hasOwnProperty(key)) {- const value = column[key][i].m;-- if (!obj.hasOwnProperty(value)) {- obj[value!] = 1;- arr.push(i);- }- // }- }-- rowList.push(arr);- }-- const newRowList = Array.from(new Set(rowList.flat()));-- const newData: { [key: number]: { [key: number]: ICellData } } = {};-- newRowList.forEach((item, i) => {- newData[i] = newCellValue[item];- });-- const removeDatas: ISetRangeDataActionData[] = [- {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: newData,- },- ];- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...removeDatas- );- _commandManager.invoke(command);- return this;- }-- /**- * get row matrix- * @returns- */- getRowMatrix(index: number) {- const { startColumn, endColumn } = this._rangeData;-- const sheetMatrix = this._worksheet.getCellMatrix();- const rangeMatrix = new ObjectMatrix<ICellData>();-- for (let r = index; r <= index; r++) {- for (let c = startColumn; c <= endColumn; c++) {- rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || {});- }- }-- return rangeMatrix;- }-- /**- * get column matrix- * @returns- */- getColumnMatrix(index: number) {- const { startRow, endRow } = this._rangeData;-- const sheetMatrix = this._worksheet.getCellMatrix();- const rangeMatrix = new ObjectMatrix<ICellData>();-- for (let r = startRow; r <= endRow; r++) {- for (let c = index; c <= index; c++) {- rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || {});- }- }-- return rangeMatrix;- }-- forEach(action: (row: number, column: number) => void): void {- Range.foreach(this._rangeData, action);- }-- /**- * Randomizes the order of the rows in the given range.- * TODO:待研究特性- * 1. 公式内的范围也会变化- * 2. 并不是所有范围都支持随机处理- * @returns- */- randomize() {- const { _context, _worksheet, _commandManager, _rangeData } = this;- const { startRow, startColumn } = _rangeData;- const cellValue = new ObjectMatrix<ICellData>();-- const value = Tools.randSort(this.getMatrix().toArray());-- value.forEach((row, r) =>- row.forEach((cell, c) => {- cell = cell as ICellData;- cellValue.setValue(r + startRow, c + startColumn, cell || {});- })- );-- const setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- cellValue: cellValue.getData(),- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);- }-- /**- * Determine whether a range is legal- */- isValid(): boolean {- if (Object.values(this._rangeData).includes(-1)) {- return false;- }- return true;- }-- /**- * en:- *- * The process of copying a range to another range is obtained by the following rules- *- * [The two-dimensional array composed of the content or format to be assigned] => [Target range]- *- * 1. 1 -> 1: 1 => 1- * 2. N -> 1: N => N- * 3. 1 -> N: N => N- * 4. N1 -> N2:- * 1) N1 <N2: If N2 is a multiple of N1 (X), N1 * X => N2; If not, N1 => N1 (refer to office excel, different from google sheet)- * 2) N1> N2: N1 => N1- *- * The above four cases can be combined and processed as- *- * Case 1, 1/2/4-2 merged into N1 => N1- * Case 2, 3/4-1 merge into N1 * X => N2 or Case 1- *- * In the end we only need to judge whether N2 is a multiple of N1- *- * zh:- *- * 处理复制一个范围到另一个范围,由以下规则得到- *- * [将要赋值的内容或者格式组成的二维数组] => [目标范围]- *- * 1. 1 -> 1 : 1 => 1- * 2. N -> 1 : N => N- * 3. 1 -> N : N => N- * 4. N1 -> N2 :- * 1) N1 < N2 : 如果N2是N1的倍数X, N1 * X => N2; 如果不是,N1 => N1(参考office excel,和google sheet不同)- * 2) N1 > N2 : N1 => N1- *- * 上面四种情况,可以合并处理为- * 情况一, 1/2/4-2合并为 N1 => N1- * 情况二, 3/4-1合并为 N1 * X => N2 或者情况一- *- * 最终我们只需要判断N2是否是N1的倍数- *- */- private _handleCopyRange(- originRange: Range,- destinationRange: IRangeData- ): [ICellDataMatrix, IRangeData];- private _handleCopyRange(- originRange: Range,- destinationRange: Range- ): [ICellDataMatrix, IRangeData];- private _handleCopyRange(...argument: any): [ICellDataMatrix, IRangeData] {- const originRange = argument[0];- let destinationRange = argument[1];- destinationRange = Tuples.checkup(argument, Range, Range)- ? destinationRange.getRangeData()- : destinationRange;-- const cellData = originRange._worksheet.getCellMatrix();- const { startRow, endRow, startColumn, endColumn } =- originRange.getRangeData();- let {- startRow: dStartRow,- endRow: dEndRow,- startColumn: dStartColumn,- endColumn: dEndColumn,- } = destinationRange;-- const originRows = endRow - startRow + 1;- const originColumns = endColumn - startColumn + 1;- const destinationRows = dEndRow - dStartRow + 1;- const destinationColumns = dEndColumn - dStartColumn + 1;-- let value: ICellDataMatrix = [];- let range: IRangeData;-- // judge whether N2 is a multiple of N1- if (- destinationRows % originRows === 0 &&- destinationColumns % originColumns === 0- ) {- /**- * A1,B1 => A1,B1,C1,D1- * A2,B2 A2,B2,C2,D2- * A3,B3,C3,D3- * A4,B4,C4,D4- */- for (let r = 0; r < destinationRows; r++) {- const row = [];- for (let c = 0; c < destinationColumns; c++) {- // Retrieve the corresponding cell data from the original range, {} as a fallback- const cell =- cellData.getValue(- (r + startRow) % originRows,- (c + startColumn) % originColumns- ) || {};- row.push(cell);- }- value.push(row);- }-- range = destinationRange;- } else {- value = cellData- .getFragments(startRow, endRow, startColumn, endColumn)- .getData();-- // Extend the destination to the same size as the original range- dEndRow += originRows - destinationRows;- dEndColumn += originColumns - destinationColumns;-- range = {- startRow: dStartRow,- endRow: dEndRow,- startColumn: dStartColumn,- endColumn: dEndColumn,- };- }-- return [value, range];- }-- /**- *- * @param arg Shorthand for the style that gets- * @returns style value- */- private _getStyles<K>(- arg: keyof IStyleData- ): Array<Array<IStyleData[keyof IStyleData]>> {- return this.getValues().map((row) =>- row.map((cell: Nullable<ICellData>) => {- const styles = this._context.getWorkBook().getStyles();-- // const style = getStyle(styles, cell);- const style = styles && styles.getStyleByCell(cell);- return (style && style[arg]) || DEFAULT_STYLES[arg];- })- );- }-- // isStartColumnBounded() {}- // isStartRowBounded() {}-- private _setStyle(- value: Nullable<string | number | ITextDecoration>,- type: string- ) {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- // string converted to a two-dimensional array- const styleObj = { [type]: value };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: SetRangeStyleAction.NAME,- value: stylesMatrix,- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- private _setStyles(- values: Array<Array<Nullable<string | number | ITextDecoration>>>,- type: string- ) {- const { _context, _worksheet, _commandManager } = this;-- const { startRow, endRow, startColumn, endColumn } = this._rangeData;-- const matrix = new ObjectMatrix<IStyleData>();- for (let r = 0; r < endRow - startRow + 1; r++) {- for (let c = 0; c < endColumn - startColumn + 1; c++) {- matrix.setValue(r, c, { [type]: values[r][c] });- }- }- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: matrix.getData(),- rangeData: this._rangeData,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setStyle- );- _commandManager.invoke(command);- return this;- }-- // /**- // * Applies a default row banding theme to the range. By default, the banding has header and no footer color.- // */- // applyRowBanding(): Nullable<Banding>;-- // /**- // * Applies a specified row banding theme to the range. By default, the banding has header and no footer color.- // * @param bandingTheme- // */- // applyRowBanding(bandingTheme: BandingTheme | IBandingProperties): Nullable<Banding>;-- // /**- // * Applies a specified row banding theme to the range with specified header and footer settings.- // * @param bandingTheme- // * @param showHeader- // * @param showFooter- // */- // applyRowBanding(- // bandingTheme: BandingTheme | IBandingProperties,- // showHeader: boolean,- // showFooter: boolean- // ): Nullable<Banding>;- // applyRowBanding(...argument: any): Nullable<Banding> {-- // // default argument- // const bandedRangeId = 'banded-range-' + Tools.generateRandomId(6);- // const rangeData = this.getRangeData()- // let rowProperties:IBanding = {- // bandingTheme:argument[0] || BandingTheme.LIGHT_GRAY,- // showHeader:argument[1] || true,- // showFooter:argument[2] || false,- // }-- // const { _context, _commandManager } = this;- // // Check whether the incoming range has been set to alternate colors- // const bandings = this.getSheet().getBandings();- // const isIntersection =- // bandings &&- // bandings.find((banding: Banding) =>- // banding.getRange().isIntersection(this)- // );- // if (isIntersection) {- // console.error(- // 'You cannot add alternating background colors to a range that already has alternating background colors.'- // );- // return- // }-- // // Organize action data- // const actionData: IAddBandingActionData = {- // actionName: ACTION_NAMES.ADD_BANDING_ACTION,- // bandedRange:{- // bandedRangeId,- // rangeData,- // rowProperties- // },- // sheetId: this.getSheet().getSheetId(),- // };-- // // Execute action- // const command = new Command(_context.getWorkBook(), actionData);- // _commandManager.invoke(command);-- // return this.getSheet().getBandingById(bandedRangeId)- // }- // /**- // * Applies a default row banding theme to the range. By default, the banding has header and no footer color.- // */- // applyRowBanding(): Nullable<Banding>;-- // /**- // * Applies a specified row banding theme to the range. By default, the banding has header and no footer color.- // * @param bandingTheme- // */- // applyRowBanding(- // bandingTheme: BandingTheme | IBandingProperties- // ): Nullable<Banding>;-- // /**- // * Applies a specified row banding theme to the range with specified header and footer settings.- // * @param bandingTheme- // * @param showHeader- // * @param showFooter- // */- // applyRowBanding(- // bandingTheme: BandingTheme | IBandingProperties,- // showHeader: boolean,- // showFooter: boolean- // ): Nullable<Banding>;- // applyRowBanding(...argument: any): Nullable<Banding> {- // // default argument- // const bandedRangeId = 'banded-range-' + Tools.generateRandomId(6);- // const rangeData = this.getRangeData();- // let rowProperties: IBanding = {- // bandingTheme: argument[0] || BandingTheme.LIGHT_GRAY,- // showHeader: argument[1] || true,- // showFooter: argument[2] || false,- // };-- // const { _worksheet } = this;- // // Check whether the incoming range has been set to alternate colors- // const bandedRanges = _worksheet.getConfig().bandedRanges;- // const isIntersection =- // bandedRanges &&- // bandedRanges.find((bandedRange: IBandedRange) =>- // _worksheet.getRange(bandedRange.rangeData).isIntersection(this)- // );- // if (isIntersection) {- // console.error(- // 'You cannot add alternating background colors to a range that already has alternating background colors.'- // );- // return;- // }-- // return new Banding(this._worksheet).addRowBanding({- // bandedRangeId,- // rangeData,- // rowProperties,- // });- // }-- /**- * Creates a filter applied to the range. There can be at most one filter in a sheet.- * @returns The new filter.- */- // createFilter(): Filter {- // return new Filter(this);- // }-}--// Alternating Colors = bandingIns, range.applyRowBanding() bandingIns.setRowBanding(XXX) // bandingIns.remove(id)+import { SheetContext } from '../../Basics';++import {+ IInsertRangeActionData,+ IClearRangeActionData,+ IAddMergeActionData,+ IRemoveMergeActionData,+ IDeleteRangeActionData,+ ISetRangeDataActionData,+ ISetRangeStyleActionData,+ ISetRangeFormattedValueActionData,+ SetRangeStyleAction,+} from '../Action';++import { CommandManager, ISheetActionData, Command } from '../../Command';++import { DEFAULT_RANGE, DEFAULT_STYLES, ACTION_NAMES } from '../../Types/Const';++import {+ BooleanNumber,+ BorderStyleTypes,+ BorderType,+ Dimension,+ Direction,+ FontItalic,+ FontWeight,+ HorizontalAlign,+ TextDirection,+ VerticalAlign,+ WrapStrategy,+ CopyPasteType,+} from '../../Types/Enum';++import {+ IBorderData,+ IBorderStyleData,+ ICellData,+ ICellDataMatrix,+ ICellV,+ IDocumentData,+ IOptionData,+ IRangeData,+ IRangeType,+ IStyleData,+ ITextDecoration,+} from '../../Types/Interfaces';++import {+ Nullable,+ ObjectMatrix,+ ObjectMatrixPrimitiveType,+ Tools,+ Tuples,+} from '../../Shared';++import { Worksheet } from './Worksheet';++/**+ * getObjectValues options type+ */+type IValueOptionsType = {+ /**+ * set whether to include style+ */+ isIncludeStyle?: boolean;+};++/**+ * Access and modify spreadsheet ranges.+ *+ * @remarks+ * A range can be a single cell in a sheet or a group of adjacent cells in a sheet.+ *+ * Reference from: https://developers.google.com/apps-script/reference/spreadsheet/range+ *+ * @beta+ */+export class Range {+ private _commandManager: CommandManager;++ private _context: SheetContext;++ private _rangeData: IRangeData;++ private _worksheet: Worksheet;++ constructor(workSheet: Worksheet, range: IRangeType) {+ this._context = workSheet.getContext();+ this._commandManager = this._context.getCommandManager();++ // Convert the range passed in by the user into a standard format+ // this._rangeData = new TransformTool(+ // this._context.getWorkBook()+ // ).transformRangeType(range);+ this._rangeData = this._context+ .getWorkBook()+ .transformRangeType(range).rangeData;+ this._worksheet = workSheet;++ // The user entered an invalid range+ if (Object.values(this._rangeData).includes(-1)) {+ console.error('Invalid range,default set index -1');+ }+ }++ static foreach(+ rangeData: IRangeData,+ action: (row: number, column: number) => void+ ): void {+ const { startRow, startColumn, endRow, endColumn } = rangeData;+ for (let i = startRow; i <= endRow; i++) {+ for (let j = startColumn; j <= endColumn; j++) {+ action(i, j);+ }+ }+ }++ /**+ * get current range data+ *+ * @returns current range+ */+ getRangeData(): IRangeData {+ return this._rangeData;+ }++ /**+ * Returns the value of the top-left cell in the range. The value may be of type Number, Boolean, Date, or String depending on the value of the cell. Empty cells return an empty string.+ * @returns The value in this cell+ */+ getValue(): Nullable<ICellData> {+ return this.getValues()[0][0];+ }++ /**+ * Returns the rectangular grid of values for this range.+ *+ * Returns a two-dimensional array of values, indexed by row, then by column. The values may be of type Number, Boolean, Date, or String, depending on the value of the cell. Empty cells are represented by an empty string in the array. Remember that while a range index starts at 0, 0, same as the JavaScript array is indexed from [0][0].+ *+ * In web apps, a Date value isn't a legal parameter. getValues() fails to return data to a web app if the range contains a cell with a Date value. Instead, transform all the values retrieved from the sheet to a supported JavaScript primitive like a Number, Boolean, or String.+ *+ * @returns A two-dimensional array of values.+ */+ getValues(): Array<Array<Nullable<ICellData>>> {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const range: Array<Array<Nullable<ICellData>>> = [];+ for (let r = startRow; r <= endRow; r++) {+ const row: Array<Nullable<ICellData>> = [];+ for (let c = startColumn; c <= endColumn; c++) {+ row.push(this.getMatrix().getValue(r, c) || null);+ }+ range.push(row);+ }+ return range;+ }++ /**+ * get range matrix+ *+ * @returns range matrix+ */+ getMatrix(): ObjectMatrix<ICellData> {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const sheetMatrix = this._worksheet.getCellMatrix();+ const rangeMatrix = new ObjectMatrix<ICellData>();++ for (let r = startRow; r <= endRow; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || null);+ }+ }++ return rangeMatrix;+ }++ /**+ * get range matrix object+ *+ * @returns range matrix object+ */+ getMatrixObject(): ObjectMatrix<ICellData> {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const sheetMatrix = this._worksheet.getCellMatrix();+ const rangeMatrix = new ObjectMatrix<ICellData>();++ for (let r = startRow; r <= endRow; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ rangeMatrix.setValue(+ r - startRow,+ c - startColumn,+ sheetMatrix.getValue(r, c) || {}+ );+ }+ }++ return rangeMatrix;+ }++ /**+ * Returns the displayed value of the top-left cell in the range. The value is a String. The displayed value takes into account date, time and currency formatting formatting, including formats applied automatically by the spreadsheet's Locale setting. Empty cells return an empty string.+ *+ * @returns The displayed value in this cell.+ */+ getDisplayValue(): string | IDocumentData {+ const value = this.getValue();+ if (value && value.p) {+ return value.p;+ }+ if (value && value.m) {+ return value.m;+ }+ return '';+ }++ /**+ * Returns the rectangular grid of values for this range.+ *+ * Returns a two-dimensional array of displayed values, indexed by row, then by column. The values are String objects. The displayed value takes into account date, time and currency formatting, including formats applied automatically by the spreadsheet's Locale setting. Empty cells are represented by an empty string in the array. Remember that while a range index starts at 0, 0, same as the JavaScript array is indexed from [0][0].+ *+ * @returns — A two-dimensional array of values.+ */+ getDisplayValues(): Array<Array<string | IDocumentData>> {+ return this.getValues().map((row) =>+ row.map((value: Nullable<ICellData>) => {+ if (value && value.p) {+ return value.p;+ }+ if (value && value.m) {+ return value.m;+ }+ return '';+ })+ );+ }++ /**+ * Returns a string description of the range, in A1 notation.+ *+ * @returns The string description of the range in A1 notation.+ */+ getA1Notation(): string {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ let start;+ let end;+ if (startColumn < endColumn) {+ start = Tools.numToWord(startColumn + 1) + (startRow + 1);+ end = Tools.numToWord(endColumn + 1) + (endRow + 1);+ } else {+ start = Tools.numToWord(endColumn + 1) + (endRow + 1);+ end = Tools.numToWord(startColumn + 1) + (startRow + 1);+ }++ if (start === end) return `${start}`;+ return `${start}:${end}`;+ }++ /**+ * Returns the background color of the top-left cell in the range (for example, '#ffffff').+ *+ * @returns — The color code of the background.+ */+ getBackground(): string {+ return this.getBackgrounds()[0][0];+ }++ /**+ * Returns the background colors of the cells in the range (for example, '#ffffff').+ *+ * @returns — A two-dimensional array of color codes of the backgrounds.+ */+ getBackgrounds(): string[][] {+ return this.getValues().map((row) =>+ row.map((cell: Nullable<ICellData>) => {+ const styles = this._context.getWorkBook().getStyles();+ let rgbColor: string = DEFAULT_STYLES.bg?.rgb!;+ rgbColor = styles.getStyleByCell(cell)?.bg?.rgb!;+ return rgbColor;+ })+ );+ }++ /**+ * Returns a given cell within a range.+ *+ * The row and column here are relative to the range+ * e.g. "B2:D4", getCell(0,0) in this code returns the cell at B2+ * @returns — A range containing a single cell at the specified coordinates.+ */+ getCell(row: number, column: number): Range {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const cell = {+ startRow: startRow + row,+ endRow: startRow + row,+ startColumn: startColumn + column,+ endColumn: startColumn + column,+ };++ return new Range(this._worksheet, cell);+ }++ /**+ * Returns the starting column position for this range+ *+ * @returns — The range's starting column position in the spreadsheet.+ */+ getColumn(): number {+ return this._rangeData.startColumn;+ }++ /**+ * Returns the data of the object structure, and can set whether to bring styles+ */+ getObjectValue(options: IValueOptionsType = {}): ICellData {+ return this.getObjectValues(options)[0][0];+ }++ /**+ * Returns the data of the object structure, and can set whether to bring styles+ *+ * @param options set whether to include style+ * @returns Returns a value in object format+ */+ getObjectValues(+ options: IValueOptionsType = {}+ ): ObjectMatrixPrimitiveType<ICellData> {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // get object values from sheet matrix, or use this.getMatrix() create a new matrix then this.getMatrix().getData()+ const values = this._worksheet+ .getCellMatrix()+ .getFragments(startRow, endRow, startColumn, endColumn)+ .getData();++ if (options.isIncludeStyle) {+ const style = this._context.getWorkBook().getStyles();+ for (let r = 0; r <= endRow - startRow; r++) {+ for (let c = 0; c <= endColumn - startColumn; c++) {+ // handle null+ if (!values[r][c]) continue;++ const s = values[r][c].s;++ // make sure value has style+ if (s) {+ values[r][c].s = style.get(s);+ }+ }+ }+ }++ return values;+ }++ /**+ * Notify other Components+ * TODO: 待触发更新测试+ */+ // notifyUpdated() {+ // this._context.onAfterChangeRangeDataObservable.notifyObservers(+ // this._worksheet+ // );+ // }++ /**+ * Returns the font color of the cell in the top-left corner of the range, in CSS notation+ */+ getFontColor(): Nullable<string> {+ return this.getFontColors()[0][0];+ }++ /**+ * Returns the font colors of the cells in the range in CSS notation (such as '#ffffff' or 'white').+ */+ getFontColors(): Array<Array<Nullable<string>>> {+ return this.getValues().map((row) =>+ row.map((cell: Nullable<ICellData>) => {+ const styles = this._context.getWorkBook().getStyles();+ const cellStyle = styles.getStyleByCell(cell);+ return cellStyle?.cl?.rgb || DEFAULT_STYLES.cl?.rgb;+ })+ );+ }++ /**+ * Returns the font families of the cells in the range.+ */+ getFontFamilies(): string[][] {+ return this._getStyles('ff') as string[][];+ }++ /**+ * Returns the font family of the cell in the top-left corner of the range.+ */+ getFontFamily(): string {+ return this.getFontFamilies()[0][0];+ }++ /**+ * Returns the underlines of the cells in the range.+ */+ getUnderlines(): ITextDecoration[][] {+ return this._getStyles('ul') as ITextDecoration[][];+ }++ /**+ * Returns the underline of the cells in the range.+ */+ getUnderline(): ITextDecoration {+ return this.getUnderlines()[0][0];+ }++ /**+ * Returns the overlines of the cells in the range.+ */+ getOverlines(): ITextDecoration[][] {+ return this._getStyles('ol') as ITextDecoration[][];+ }++ /**+ * Returns the overline of the cells in the range.+ */+ getOverline(): ITextDecoration {+ return this.getOverlines()[0][0];+ }++ /**+ * Returns the strikeThroughs of the cells in the range.+ */+ getStrikeThroughs(): ITextDecoration[][] {+ return this._getStyles('st') as ITextDecoration[][];+ }++ /**+ * Returns the strikeThrough of the cells in the range.+ */+ getStrikeThrough(): ITextDecoration {+ return this.getStrikeThroughs()[0][0];+ }++ /**+ * Returns the font size in point size of the cell in the top-left corner of the range.+ */+ getFontSize(): number {+ return this.getFontSizes()[0][0];+ }++ /**+ * Returns the font sizes of the cells in the range.+ */+ getFontSizes(): number[][] {+ return this._getStyles('fs') as number[][];+ }++ /**+ * Returns the border info of the cells in the range.+ */++ getBorder(): IBorderData {+ return this.getBorders()[0][0];+ }++ getBorders(): IBorderData[][] {+ return this._getStyles('bd') as IBorderData[][];+ }++ /**+ * Returns the font style ('italic' or 'normal') of the cell in the top-left corner of the range.+ */+ getFontStyle(): FontItalic {+ return this.getFontStyles()[0][0];+ }++ /**+ * Returns the font styles of the cells in the range.+ */+ getFontStyles(): FontItalic[][] {+ return this._getStyles('it') as FontItalic[][];+ }++ /**+ * Returns the font weight (normal/bold) of the cell in the top-left corner of the range.+ */+ getFontWeight(): FontWeight {+ return this.getFontWeights()[0][0];+ }++ /**+ * Returns the font weights of the cells in the range.+ */+ getFontWeights(): FontWeight[][] {+ return this._getStyles('bl') as FontWeight[][];+ }++ /**+ * Returns the formula (A1 notation) for the top-left cell of the range, or an empty string if the cell is empty or doesn't contain a formula.+ */+ // getFormula(): string {+ // return this.getFormulas()[0][0];+ // }++ /**+ * Returns the formulas (A1 notation) for the cells in the range.+ */+ // getFormulas(): string[][] {+ // return this.getValues().map((row) =>+ // row.map((cell: Nullable<ICellData>) => cell?.f || '')+ // );+ // }++ /**+ * Returns the grid ID of the range's parent sheet.+ */+ getGridId(): string {+ return this._worksheet.getSheetId();+ }++ /**+ * Returns the height of the range.+ */+ getHeight(): number {+ const { _rangeData, _worksheet } = this;+ const { startRow, endRow } = _rangeData;+ let h = 0;+ for (let i = 0; i <= endRow - startRow; i++) {+ const hh = _worksheet.getRowHeight(i);+ h += hh;+ }+ return h;+ }++ /**+ * Returns the horizontal alignment of the text (left/center/right) of the cell in the top-left corner of the range.+ */+ getHorizontalAlignment(): HorizontalAlign {+ return this.getHorizontalAlignments()[0][0];+ }++ /**+ *Returns the horizontal alignments of the cells in the range.+ */+ getHorizontalAlignments(): HorizontalAlign[][] {+ return this._getStyles('ht') as HorizontalAlign[][];+ }++ /**+ * Returns the end column position.+ */+ getLastColumn(): number {+ return this._rangeData.endColumn;+ }++ /**+ * Returns the end row position.+ */+ getLastRow(): number {+ return this._rangeData.endRow;+ }++ /**+ * Returns an array of Range objects representing merged cells that either are fully within the current range, or contain at least one cell in the current range.+ */+ getMergedRanges(): Range[] {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ return this._worksheet+ .getMerges()+ .getMergedRanges({ startRow, endRow, startColumn, endColumn })+ .map((rangeData) => new Range(this._worksheet, rangeData));+ }++ /**+ * Starting at the cell in the first column and row of the range, returns the next cell in the given direction that is the edge of a contiguous range of cells with data in them or the cell at the edge of the spreadsheet in that direction.+ * @param direction+ * @returns The data region edge cell or the cell at the edge of the spreadsheet.+ */+ getNextDataCell(direction: Direction): Range {+ const { _worksheet } = this;+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const maxRow = _worksheet.getMaxRows();+ const maxColumn = _worksheet.getMaxColumns();+ if (direction === Direction.BOTTOM) {+ for (let i = 0; i < maxRow - startColumn; i++) {+ const value = this._worksheet+ .getCellMatrix()+ .getValue(startRow + i, startColumn);+ if (value)+ _worksheet.getRange(+ startRow + i,+ startColumn,+ startRow + i,+ startColumn+ );+ }+ return _worksheet.getRange(maxRow, startColumn, maxRow, startColumn);+ }+ if (direction === Direction.TOP) {+ for (let i = 0; i < startRow; i++) {+ const value = this._worksheet+ .getCellMatrix()+ .getValue(startRow - i, startColumn);+ if (value)+ _worksheet.getRange(+ startRow - i,+ startColumn,+ startRow - i,+ startRow+ );+ }+ return _worksheet.getRange(0, startColumn, 0, startColumn);+ }+ if (direction === Direction.RIGHT) {+ for (let i = 0; i < maxColumn - startColumn; i++) {+ const value = this._worksheet+ .getCellMatrix()+ .getValue(startRow, startColumn + i);+ if (value)+ _worksheet.getRange(+ startRow,+ startColumn + i,+ startRow,+ startColumn + i+ );+ }+ return _worksheet.getRange(startRow, maxColumn, startRow, maxColumn);+ }+ if (direction === Direction.LEFT) {+ for (let i = 0; i < maxRow - startColumn; i++) {+ const value = this._worksheet+ .getCellMatrix()+ .getValue(startRow, startColumn - i);+ if (value)+ _worksheet.getRange(+ startRow,+ startColumn - i,+ startRow,+ startColumn - i+ );+ }+ return _worksheet.getRange(startRow, 0, startRow, 0);+ }+ return _worksheet.getRange(DEFAULT_RANGE);+ }++ /**+ * Returns the note associated with the given range.+ */+ // getNote(): string {+ // return this.getNotes()[0][0];+ // }++ /**+ * Returns the notes associated with the cells in the range.+ */+ // getNotes(): string[][] {+ // return this.getValues().map((row) =>+ // row.map((cell: Nullable<ICellData>) => cell?.n || '')+ // );+ // }++ /**+ * Returns the number of columns in this range.+ */+ getNumColumns(): number {+ const { startColumn, endColumn } = this._rangeData;+ return endColumn - startColumn + 1;+ }++ /**+ * Returns the number of rows in this range.+ */+ getNumRows(): number {+ const { startRow, endRow } = this._rangeData;+ return endRow - startRow + 1;+ }++ /**+ * Get the number or date formatting of the top-left cell of the given range.+ */+ // getNumberFormat(): string {+ // return this.getNumberFormats()[0][0];+ // }++ /**+ * Returns the number or date formats for the cells in the range.+ */+ // getNumberFormats(): string[][] {+ // return this.getValues().map((row) =>+ // row.map((cell: Nullable<ICellData>) => cell?.fm?.f || '')+ // );+ // }++ /**+ * Returns the Rich Text value for the top left cell of the range, or null if the cell value is not text.+ */+ getRichTextValue(): Nullable<IDocumentData | ''> {+ return this.getRichTextValues()[0][0];+ }++ /**+ * Returns the Rich Text values for the cells in the range.+ */+ getRichTextValues(): Array<Array<Nullable<IDocumentData | ''>>> {+ return this.getValues().map((row) =>+ row.map((cell: Nullable<ICellData>) => cell?.p || '')+ );+ }++ /**+ * Returns the row position for this range.+ */+ getRowIndex(): number {+ return this._rangeData.startRow;+ }++ /**+ * Returns the sheet this range belongs to.+ */+ getSheet(): Worksheet {+ return this._worksheet;+ }++ /**+ * Returns the text direction for the top left cell of the range.+ */+ getTextDirection(): number {+ return this.getTextDirections()[0][0];+ }++ /**+ * Returns the text directions for the cells in the range.+ */+ getTextDirections(): number[][] {+ return this._getStyles('td') as number[][];+ }++ /**+ * Returns the text rotation settings for the top left cell of the range.+ */+ // getTextRotation(): number {+ getTextRotation() {+ return this.getTextRotations()[0][0];+ }++ /**+ * Returns the text rotation settings for the cells in the range.+ */+ // getTextRotations(): number[][] {+ getTextRotations() {+ return this._getStyles('tr');+ }++ /**+ * Returns the text style for the top left cell of the range.+ */+ getTextStyle(): Nullable<IStyleData> {+ return this.getTextStyles()[0][0];+ }++ /**+ * Returns the text styles for the cells in the range.+ */+ getTextStyles(): Array<Array<Nullable<IStyleData>>> {+ return this.getValues().map((row) =>+ row.map((cell: Nullable<ICellData>) => {+ const styles = this._context.getWorkBook().getStyles();+ return styles.getStyleByCell(cell);+ })+ );+ }++ /**+ * Returns the vertical alignment (top/middle/bottom) of the cell in the top-left corner of the range.+ */+ getVerticalAlignment(): VerticalAlign {+ return this.getVerticalAlignments()[0][0];+ }++ /**+ * Returns the vertical alignments of the cells in the range.+ */+ getVerticalAlignments(): VerticalAlign[][] {+ return this._getStyles('vt') as VerticalAlign[][];+ }++ /**+ * Returns the width of the range in columns.+ */+ getWidth(): number {+ const { _rangeData, _worksheet } = this;+ const { startColumn, endColumn } = _rangeData;+ let w = 0;+ for (let i = 0; i <= endColumn - startColumn; i++) {+ w += _worksheet.getColumnWidth(i);+ }+ return w;+ }++ /**+ * Returns whether the text in the cell wraps.+ */+ getWrap(): BooleanNumber {+ return this.getWraps()[0][0];+ }++ /**+ * Returns whether the text in the cells wrap.+ */+ getWraps(): BooleanNumber[][] {+ return this._getStyles('tb') as BooleanNumber[][];+ }++ /**+ * Returns the text wrapping strategies for the cells in the range.+ */+ getWrapStrategies(): WrapStrategy[][] {+ return this._getStyles('tb') as WrapStrategy[][];+ }++ /**+ * Returns the text wrapping strategy for the top left cell of the range.+ */+ getWrapStrategy(): WrapStrategy {+ return this.getWrapStrategies()[0][0];+ }++ /**+ * Returns true if the range is totally blank.+ */+ isBlank(): boolean {+ const data = this.getValues();+ return data.some((items) => items.some((item) => item?.m === ''));+ }++ // isChecked() {}+ // isEndColumnBounded() {}+ // isEndRowBounded() {}++ /**+ * Returns true if the cells in the current range overlap any merged cells.+ */+ isPartOfMerge(): boolean {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const data = this._worksheet+ .getMerges()+ .getByRowColumn(startRow, endRow, startColumn, endColumn);+ if (data) {+ return true;+ }++ return false;+ }++ /**+ * Sets the background color of all cells in the range in CSS notation (such as '#ffffff' or 'white').+ *+ * @param color Sets the background color of all cells in the range in CSS notation (such as '#ffffff' or 'white').+ * @returns This range, for chaining.+ */+ setBackground(color: string): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array++ const colorObj: IStyleData = {+ bg: {+ rgb: color,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ colorObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets a rectangular grid of background colors (must match dimensions of this range). The colors are in CSS notation (such as '#ffffff' or 'white').+ *+ * @param color A two-dimensional array of colors in CSS notation (such as '#ffffff' or 'white'); null values reset the color.+ * @returns This range, for chaining.+ */+ setBackgrounds(color: string[][]): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const matrix = new ObjectMatrix<IStyleData>();+ for (let r = 0; r < endRow - startRow + 1; r++) {+ for (let c = 0; c < endColumn - startColumn + 1; c++) {+ matrix.setValue(r, c, {+ bg: {+ rgb: color[r][c],+ },+ });+ }+ }+ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: matrix.getData(),+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets the background to the given color using RGB values (integers between 0 and 255 inclusive).+ *+ * @param red The red value in RGB notation.+ * @param green The green value in RGB notation.+ * @param blue The blue value in RGB notation.+ * @returns This range, for chaining.+ */+ setBackgroundRGB(red: number, green: number, blue: number): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const rgbString = `RGB(${red},${green},${blue})`;++ const colorObj: IStyleData = {+ bg: {+ rgb: rgbString,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ colorObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets a rectangular grid of font colors (must match dimensions of this range). The colors are in CSS notation (such as '#ffffff' or 'white').+ *+ * @param colors A two-dimensional array of colors in CSS notation (such as '#ffffff' or 'white'); null values reset the color.+ * @returns This range, for chaining.+ */+ setFontColors(colors: string[][]): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const matrix = new ObjectMatrix<IStyleData>();+ for (let r = 0; r < endRow - startRow + 1; r++) {+ for (let c = 0; c < endColumn - startColumn + 1; c++) {+ matrix.setValue(r, c, { cl: { rgb: colors[r][c] } });+ }+ }+ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: matrix.getData(),+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets a rectangular grid of font families (must match dimensions of this range). Examples of font families are "Arial" or "Helvetica".+ *+ * @param fontFamilies A two-dimensional array of font families; null values reset the font family.+ * @returns This range, for chaining.+ */+ setFontFamilies(fontFamilies: string[][]): Range {+ this._setStyles(fontFamilies, 'ff');+ return this;+ }++ /**+ * Sets the font line style of the given range+ *+ * @param fontLine The font line style; a null value resets the font line style+ * @returns This range, for chaining.+ */+ setUnderline(fontLine: Nullable<ITextDecoration>): Range {+ this._setStyle(fontLine, 'ul');+ return this;+ }++ /**+ * Sets the font line style of the given range+ *+ * @param fontLine The font line style; a null value resets the font line style+ * @returns This range, for chaining.+ */+ setOverline(fontLine: Nullable<ITextDecoration>): Range {+ this._setStyle(fontLine, 'ol');+ return this;+ }++ /**+ * Sets a rectangular grid of line styles (must match dimensions of this range).+ *+ * @param fontLine The font line style; a null value resets the font line style+ * @returns This range, for chaining.+ */+ setStrikeThrough(fontLine: Nullable<ITextDecoration>): Range {+ this._setStyle(fontLine, 'st');+ return this;+ }++ /**+ * Sets the font line style of the given range+ *+ * @param fontLines A two-dimensional array of font line styles ; null values reset the font line style.+ * @returns This range, for chaining.+ */+ setUnderlines(fontLines: Array<Array<Nullable<ITextDecoration>>>): Range {+ this._setStyles(fontLines, 'ul');+ return this;+ }++ /**+ * Sets the font line style of the given range+ *+ * @param fontLines A two-dimensional array of font line styles ; null values reset the font line style.+ * @returns This range, for chaining.+ */+ setOverlines(fontLines: Array<Array<Nullable<ITextDecoration>>>): Range {+ this._setStyles(fontLines, 'ol');+ return this;+ }++ /**+ * Sets the font line style of the given range+ *+ * @param fontLines A two-dimensional array of font line styles ; null values reset the font line style.+ * @returns This range, for chaining.+ */+ setStrikeThroughs(fontLines: Array<Array<Nullable<ITextDecoration>>>): Range {+ this._setStyles(fontLines, 'st');+ return this;+ }++ /**+ * Sets a rectangular grid of font sizes (must match dimensions of this range).+ *+ * @param sizes A two-dimensional array of sizes.+ * @returns This range, for chaining.+ */+ setFontSizes(sizes: number[][]): Range {+ this._setStyles(sizes, 'fs');+ return this;+ }++ /**+ * Set the font style for the given range ('italic' or 'normal').+ *+ * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.+ * @returns This range, for chaining.+ */+ setFontStyle(fontStyle: Nullable<FontItalic>): Range {+ this._setStyle(fontStyle, 'it');+ return this;+ }++ /**+ * Sets a rectangular grid of font styles (must match dimensions of this range).+ *+ * @param fontStyles A two-dimensional array of font styles, either 'italic' or 'normal'; null values reset the font style.+ * @returns This range, for chaining.+ */+ setFontStyles(fontStyles: Array<Array<Nullable<FontItalic>>>): Range {+ this._setStyles(fontStyles, 'it');+ return this;+ }++ /**+ * Set the font weight for the given range (normal/bold).+ *+ * @param fontWeight The font weight, either 'bold' or 'normal'; a null value resets the font weight.+ * @returns This range, for chaining.+ */+ setFontWeight(fontWeight: Nullable<FontWeight>): Range {+ this._setStyle(fontWeight, 'bl');+ return this;+ }++ /**+ * Sets a rectangular grid of font weights (must match dimensions of this range).+ *+ * @param fontWeights A two-dimensional array of font weights, either 'bold' or 'normal'; null values reset the font weight.+ * @returns This range, for chaining.+ */+ setFontWeights(fontWeights: Array<Array<Nullable<FontWeight>>>): Range {+ this._setStyles(fontWeights, 'bl');+ return this;+ }++ /**+ * Sets a rectangular grid of horizontal alignments.+ *+ * @param alignments A two-dimensional array of alignments, either 'left', 'center' or 'normal'; a null value resets the alignment.+ * @returns This range, for chaining.+ */+ setHorizontalAlignments(+ alignments: Array<Array<Nullable<HorizontalAlign>>>+ ): Range {+ this._setStyles(alignments, 'ht');+ return this;+ }++ /**+ * Sets the note to the given value.+ *+ * @param note The note value to set for the range; a null value removes the note.+ * @returns This range, for chaining.+ */+ // setNote(note: string): Range {+ // const { _rangeData, _context, _commandManager, _worksheet } = this;+ // const { startRow, startColumn, endRow, endColumn } = _rangeData;+ // const cellValue = new ObjectMatrix<string>();+ // for (let r = startRow; r <= endRow; r++) {+ // for (let c = startColumn; c <= endColumn; c++) {+ // cellValue.setValue(r, c, note);+ // }+ // }+ // const setValue: ISetRangeNoteActionData = {+ // sheetId: _worksheet.getSheetId(),+ // actionName: ACTION_NAMES.SET_RANGE_NOTE_ACTION,+ // cellNote: cellValue.getData(),+ // rangeData: this._rangeData,+ // };+ // const command = new Command(_context.getWorkBook(), setValue);+ // _commandManager.invoke(command);++ // return this;+ // }++ /**+ * Sets the note to the given value.+ *+ * @param notes A two-dimensional array of notes; null values remove the note.+ * @returns This range, for chaining.+ */+ // setNotes(notes: string[][]): Range {+ // const { _rangeData, _context, _commandManager, _worksheet } = this;++ // const { startRow, startColumn, endRow, endColumn } = _rangeData;++ // const cellValue = new ObjectMatrix<string>();+ // for (let r = 0; r <= endRow - startRow; r++) {+ // for (let c = 0; c <= endColumn - startColumn; c++) {+ // cellValue.setValue(r + startRow, c + startColumn, notes[r][c]);+ // }+ // }++ // const setValue: ISetRangeNoteActionData = {+ // sheetId: _worksheet.getSheetId(),+ // actionName: ACTION_NAMES.SET_RANGE_NOTE_ACTION,+ // cellNote: cellValue.getData(),+ // rangeData: this._rangeData,+ // };+ // const command = new Command(_context.getWorkBook(), setValue);+ // _commandManager.invoke(command);++ // return this;+ // }++ /**+ * Sets the number or date format to the given formatting string.+ *+ * @param numberFormat A number format string.+ * @returns This range, for chaining.+ */+ // setNumberFormat(numberFormat: string): Range {+ // const { _rangeData, _context, _commandManager, _worksheet } = this;++ // const { startRow, startColumn, endRow, endColumn } = _rangeData;++ // const cellValue = new ObjectMatrix<string>();+ // for (let r = 0; r <= endRow - startRow; r++) {+ // for (let c = 0; c <= endColumn - startColumn; c++) {+ // const fm = {+ // f: numberFormat,+ // t: FormatType.NUMBER,+ // };+ // cellValue.setValue(r + startRow, c + startColumn, JSON.stringify(fm));+ // }+ // }++ // const setValue: ISetRangeFormatActionData = {+ // sheetId: _worksheet.getSheetId(),+ // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,+ // cellFormat: cellValue.getData(),+ // rangeData: this._rangeData,+ // };+ // const command = new Command(_context.getWorkBook(), setValue);+ // _commandManager.invoke(command);++ // return this;+ // }++ /**+ * Sets a rectangular grid of number or date formats (must match dimensions of this range).+ *+ * @param numberFormats A two-dimensional array of number formats.+ * @returns This range, for chaining.+ */+ // setNumberFormats(numberFormats: string[][]): Range {+ // const { _rangeData, _context, _commandManager, _worksheet } = this;++ // const { startRow, startColumn, endRow, endColumn } = _rangeData;++ // const cellValue = new ObjectMatrix<string>();+ // for (let r = 0; r <= endRow - startRow; r++) {+ // for (let c = 0; c <= endColumn - startColumn; c++) {+ // const fm = {+ // f: numberFormats[r][c],+ // t: FormatType.NUMBER,+ // };+ // cellValue.setValue(r + startRow, c + startColumn, JSON.stringify(fm));+ // }+ // }++ // const setValue: ISetRangeFormatActionData = {+ // sheetId: _worksheet.getSheetId(),+ // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,+ // cellFormat: cellValue.getData(),+ // rangeData: this._rangeData,+ // };+ // const command = new Command(_context.getWorkBook(), setValue);+ // _commandManager.invoke(command);++ // return this;+ // }++ // setRichTextValue(value) {}+ // setRichTextValues(values) {}+ // setShowHyperlink(showHyperlink) {}++ /**+ * Sets a rectangular grid of text directions.+ *+ * @param directions The desired text directions; if a specified direction is null it is inferred before setting.+ * @returns This range, for chaining.+ */+ setTextDirections(directions: number[][]): Range {+ this._setStyles(directions, 'td');+ return this;+ }++ /**+ * Sets the text rotation settings for the cells in the range.+ *+ * @param degrees The desired angle between the standard orientation and the desired orientation. For left to right text, positive angles are in the counterclockwise direction.+ * @returns This range, for chaining.+ */+ setTextRotation(degrees: Nullable<number>): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const styleObj: IStyleData = {+ tr: {+ v: 0,+ a: Number(degrees),+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets a rectangular grid of text rotations.+ *+ * @param rotations The desired text rotation settings.+ * @returns This range, for chaining.+ */+ setTextRotations(rotations: number[][]): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const matrix = new ObjectMatrix<IStyleData>();+ for (let r = 0; r < endRow - startRow + 1; r++) {+ for (let c = 0; c < endColumn - startColumn + 1; c++) {+ matrix.setValue(r, c, {+ tr: {+ v: 0,+ a: rotations[r][c]!,+ },+ });+ }+ }+ const a = matrix.getData();+ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: matrix.getData(),+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets the text style for the cells in the range.+ *+ * @param style The desired text style.+ * @returns This range, for chaining.+ */+ setTextStyle(style: Nullable<IStyleData>): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const stylesObj = { ...style };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ stylesObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets a rectangular grid of text styles.+ *+ * @param styles The desired text styles.+ * @returns This range, for chaining.+ */+ setTextStyles(styles: Array<Array<Nullable<IStyleData>>>): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const matrix = new ObjectMatrix<IStyleData>();+ for (let r = 0; r < endRow - startRow + 1; r++) {+ for (let c = 0; c < endColumn - startColumn + 1; c++) {+ matrix.setValue(r, c, { ...styles[r][c] });+ }+ }+ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: matrix.getData(),+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets a rectangular grid of vertical alignments (must match dimensions of this range).+ *+ * @param alignments A two-dimensional array of alignments, either 'top', 'middle' or 'bottom'; a null value resets the alignment.+ * @returns This range, for chaining.+ */+ setVerticalAlignments(alignments: Array<Array<Nullable<VerticalAlign>>>): Range {+ this._setStyles(alignments, 'vt');+ return this;+ }++ /**+ * Sets whether or not to stack the text for the cells in the range.+ * @param isVertical Whether or not to stack the text.+ * @returns+ */+ setVerticalText(isVertical: BooleanNumber): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const styleObj = {+ tr: {+ v: isVertical,+ a: 90,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Set the cell wrap of the given range+ *+ * @param isWrapEnabled Whether to wrap text or not.+ * @returns This range, for chaining.+ */+ setWrap(isWrapEnabled: BooleanNumber): Range {+ this._setStyle(isWrapEnabled, 'tb');+ return this;+ }++ /**+ * Sets a rectangular grid of wrap strategies.+ *+ * @param strategies The desired wrapping strategies.+ * @returns This range, for chaining.+ */+ setWrapStrategies(strategies: Array<Array<Nullable<WrapStrategy>>>): Range {+ this._setStyles(strategies, 'tb');+ return this;+ }++ /**+ * Sets a rectangular grid of word wrap policies (must match dimensions of this range).+ *+ * @param isWrapEnabled A two-dimensional array of wrap variables that determine whether to wrap text in a cell or not.+ * @returns This range, for chaining.+ */+ setWraps(isWrapEnabled: BooleanNumber[][]): Range {+ this._setStyles(isWrapEnabled, 'tb');+ return this;+ }++ /**+ * Fills the destinationRange with data based on the data in this range. The new values are also determined by the specified series type. The destination range must contain this range and extend it in only one direction. For example, the following fills A1:A20 with a series of increasing numbers based on the current values in A1:A4:+ *+ * @param destination The range to be auto-filled with values. The destination range should contain this range and extend it in only one direction (upwards, downwards, left, or right).+ * @param series The type of autoFill series that should be used to calculate new values. The effect of this series differs based on the type and amount of source data.+ * @returns This range, for chaining.+ */+ // autoFill(destination: Range, series: AutoFillSeries): Range {+ // const { _worksheet, _context, _commandManager } = this;+ // const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ // const {+ // startRow: Dsr,+ // endRow: Der,+ // startColumn: Dsc,+ // endColumn: Dec,+ // } = destination._rangeData;+ // let direction = Direction.BOTTOM;+ // let csLen: number = 0;+ // let asLen: number = 0;++ // // 复制范围+ // const copy_str_r = startRow;+ // const copy_end_r = endRow;+ // const copy_str_c = startColumn;+ // const copy_end_c = endColumn;++ // // 应用范围+ // const apply_str_r = Dsr;+ // const apply_end_r = Der;+ // const apply_str_c = Dsc;+ // const apply_end_c = Dec;++ // const matrix = new ObjectMatrix<ICellData>();++ // if (apply_str_c === copy_str_c && apply_end_c === copy_end_c) {+ // if (apply_end_r > copy_end_r) {+ // direction = Direction.BOTTOM;+ // } else {+ // direction = Direction.TOP;+ // }+ // } else if (apply_end_c > copy_end_c) {+ // direction = Direction.RIGHT;+ // } else {+ // direction = Direction.LEFT;+ // }++ // if (direction === Direction.BOTTOM || direction === Direction.TOP) {+ // // 列+ // csLen = copy_end_r - copy_str_r + 1;+ // asLen = apply_end_r - apply_str_r + 1;++ // for (let i = 0; i <= endColumn - startColumn; i++) {+ // const sourceRange = this.getColumnMatrix(i).toArray();++ // const copydata = DropCell.getCopyData(+ // sourceRange,+ // copy_str_r,+ // copy_end_r,+ // copy_str_c,+ // copy_end_c,+ // direction+ // );+ // copydata.forEach((item) => {+ // const data = DropCell.getApplyData(+ // item,+ // csLen,+ // asLen,+ // series,+ // direction+ // );+ // data.forEach((dataItem, j) => {+ // matrix.setValue(j, i, dataItem);+ // });+ // });+ // }+ // } else if (direction === Direction.RIGHT || direction === Direction.LEFT) {+ // asLen = apply_end_c - apply_str_c;+ // csLen = copy_end_c - copy_str_c;+ // // 行+ // for (let i = 0; i <= endRow - startRow; i++) {+ // const sourceRange = this.getRowMatrix(i).toArray();++ // const copydata = DropCell.getCopyData(+ // sourceRange,+ // copy_str_r,+ // copy_end_r,+ // copy_str_c,+ // copy_end_c,+ // direction+ // );+ // copydata.forEach((item) => {+ // const data = DropCell.getApplyData(+ // item,+ // csLen,+ // asLen,+ // series,+ // direction+ // );+ // });+ // }+ // }++ // const setValue: ISetRangeDataActionData = {+ // sheetId: _worksheet.getSheetId(),+ // actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ // cellValue: matrix.getData(),+ // };+ // const command = new Command(+ // {+ // WorkBookUnit: _context.getWorkBook(),+ // },+ // setValue+ // );+ // _commandManager.invoke(command);+ // return this;+ // }++ // TODO+ // autoFillToNeighbor(series: AutoFillSeries) {}++ /**+ * Returns a copy of the range expanded in the four cardinal Directions to cover all adjacent cells with data in them.+ *+ * @returns This range, for chaining.+ */+ getDataRegion(): Range;+ /**+ * Returns a copy of the range expanded Direction.UP and Direction.DOWN if the specified dimension is Dimension.ROWS, or Direction.NEXT and Direction.PREVIOUS if the dimension is Dimension.COLUMNS.+ *+ * @returns This range, for chaining.+ */+ getDataRegion(dimension: Dimension): Range;+ getDataRegion(...argument: any): Range {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ let numRows: number;+ let numColumns: number;++ const data = this._worksheet.getCellMatrix();+ if (Tools.isNumber(argument[0])) {+ const dimension = argument[0];++ if (dimension === Dimension.COLUMNS) {+ let start: number = startRow;+ let end: number = startRow;+ const rowMax = this._worksheet.getRowCount();+ for (let i = 1; i < startRow; i++) {+ const element = data.getValue(startRow - i, startColumn);+ if (!element) {+ start = startRow - i + 1;+ break;+ }+ }+ const j = 0;+ while (j < rowMax - startRow) {+ const element = data.getValue(startRow + j, startColumn);+ if (!element) {+ end = startRow - j - 1;+ break;+ }+ }++ numColumns = start - end;+ numRows = 0;+ return this._worksheet.getRange(+ startRow,+ start,+ numRows,+ numColumns+ );+ }+ if (dimension === Dimension.ROWS) {+ let start: number = startRow;+ let end: number = startRow;+ const colMax = this._worksheet.getColumnCount();+ for (let i = 1; i < startRow; i++) {+ const element = data.getValue(startRow, startColumn - i);+ if (!element) {+ start = startRow - i + 1;+ break;+ }+ }+ const j = 0;+ while (j < colMax - startColumn) {+ const element = data.getValue(startRow, startColumn + j);+ if (!element) {+ end = startRow - j - 1;+ break;+ }+ }++ numColumns = 0;+ numRows = start - end;+ return this._worksheet.getRange(+ start,+ startColumn,+ numRows,+ numColumns+ );+ }+ } else {+ let rowStart: number = startRow;+ let rowEnd: number = startRow;+ const rowMax = this._worksheet.getRowCount();+ for (let i = 1; i < startRow; i++) {+ const element = data.getValue(startRow - i, startColumn);+ if (!element) {+ rowStart = startRow - i + 1;+ break;+ }+ }+ const rj = 0;+ while (rj < rowMax - startRow) {+ const element = data.getValue(startRow + rj, startColumn);+ if (!element) {+ rowEnd = startRow - rj - 1;+ break;+ }+ }++ let columnStart: number = startRow;+ let columnEnd: number = startRow;+ const colMax = this._worksheet.getColumnCount();+ for (let i = 1; i < startRow; i++) {+ const element = data.getValue(startRow, startColumn - i);+ if (!element) {+ columnStart = startRow - i + 1;+ break;+ }+ }+ const cj = 0;+ while (cj < colMax - startColumn) {+ const element = data.getValue(startRow, startColumn + cj);+ if (!element) {+ columnEnd = startRow - cj - 1;+ break;+ }+ }++ numColumns = columnStart - columnEnd;+ numColumns = rowStart - rowEnd;+ numRows = startRow;+ return this._worksheet.getRange(+ rowStart,+ columnStart,+ numRows,+ numColumns+ );+ }+ return this;+ }++ /**+ * Trims the whitespace (such as spaces, tabs, or new lines) in every cell in this range. Removes all whitespace from the start and end of each cell's text, and reduces any subsequence of remaining whitespace characters to a single space.+ *+ * @returns This range, for chaining.+ */+ trimWhitespace(): Range {+ const { _context, _worksheet, _commandManager } = this;+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const sheetMatrix = this._worksheet.getCellMatrix();+ const regx = /\s+/g;++ const cellValue = new ObjectMatrix<ICellV>();+ for (let r = 0; r <= endRow - startRow; r++) {+ for (let c = 0; c <= endColumn - startColumn; c++) {+ const value = sheetMatrix.getValue(r, c)!.m?.replace(regx, '');+ cellValue.setValue(r + startRow, c + startColumn, value || '');+ }+ }++ const setValue: ISetRangeFormattedValueActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,+ cellValue: cellValue.getData(),+ rangeData: this._rangeData,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);++ return this;+ }+ // uncheck++ /**+ * Sets the specified range as the active range, with the top left cell in the range as the current cell.+ *+ * @returns This range, for chaining.+ * @internal+ */+ activate(): Range {+ // const { _context, _commandManager } = this;+ // The user entered an invalid range+ if (this._rangeData?.startRow === -1) {+ console.error('Invalid range,default set startRow -1');+ return this;+ }++ this._worksheet.getSelection().setSelection({ selection: this });++ // This range, for chaining+ return this;+ }++ /**+ * Sets the specified cell as the current cell.+ *+ * If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.+ *+ * If the specified cell is not present in any existing range, then the existing selection is removed and the cell becomes the current cell and the active range.+ *+ * Note: The specified Range must consist of one cell, otherwise it throws an exception.+ *+ * @returns This range, for chaining.+ */+ activateAsCurrentCell(): Range {+ this._worksheet.getSelection().setCurrentCell(this);+ return this;+ }++ /**+ * Whether the current range and the incoming range have an intersection+ *+ * @param range the incoming range+ * @returns Intersect or not+ */+ isIntersection(range: Range): boolean {+ const currentStartRow = this._rangeData.startRow;+ const currentEndRow = this._rangeData.endRow;+ const currentStartColumn = this._rangeData.startColumn;+ const currentEndColumn = this._rangeData.endColumn;++ const incomingStartRow = range.getRangeData().startRow;+ const incomingEndRow = range.getRangeData().endRow;+ const incomingStartColumn = range.getRangeData().startColumn;+ const incomingEndColumn = range.getRangeData().endColumn;++ const zx = Math.abs(+ currentStartColumn ++ currentEndColumn -+ incomingStartColumn -+ incomingEndColumn+ );+ const x =+ Math.abs(currentStartColumn - currentEndColumn) ++ Math.abs(incomingStartColumn - incomingEndColumn);+ const zy = Math.abs(+ currentStartRow + currentEndRow - incomingStartRow - incomingEndRow+ );+ const y =+ Math.abs(currentStartRow - currentEndRow) ++ Math.abs(incomingStartRow - incomingEndRow);+ if (zx <= x && zy <= y) {+ return true;+ }+ return false;+ }++ /**+ * Sets the font color in CSS notation (such as '#ffffff' or 'white').+ *+ * @param color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.+ * @returns+ */+ setFontColor(color: string): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array++ const colorObj: IStyleData = {+ cl: {+ rgb: color,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ colorObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Copies the data from a range of cells to another range of cells. Both the values and formatting are copied.+ *+ * @param destination A destination range to copy to; only the top-left cell position is relevant.+ */+ copyTo(destination: Range): void;++ /**+ * Copies the data from a range of cells to another range of cells..+ *+ * @param destination A destination range to copy to; only the top-left cell position is relevant.+ * @param copyPasteType A type that specifies how the range contents are pasted to the destination.+ * @param transposed Whether the range should be pasted in its transposed orientation.+ */+ copyTo(+ destination: Range,+ copyPasteType: CopyPasteType,+ transposed: boolean+ ): void;++ /**+ * Copies the data from a range of cells to another range of cells. By default both the values and formatting are copied, but this can be overridden using advanced arguments.+ *+ * @param destination A destination range to copy to; only the top-left cell position is relevant.+ * @param options A JavaScript object that specifies advanced parameters, as listed below.+ */+ copyTo(destination: Range, options: IOptionData): void;+ copyTo(...argument: any): void {+ const { _context, _worksheet, _commandManager } = this;+ const destination = argument[0];+ const [value, range] = this._handleCopyRange(this, destination);+ const { startRow, startColumn, endRow, endColumn } = range;++ if (Tuples.checkup(argument, Range, Tuples.BOOLEAN_TYPE)) {+ const copyPasteType = argument[1];+ const transposed = argument[2];++ if (copyPasteType === CopyPasteType.PASTE_NORMAL) {+ const cellValue = new ObjectMatrix<ICellData>();+ value.forEach((row, r) =>+ row.forEach((cell, c) => {+ cell = cell as ICellData;+ cellValue.setValue(+ r + startRow,+ c + startColumn,+ cell || {}+ );+ })+ );++ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: cellValue.getData(),+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ } else if (copyPasteType === CopyPasteType.PASTE_FORMAT) {+ const styles = _context.getWorkBook().getStyles();++ const stylesMatrix = new ObjectMatrix<IStyleData>();+ const stylesArray = value.map((row, r) =>+ row.forEach((cell, c) => {+ cell = cell as ICellData;+ stylesMatrix.setValue(+ r,+ c,+ styles.getStyleByCell(cell) || {}+ );+ })+ );++ // Organize the style format of the current range into the format of the destination range+ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix.getData(),+ rangeData: range,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ } else if (copyPasteType === CopyPasteType.PASTE_VALUES) {+ const cellValue = new ObjectMatrix<ICellV>();+ value.forEach((row, r) =>+ row.forEach((cell, c) => {+ cell = cell as ICellData;+ cellValue.setValue(+ r + startRow,+ c + startColumn,+ cell?.v || ''+ );+ })+ );++ const setValue: ISetRangeFormattedValueActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,+ cellValue: cellValue.getData(),+ rangeData: range,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ } else if (copyPasteType === CopyPasteType.PASTE_COLUMN_WIDTHS) {+ const rangeStartColumn = this._rangeData.startColumn;+ for (let i = 0; i < endColumn - rangeStartColumn; i++) {+ const width = _worksheet.getColumnWidth(rangeStartColumn + i);+ _worksheet.setColumnWidth(rangeStartColumn + i, width);+ }+ }+ } else if (Tuples.checkup(argument, Range, Tuples.OBJECT_TYPE)) {+ const options = argument[1];++ const cellValue = new ObjectMatrix<ICellData>();+ value.forEach((row, r) =>+ row.forEach((cell, c) => {+ cell = cell as ICellData;+ cellValue.setValue(r + startRow, c + startColumn, cell || {});+ })+ );++ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: cellValue.getData(),+ options,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ } else if (Tuples.checkup(argument, Range)) {+ const cellValue = new ObjectMatrix<ICellData>();+ value.forEach((row, r) =>+ row.forEach((cell, c) => {+ cell = cell as ICellData;+ cellValue.setValue(r + startRow, c + startColumn, cell || {});+ })+ );++ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: cellValue.getData(),+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ }+ }++ /**+ * Copy the formatting of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly. Note that this method copies the formatting only.+ *+ * @param sheetId The unique ID of the sheet within the spreadsheet, irrespective of position.+ * @param startRow The start row of the target range.+ * @param endRow The end row of the target range.+ * @param startColumn The first column of the target range.+ * @param endColumn The end column of the target range.+ */+ copyFormatToRange(+ sheetId: string,+ startRow: number,+ endRow: number,+ startColumn: number,+ endColumn: number+ ): void;+ /**+ * Copy the formatting of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly. Note that this method copies the formatting only.+ *+ * @param sheet The target sheet.+ * @param startRow The start row of the target range.+ * @param endRow The end row of the target range.+ * @param startColumn The first column of the target range.+ * @param endColumn The end column of the target range.+ */+ copyFormatToRange(+ sheet: Worksheet,+ startRow: number,+ endRow: number,+ startColumn: number,+ endColumn: number+ ): void;+ copyFormatToRange(...argument: any): void {+ const { _context, _commandManager } = this;++ const startRow = argument[1];+ const endRow = argument[2];+ const startColumn = argument[3];+ const endColumn = argument[4];++ const sheetId = Tools.isAssignableFrom(argument[0], Worksheet)+ ? argument[0].getSheetId()+ : argument[0];++ const [value, range] = this._handleCopyRange(this, {+ startRow,+ endRow,+ startColumn,+ endColumn,+ });++ const styles = _context.getWorkBook().getStyles();++ const stylesMatrix = new ObjectMatrix<IStyleData>();+ value.map((row, r) =>+ row.map((cell, c) => {+ cell = cell as ICellData;+ stylesMatrix.setValue(r, c, styles.getStyleByCell(cell) || {});+ return styles.getStyleByCell(cell) || {};+ })+ );++ // Organize the style format of the current range into the format of the destination range+ const setStyle: ISetRangeStyleActionData = {+ sheetId,+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix.getData(),+ rangeData: range,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ }++ /**+ * Copy the content of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly.For a detailed description of the gridId parameter, see getGridId().+ * @param sheetId The unique ID of the sheet within the spreadsheet, irrespective of position.+ * @param startRow The start row of the target range.+ * @param endRow The end row of the target range.+ * @param startColumn The first column of the target range.+ * @param endColumn The end column of the target range.+ * @returns+ */+ copyValuesToRange(+ sheetId: string,+ startRow: number,+ endRow: number,+ startColumn: number,+ endColumn: number+ ): void;+ /**+ * Copy the content of the range to the given location. If the destination is larger or smaller than the source range then the source is repeated or truncated accordingly.+ * @param sheet The target sheet.+ * @param startRow The start row of the target range.+ * @param endRow The end row of the target range.+ * @param startColumn The first column of the target range.+ * @param endColumn The end column of the target range.+ * @returns+ */+ copyValuesToRange(+ sheet: Worksheet,+ startRow: number,+ endRow: number,+ startColumn: number,+ endColumn: number+ ): void;+ copyValuesToRange(...argument: any): void {+ const { _context, _commandManager } = this;++ const startRow = argument[1];+ const endRow = argument[2];+ const startColumn = argument[3];+ const endColumn = argument[4];++ const sheetId = Tools.isAssignableFrom(argument[0], Worksheet)+ ? argument[0].getSheetId()+ : argument[0];++ const [value, range] = this._handleCopyRange(this, {+ startRow,+ endRow,+ startColumn,+ endColumn,+ });++ const cellValue = new ObjectMatrix<ICellV>();+ value.forEach((row, r) =>+ row.forEach((cell, c) => {+ cell = cell as ICellData;+ cellValue.setValue(+ r + range.startRow,+ c + range.startColumn,+ cell?.v || ''+ );+ })+ );++ const setValue: ISetRangeFormattedValueActionData = {+ sheetId,+ actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,+ cellValue: cellValue.getData(),+ rangeData: range,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ }++ /**+ * Cut and paste (both format and values) from this range to the target range.+ * @param target A target range to copy this range to; only the top-left cell position is relevant.+ * @returns+ */+ moveTo(target: Range): void {+ const { _context, _worksheet, _commandManager, _rangeData } = this;++ // clear current range+ const options = {+ formatOnly: true,+ contentsOnly: true,+ commentsOnly: true,+ validationsOnly: true,+ skipFilteredRows: true,+ };+ const clearValue: IClearRangeActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.CLEAR_RANGE_ACTION,+ options,+ rangeData: _rangeData,+ };++ // get values from this range+ const currentMatrix = this.getMatrix();+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const { startRow: targetStartRow, startColumn: targetStartColumn } =+ target.getRangeData();++ const targetMatrix = new ObjectMatrix<ICellData>();++ for (let r = startRow; r <= endRow; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ targetMatrix.setValue(+ targetStartRow + (r - startRow),+ targetStartColumn + (c - startColumn),+ currentMatrix.getValue(r, c) || {}+ );+ }+ }++ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: targetMatrix.getData(),+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ clearValue,+ setValue+ );+ _commandManager.invoke(command);+ }++ /**+ * Returns a new range that is offset from this range by the given number of rows and columns (which can be negative). The new range is the same size as the original range.+ * @param rowOffset The number of rows down from the range's top-left cell; negative values represent rows up from the range's top-left cell.+ * @param columnOffset The number of columns right from the range's top-left cell; negative values represent columns left from the range's top-left cell.+ * @returns Range — This range, for chaining.+ */+ offset(rowOffset: number, columnOffset: number): Range;++ /**+ * Returns a new range that is relative to the current range, whose upper left point is offset from the current range by the given rows and columns, and with the given height in cells.+ * @param rowOffset The number of rows down from the range's top-left cell; negative values represent rows up from the range's top-left cell.+ * @param columnOffset The number of columns right from the range's top-left cell; negative values represent columns left from the range's top-left cell.+ * @param numRows The height in rows of the new range.+ * @returns Range — This range, for chaining.+ */+ offset(rowOffset: number, columnOffset: number, numRows: number): Range;++ /**+ * Returns a new range that is relative to the current range, whose upper left point is offset from the current range by the given rows and columns, and with the given height and width in cells.+ * @param rowOffset The number of rows down from the range's top-left cell; negative values represent rows up from the range's top-left cell.+ * @param columnOffset The number of columns right from the range's top-left cell; negative values represent columns left from the range's top-left cell.+ * @param numRows The height in rows of the new range.+ * @param numColumns The width in columns of the new range.+ * @returns Range — This range, for chaining.+ */+ offset(+ rowOffset: number,+ columnOffset: number,+ numRows: number,+ numColumns: number+ ): Range;+ offset(...argument: any): Range {+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const rowOffset = argument[0];+ const columnOffset = argument[1];+ const numRows = argument[2];+ const numColumns = argument[3];++ const offset = {+ startRow: startRow + rowOffset,+ endRow: endRow + rowOffset,+ startColumn: startColumn + columnOffset,+ endColumn: endColumn + columnOffset,+ };++ if (Tools.isNumber(numRows)) {+ offset.endRow = offset.startRow + numRows - 1;+ }++ if (Tools.isNumber(numColumns)) {+ offset.endColumn = offset.endColumn + numColumns - 1;+ }++ return new Range(this._worksheet, offset);+ }++ /**+ * Sets the border property with color and/or style. Valid values are true (on), false (off) and null (no change). For color, use Color in CSS notation (such as '#ffffff' or 'white').+ *+ * @param top true for border, false for none, null for no change.+ * @param left true for border, false for none, null for no change.+ * @param bottom true for border, false for none, null for no change.+ * @param right true for border, false for none, null for no change.+ * @param vertical true for internal vertical borders, false for none, null for no change.+ * @param horizontal true for internal horizontal borders, false for none, null for no change.+ * @param color A color in CSS notation (such as '#ffffff' or 'white'), null for default color (black).+ * @param style A style for the borders, null for default style (solid).+ * @returns+ */+ setBorder(+ top: Nullable<boolean>,+ left: Nullable<boolean>,+ bottom: Nullable<boolean>,+ right: Nullable<boolean>,+ vertical: Nullable<boolean>,+ horizontal: Nullable<boolean>+ ): Range;+ setBorder(+ top: Nullable<boolean>,+ left: Nullable<boolean>,+ bottom: Nullable<boolean>,+ right: Nullable<boolean>,+ vertical: Nullable<boolean>,+ horizontal: Nullable<boolean>,+ color: string,+ style: BorderStyleTypes+ ): Range;+ setBorder(...argument: any): Range {+ const top = argument[0];+ const left = argument[1];+ const bottom = argument[2];+ const right = argument[3];++ const vertical = argument[4];+ const horizontal = argument[5];++ const color = argument[6] ? argument[6] : 'black';+ const style = argument[7] ? argument[7] : BorderStyleTypes.DASH_DOT;++ const { _context, _worksheet, _commandManager } = this;+ const _workbook = _context.getWorkBook();++ const rangeData = this._rangeData;+ const _sheetId = _worksheet.getSheetId();++ // Cells in the surrounding range may need to clear the border+ const topRangeOut = {+ startRow: rangeData.startRow - 1,+ startColumn: rangeData.startColumn,+ endRow: rangeData.startRow - 1,+ endColumn: rangeData.endColumn,+ };++ const leftRangeOut = {+ startRow: rangeData.startRow,+ startColumn: rangeData.startColumn - 1,+ endRow: rangeData.endRow,+ endColumn: rangeData.startColumn - 1,+ };++ const bottomRangeOut = {+ startRow: rangeData.endRow + 1,+ startColumn: rangeData.startColumn,+ endRow: rangeData.endRow + 1,+ endColumn: rangeData.endColumn,+ };++ const rightRangeOut = {+ startRow: rangeData.startRow,+ startColumn: rangeData.endColumn + 1,+ endRow: rangeData.endRow,+ endColumn: rangeData.endColumn + 1,+ };++ // Cells in the upper, lower, left and right ranges+ const topRange = {+ startRow: rangeData.startRow,+ startColumn: rangeData.startColumn,+ endRow: rangeData.startRow,+ endColumn: rangeData.endColumn,+ };++ const leftRange = {+ startRow: rangeData.startRow,+ startColumn: rangeData.startColumn,+ endRow: rangeData.endRow,+ endColumn: rangeData.startColumn,+ };++ const bottomRange = {+ startRow: rangeData.endRow,+ startColumn: rangeData.startColumn,+ endRow: rangeData.endRow,+ endColumn: rangeData.endColumn,+ };++ const rightRange = {+ startRow: rangeData.startRow,+ startColumn: rangeData.endColumn,+ endRow: rangeData.endRow,+ endColumn: rangeData.endColumn,+ };++ const tr = new Range(_worksheet, topRangeOut);+ const lr = new Range(_worksheet, leftRangeOut);+ const br = new Range(_worksheet, bottomRangeOut);+ const rr = new Range(_worksheet, rightRangeOut);+ const t = new Range(_worksheet, topRange);+ const l = new Range(_worksheet, leftRange);+ const b = new Range(_worksheet, bottomRange);+ const r = new Range(_worksheet, rightRange);++ const mtr = new ObjectMatrix<IStyleData>();+ const mlr = new ObjectMatrix<IStyleData>();+ const mbr = new ObjectMatrix<IStyleData>();+ const mrr = new ObjectMatrix<IStyleData>();+ const mcr = new ObjectMatrix<IStyleData>();++ const actions: ISheetActionData[] = [];++ const border: IBorderStyleData = {+ s: style,+ cl: {+ rgb: color,+ },+ };++ if (top === true || top === false) {+ // Probably to the border, there are no surrounding cells+ if (tr.isValid()) {+ // Clear the bottom border of the top range+ tr.forEach((row, column) => {+ mtr.setValue(row, column, { bd: { b: null } });+ });++ const setBottomData: ISetRangeStyleActionData = {+ sheetId: _sheetId,+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: mtr.getArrayData(),+ rangeData: topRangeOut,+ };+ actions.push(setBottomData);+ }++ // first row+ t.forEach((row, column) => {+ // update+ if (top === true) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { t: Tools.deepClone(border) },+ });+ mcr.setValue(row, column, style);+ }+ // delete+ else if (top === false) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { t: null },+ });+ mcr.setValue(row, column, style);+ }+ });+ }+ if (bottom === true || bottom === false) {+ // Probably to the border, there are no surrounding cells+ if (br.isValid()) {+ // Clear the top border of the lower range+ br.forEach((row, column) => {+ mbr.setValue(row, column, { bd: { t: null } });+ });++ const setTopData: ISetRangeStyleActionData = {+ sheetId: _sheetId,+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: mbr.getArrayData(),+ rangeData: bottomRangeOut,+ };+ actions.push(setTopData);+ }++ // the last row+ b.forEach((row, column) => {+ // update+ if (bottom === true) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { b: Tools.deepClone(border) },+ });+ mcr.setValue(row, column, style);+ }+ // delete+ else if (bottom === false) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { b: null },+ });+ mcr.setValue(row, column, style);+ }+ });+ }+ if (left === true || left === false) {+ // Probably to the border, there are no surrounding cells+ if (lr.isValid()) {+ // Clear the right border of the left range+ lr.forEach((row, column) => {+ mlr.setValue(row, column, { bd: { r: null } });+ });++ const setRightData: ISetRangeStyleActionData = {+ sheetId: _sheetId,+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: mlr.getArrayData(),+ rangeData: leftRangeOut,+ };+ actions.push(setRightData);+ }++ // first column+ l.forEach((row, column) => {+ // update+ if (left === true) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { l: Tools.deepClone(border) },+ });+ mcr.setValue(row, column, style);+ }+ // delete+ else if (left === false) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { l: null },+ });+ mcr.setValue(row, column, style);+ }+ });+ }+ if (right === true || right === false) {+ // Probably to the border, there are no surrounding cells+ if (rr.isValid()) {+ // Clear the left border of the right range+ rr.forEach((row, column) => {+ mrr.setValue(row, column, { bd: { l: null } });+ });++ const setLeftData: ISetRangeStyleActionData = {+ sheetId: _sheetId,+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: mrr.getArrayData(),+ rangeData: rightRangeOut,+ };+ actions.push(setLeftData);+ }++ // last column+ r.forEach((row, column) => {+ // update+ if (right === true) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { r: Tools.deepClone(border) },+ });+ mcr.setValue(row, column, style);+ }+ // delete+ else if (right === false) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { r: null },+ });+ mcr.setValue(row, column, style);+ }+ });+ }++ // inner vertical border+ if (vertical === true || vertical === false) {+ // current range+ this.forEach((row, column) => {+ // Set the right border except the last column+ if (column !== rangeData.endColumn) {+ // update+ if (vertical === true) {+ const style = Tools.deepMerge(+ mcr.getValue(row, column) || {},+ {+ bd: { r: Tools.deepClone(border) },+ }+ );+ mcr.setValue(row, column, style);+ }+ // delete+ else if (vertical === false) {+ const style = Tools.deepMerge(+ mcr.getValue(row, column) || {},+ {+ bd: { r: null },+ }+ );+ mcr.setValue(row, column, style);+ }+ }++ // Except for the first column, clear the left border+ if (column !== rangeData.startColumn) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { l: null },+ });+ mcr.setValue(row, column, style);+ }+ });+ }+ // inner horizontal border+ if (horizontal === true || horizontal === false) {+ // current range+ this.forEach((row, column) => {+ // Except for the last row, set the bottom border+ if (row !== rangeData.endRow) {+ // update+ if (horizontal === true) {+ const style = Tools.deepMerge(+ mcr.getValue(row, column) || {},+ {+ bd: { b: Tools.deepClone(border) },+ }+ );+ mcr.setValue(row, column, style);+ }+ // delete+ else if (horizontal === false) {+ const style = Tools.deepMerge(+ mcr.getValue(row, column) || {},+ {+ bd: { b: null },+ }+ );+ mcr.setValue(row, column, style);+ }+ }++ // Except for the first row, clear the top border+ if (row !== rangeData.startRow) {+ const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {+ bd: { t: null },+ });+ mcr.setValue(row, column, style);+ }+ });+ }++ const setCCData: ISetRangeStyleActionData = {+ sheetId: _sheetId,+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: mcr.getArrayData(),+ rangeData: mcr.getDataRange(),+ };+ actions.push(setCCData);++ const commandCC = new Command(+ {+ WorkBookUnit: _workbook,+ },+ ...actions+ );+ _commandManager.invoke(commandCC);++ return this;+ }++ /**+ * Set Border by tool bar+ * @param type border type+ * @param color color+ * @param style size+ */+ setBorderByType(type: BorderType, color: string, style: BorderStyleTypes) {+ let top = null;+ let left = null;+ let bottom = null;+ let right = null;+ let vertical = null;+ let horizontal = null;++ switch (type) {+ case BorderType.TOP:+ top = true;+ break;+ case BorderType.BOTTOM:+ bottom = true;+ break;+ case BorderType.LEFT:+ left = true;+ break;+ case BorderType.RIGHT:+ right = true;+ break;+ case BorderType.NONE:+ top = false;+ left = false;+ bottom = false;+ right = false;+ vertical = false;+ horizontal = false;+ break;+ case BorderType.ALL:+ top = true;+ left = true;+ bottom = true;+ right = true;+ vertical = true;+ horizontal = true;+ break;+ case BorderType.OUTSIDE:+ top = true;+ left = true;+ bottom = true;+ right = true;+ break;+ case BorderType.INSIDE:+ vertical = true;+ horizontal = true;+ break;+ case BorderType.HORIZONTAL:+ horizontal = true;+ break;+ case BorderType.VERTICAL:+ vertical = true;+ break;++ default:+ break;+ }++ this.setBorder(top, left, bottom, right, vertical, horizontal, color, style);+ }++ /**+ * Sets the font family, such as "Arial" or "Helvetica".+ *+ * @param fontFamily The font family to set; a null value resets the font family.+ * @returns+ */+ setFontFamily(fontFamily: Nullable<string>): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const fontFamilyObj: IStyleData = { ff: fontFamily };+ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ fontFamilyObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets the font size, with the size being the point size to use.+ *+ * @param size A font size in point size.+ * @returns+ */+ setFontSize(size: number): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const fontSizeObj = { fs: size };+ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ fontSizeObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Set the horizontal (left to right) alignment for the given range (left/center/right).+ *+ * @param alignment The alignment, either 'left', 'center' or 'normal'; a null value resets the alignment.+ * @returns+ */+ setHorizontalAlignment(alignment: Nullable<HorizontalAlign>): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const horizontalAlignmentObj = { ht: alignment };+ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ horizontalAlignmentObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).+ *+ * @param alignment The alignment, either 'top', 'middle' or 'bottom'; a null value resets the alignment.+ * @returns+ */+ setVerticalAlignment(alignment: Nullable<VerticalAlign>): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const verticalAlignmentObj = { vt: alignment };+ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ verticalAlignmentObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).+ *+ * @param direction The desired text direction; if null the direction is inferred before setting.+ * @returns+ */+ setTextDirection(direction: Nullable<TextDirection>): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const textDirectionObj: IStyleData = { td: direction };+ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ textDirectionObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets the text wrapping strategy for the cells in the range.+ *+ * @param strategy The desired wrapping strategy.+ * @returns+ */+ setWrapStrategy(strategy: WrapStrategy): Range {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const wrapStrategyObj = { tb: strategy };+ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ wrapStrategyObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets the value of the range. The value can be numeric, string, boolean or date. If it begins with '=' it is interpreted as a formula.+ * @param value The value for the range.+ * @returns This range, for chaining.+ */+ setValue(value: ICellV): Range {+ const { _rangeData, _context, _commandManager, _worksheet } = this;+ const { startRow, startColumn, endRow, endColumn } = _rangeData;+ const cellValue = new ObjectMatrix<ICellV>();+ for (let r = startRow; r <= endRow; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ cellValue.setValue(r, c, value);+ }+ }+ const setValue: ISetRangeFormattedValueActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,+ cellValue: cellValue.getData(),+ rangeData: this._rangeData,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * Sets a rectangular grid of values (must match dimensions of this range).+ * @param values A two-dimensional array of values.+ * @returns Range — This range, for chaining.+ */+ setValues(values: ICellV[][]): Range;+ setValues(values: ObjectMatrix<ICellV>): Range;+ setValues(...argument: any): Range {+ const { _rangeData, _context, _commandManager, _worksheet } = this;+ const values = argument[0];++ if (Tuples.checkup(argument, Array)) {+ const { startRow, startColumn, endRow, endColumn } = _rangeData;++ const cellValue = new ObjectMatrix<ICellV>();+ for (let r = 0; r <= endRow - startRow; r++) {+ for (let c = 0; c <= endColumn - startColumn; c++) {+ cellValue.setValue(r + startRow, c + startColumn, values[r][c]);+ }+ }++ const setValue: ISetRangeFormattedValueActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,+ cellValue: cellValue.getData(),+ rangeData: this._rangeData,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ } else if (Tuples.checkup(argument, ObjectMatrix)) {+ const setValue: ISetRangeFormattedValueActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,+ cellValue: values,+ rangeData: this._rangeData,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ }++ return this;+ }++ /**+ * Sets cell data object for current range+ * @param value Cell data object+ * @returns+ */+ setRangeData(value: ICellData): Range {+ const { _rangeData, _context, _commandManager, _worksheet } = this;+ const { startRow, startColumn } = _rangeData;+ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: {+ [startRow]: {+ [startColumn]: value,+ },+ },+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * Sets a rectangular grid of cell obejct data (must match dimensions of this range).+ * @param values A two-dimensional array of cell object data.+ * @returns Range — This range, for chaining.+ */+ setRangeDatas(values: ICellData[][]): Range;+ setRangeDatas(values: ObjectMatrixPrimitiveType<ICellData>): Range;+ setRangeDatas(...argument: any): Range {+ const { _rangeData, _context, _commandManager, _worksheet } = this;+ const values = argument[0];++ if (Tuples.checkup(argument, Array)) {+ const { startRow, startColumn, endRow, endColumn } = _rangeData;++ const cellValue = new ObjectMatrix<ICellData>();+ for (let r = 0; r <= endRow - startRow; r++) {+ for (let c = 0; c <= endColumn - startColumn; c++) {+ cellValue.setValue(r + startRow, c + startColumn, values[r][c]);+ }+ }++ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: cellValue.getData(),+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ } else if (Tuples.checkup(argument, Tuples.OBJECT_TYPE)) {+ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: values,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ }++ return this;+ }++ /**+ * Clears the range of contents, formats, and data validation rules.+ * @returns This range, for chaining.+ */+ clear(): Range;+ /**+ * Clears the range of contents and/or format, as specified with the given advanced options. By default all data is cleared.+ * @param options A JavaScript object that specifies advanced parameters, as listed below.+ * @returns This range, for chaining.+ */+ clear(options: IOptionData): Range;+ clear(...argument: any): Range {+ const { _context, _worksheet, _commandManager, _rangeData } = this;++ // default options+ let options = {+ formatOnly: true,+ contentsOnly: true,+ };+ if (Tuples.checkup(argument, Tuples.OBJECT_TYPE)) {+ options = argument[0];+ }++ const setValue: IClearRangeActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.CLEAR_RANGE_ACTION,+ options,+ rangeData: _rangeData,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * Clears formatting for this range.+ *+ * This clears text formatting for the cell or cells in the range, but does not reset any number formatting rules.+ *+ * @returns Range This range, for chaining.+ */+ clearFormat(): Range {+ return this.clear({ formatOnly: true });+ }++ /**+ * Clears the content of the range, leaving the formatting intact.+ *+ * @returns Range This range, for chaining.+ */+ clearContent(): Range {+ return this.clear({ contentsOnly: true });+ }++ /**+ * Deletes this range of cells. Existing data in the sheet along the provided dimension is shifted towards the deleted range.+ *+ * solution: Clear the range to be deleted, and then set the new value of the cell content at the bottom using setValue+ * @param {Dimension} shiftDimension The dimension along which to shift existing data.+ * @returns void+ */+ deleteCells(shiftDimension: Dimension): void {+ const { _rangeData, _context, _commandManager, _worksheet } = this;++ const setValue: IDeleteRangeActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.DELETE_RANGE_ACTION,+ shiftDimension,+ rangeData: _rangeData,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ }++ /**+ * Inserts empty cells into this range. The new cells retain any formatting present in the cells previously occupying this range. Existing data in the sheet along the provided dimension is shifted away from the inserted range.+ * @param {Dimension} shiftDimension The dimension along which to shift existing data.+ * @returns Range This range, for chaining.+ */+ insertCells(shiftDimension: Dimension): Range;+ insertCells(shiftDimension: Dimension, destination: Range): Range;+ insertCells(...argument: any): Range {+ const shiftDimension = argument[0];+ const destination: Range = argument[1];+ const { _rangeData, _context, _commandManager, _worksheet } = this;+ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ let rangeData = this._rangeData;++ // TODO 1. 补充另一个方向+ // 2. 重载,传入数据,范围根据数据范围变化++ // build blank values+ let cellValue = new ObjectMatrix<ICellData>();+ if (destination) {+ cellValue = destination.getMatrixObject();++ const destinationRangeData = destination.getRangeData();++ rangeData = {+ startRow,+ endRow:+ startRow ++ destinationRangeData.endRow -+ destinationRangeData.startRow,+ startColumn,+ endColumn:+ startRow ++ destinationRangeData.endColumn -+ destinationRangeData.startColumn,+ };+ } else {+ for (let r = startRow; r <= endRow; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ cellValue.setValue(r, c, { m: '', v: '' });+ }+ }+ }++ const insertValue: IInsertRangeActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.INSERT_RANGE_ACTION,+ shiftDimension,+ rangeData,+ cellValue: cellValue.getData(),+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ insertValue+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Merges the cells in the range together into a single block.+ *+ * @returns Range — This range, for chaining.+ */+ merge(): Range {+ const { _worksheet } = this;+ const merges = _worksheet.getMerges();+ merges.add(this._rangeData);+ return this;+ }++ /**+ * Merge the cells in the range across the columns of the range.+ *+ * @returns Range — This range, for chaining.+ */+ mergeAcross(): Range {+ const { _worksheet } = this;+ const _commandManager = _worksheet.getCommandManager();+ const _context = _worksheet.getContext();+ const _sheetId = _worksheet.getSheetId();++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const rectangles = [];++ for (let r = startRow; r <= endRow; r++) {+ const data = {+ startRow: r,+ endRow: r,+ startColumn,+ endColumn,+ };+ rectangles.push(data);+ }+ const dataRowInsert: IAddMergeActionData = {+ actionName: ACTION_NAMES.ADD_MERGE_ACTION,+ sheetId: _sheetId,+ rectangles,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ dataRowInsert+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * Merges the cells in the range together.+ *+ * @returns Range — This range, for chaining.+ */+ mergeVertically(): Range {+ const { _worksheet } = this;+ const _commandManager = _worksheet.getCommandManager();+ const _context = _worksheet.getContext();+ const _sheetId = _worksheet.getSheetId();++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;+ const rectangles = [];++ for (let c = startColumn; c <= endColumn; c++) {+ const data = {+ startRow,+ endRow,+ startColumn: c,+ endColumn: c,+ };+ rectangles.push(data);+ }+ const dataRowInsert: IAddMergeActionData = {+ actionName: ACTION_NAMES.ADD_MERGE_ACTION,+ sheetId: _sheetId,+ rectangles,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ dataRowInsert+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * Break any multi-column cells in the range into individual cells again.++ Calling this function on a range is equivalent to selecting a range and clicking Format -> Merge -> Unmerge.++ @returns Range — This range, for chaining.+ */+ breakApart(): Range {+ // 您必须选中某个合并范围内的所有单元格才能执行合并或撤消合并。+ const { _worksheet } = this;+ const _commandManager = _worksheet.getCommandManager();+ const _context = _worksheet.getContext();+ const _sheetId = _worksheet.getSheetId();++ const rectangles = this._worksheet+ .getMerges()+ .getMergedRanges(this._rangeData);++ const dataRowInsert: IRemoveMergeActionData = {+ actionName: ACTION_NAMES.REMOVE_MERGE_ACTION,+ sheetId: _sheetId,+ rectangles,+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ dataRowInsert+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * Removes rows within this range that contain values that are duplicates of values in any previous row. Rows with identical values but different letter cases, formatting, or formulas are considered to be duplicates. This method also removes duplicates rows hidden from view (for example, due to a filter). Content outside of this range isn't removed.+ *+ * @returns Range The resulting range after removing duplicates. The size of the range is reduced by a row for every row removed.+ */+ removeDuplicates(): Range;++ /**+ * Removes rows within this range that contain values in the specified columns that are duplicates of values any previous row. Rows with identical values but different letter cases, formatting, or formulas are considered to be duplicates. This method also removes duplicates rows hidden from view (for example, due to a filter). Content outside of this range isn't removed.+ * @param columnsToCompare The columns to analyze for duplicate values. If no columns are provided then all columns are analyzed for duplicates.+ * @returns Range The resulting range after removing duplicates. The size of the range is reduced by a row for every row removed.+ */+ removeDuplicates(columnsToCompare: number[]): Range;+ removeDuplicates(...argument: any): Range {+ const { _rangeData, _context, _commandManager, _worksheet } = this;+ let columnsToCompare = [];+ // set columns+ if (Array.isArray(argument[0])) {+ columnsToCompare = argument[0];+ }++ const newCellValue = this.getMatrix().getData();++ const rowList: number[][] = [];++ for (let i = 0; i <= _rangeData.endColumn - _rangeData.startColumn; i++) {+ const arr: number[] = [];+ const obj: any = {};++ const column = this.getColumnMatrix(i).getData();+ for (const key in column) {+ // if (column.hasOwnProperty(key)) {+ const value = column[key][i].m;++ if (!obj.hasOwnProperty(value)) {+ obj[value!] = 1;+ arr.push(i);+ }+ // }+ }++ rowList.push(arr);+ }++ const newRowList = Array.from(new Set(rowList.flat()));++ const newData: { [key: number]: { [key: number]: ICellData } } = {};++ newRowList.forEach((item, i) => {+ newData[i] = newCellValue[item];+ });++ const removeDatas: ISetRangeDataActionData[] = [+ {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: newData,+ },+ ];+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...removeDatas+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * get row matrix+ * @returns+ */+ getRowMatrix(index: number) {+ const { startColumn, endColumn } = this._rangeData;++ const sheetMatrix = this._worksheet.getCellMatrix();+ const rangeMatrix = new ObjectMatrix<ICellData>();++ for (let r = index; r <= index; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || {});+ }+ }++ return rangeMatrix;+ }++ /**+ * get column matrix+ * @returns+ */+ getColumnMatrix(index: number) {+ const { startRow, endRow } = this._rangeData;++ const sheetMatrix = this._worksheet.getCellMatrix();+ const rangeMatrix = new ObjectMatrix<ICellData>();++ for (let r = startRow; r <= endRow; r++) {+ for (let c = index; c <= index; c++) {+ rangeMatrix.setValue(r, c, sheetMatrix.getValue(r, c) || {});+ }+ }++ return rangeMatrix;+ }++ forEach(action: (row: number, column: number) => void): void {+ Range.foreach(this._rangeData, action);+ }++ /**+ * Randomizes the order of the rows in the given range.+ * TODO:待研究特性+ * 1. 公式内的范围也会变化+ * 2. 并不是所有范围都支持随机处理+ * @returns+ */+ randomize() {+ const { _context, _worksheet, _commandManager, _rangeData } = this;+ const { startRow, startColumn } = _rangeData;+ const cellValue = new ObjectMatrix<ICellData>();++ const value = Tools.randSort(this.getMatrix().toArray());++ value.forEach((row, r) =>+ row.forEach((cell, c) => {+ cell = cell as ICellData;+ cellValue.setValue(r + startRow, c + startColumn, cell || {});+ })+ );++ const setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ cellValue: cellValue.getData(),+ };+ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setValue+ );+ _commandManager.invoke(command);+ }++ /**+ * Determine whether a range is legal+ */+ isValid(): boolean {+ if (Object.values(this._rangeData).includes(-1)) {+ return false;+ }+ return true;+ }++ /**+ * en:+ *+ * The process of copying a range to another range is obtained by the following rules+ *+ * [The two-dimensional array composed of the content or format to be assigned] => [Target range]+ *+ * 1. 1 -> 1: 1 => 1+ * 2. N -> 1: N => N+ * 3. 1 -> N: N => N+ * 4. N1 -> N2:+ * 1) N1 <N2: If N2 is a multiple of N1 (X), N1 * X => N2; If not, N1 => N1 (refer to office excel, different from google sheet)+ * 2) N1> N2: N1 => N1+ *+ * The above four cases can be combined and processed as+ *+ * Case 1, 1/2/4-2 merged into N1 => N1+ * Case 2, 3/4-1 merge into N1 * X => N2 or Case 1+ *+ * In the end we only need to judge whether N2 is a multiple of N1+ *+ * zh:+ *+ * 处理复制一个范围到另一个范围,由以下规则得到+ *+ * [将要赋值的内容或者格式组成的二维数组] => [目标范围]+ *+ * 1. 1 -> 1 : 1 => 1+ * 2. N -> 1 : N => N+ * 3. 1 -> N : N => N+ * 4. N1 -> N2 :+ * 1) N1 < N2 : 如果N2是N1的倍数X, N1 * X => N2; 如果不是,N1 => N1(参考office excel,和google sheet不同)+ * 2) N1 > N2 : N1 => N1+ *+ * 上面四种情况,可以合并处理为+ * 情况一, 1/2/4-2合并为 N1 => N1+ * 情况二, 3/4-1合并为 N1 * X => N2 或者情况一+ *+ * 最终我们只需要判断N2是否是N1的倍数+ *+ */+ private _handleCopyRange(+ originRange: Range,+ destinationRange: IRangeData+ ): [ICellDataMatrix, IRangeData];+ private _handleCopyRange(+ originRange: Range,+ destinationRange: Range+ ): [ICellDataMatrix, IRangeData];+ private _handleCopyRange(...argument: any): [ICellDataMatrix, IRangeData] {+ const originRange = argument[0];+ let destinationRange = argument[1];+ destinationRange = Tuples.checkup(argument, Range, Range)+ ? destinationRange.getRangeData()+ : destinationRange;++ const cellData = originRange._worksheet.getCellMatrix();+ const { startRow, endRow, startColumn, endColumn } =+ originRange.getRangeData();+ let {+ startRow: dStartRow,+ endRow: dEndRow,+ startColumn: dStartColumn,+ endColumn: dEndColumn,+ } = destinationRange;++ const originRows = endRow - startRow + 1;+ const originColumns = endColumn - startColumn + 1;+ const destinationRows = dEndRow - dStartRow + 1;+ const destinationColumns = dEndColumn - dStartColumn + 1;++ let value: ICellDataMatrix = [];+ let range: IRangeData;++ // judge whether N2 is a multiple of N1+ if (+ destinationRows % originRows === 0 &&+ destinationColumns % originColumns === 0+ ) {+ /**+ * A1,B1 => A1,B1,C1,D1+ * A2,B2 A2,B2,C2,D2+ * A3,B3,C3,D3+ * A4,B4,C4,D4+ */+ for (let r = 0; r < destinationRows; r++) {+ const row = [];+ for (let c = 0; c < destinationColumns; c++) {+ // Retrieve the corresponding cell data from the original range, {} as a fallback+ const cell =+ cellData.getValue(+ (r + startRow) % originRows,+ (c + startColumn) % originColumns+ ) || {};+ row.push(cell);+ }+ value.push(row);+ }++ range = destinationRange;+ } else {+ value = cellData+ .getFragments(startRow, endRow, startColumn, endColumn)+ .getData();++ // Extend the destination to the same size as the original range+ dEndRow += originRows - destinationRows;+ dEndColumn += originColumns - destinationColumns;++ range = {+ startRow: dStartRow,+ endRow: dEndRow,+ startColumn: dStartColumn,+ endColumn: dEndColumn,+ };+ }++ return [value, range];+ }++ /**+ *+ * @param arg Shorthand for the style that gets+ * @returns style value+ */+ private _getStyles<K>(+ arg: keyof IStyleData+ ): Array<Array<IStyleData[keyof IStyleData]>> {+ return this.getValues().map((row) =>+ row.map((cell: Nullable<ICellData>) => {+ const styles = this._context.getWorkBook().getStyles();++ // const style = getStyle(styles, cell);+ const style = styles && styles.getStyleByCell(cell);+ return (style && style[arg]) || DEFAULT_STYLES[arg];+ })+ );+ }++ // isStartColumnBounded() {}+ // isStartRowBounded() {}++ private _setStyle(+ value: Nullable<string | number | ITextDecoration>,+ type: string+ ) {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ // string converted to a two-dimensional array+ const styleObj = { [type]: value };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: SetRangeStyleAction.NAME,+ value: stylesMatrix,+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ private _setStyles(+ values: Array<Array<Nullable<string | number | ITextDecoration>>>,+ type: string+ ) {+ const { _context, _worksheet, _commandManager } = this;++ const { startRow, endRow, startColumn, endColumn } = this._rangeData;++ const matrix = new ObjectMatrix<IStyleData>();+ for (let r = 0; r < endRow - startRow + 1; r++) {+ for (let c = 0; c < endColumn - startColumn + 1; c++) {+ matrix.setValue(r, c, { [type]: values[r][c] });+ }+ }+ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: matrix.getData(),+ rangeData: this._rangeData,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setStyle+ );+ _commandManager.invoke(command);+ return this;+ }++ // /**+ // * Applies a default row banding theme to the range. By default, the banding has header and no footer color.+ // */+ // applyRowBanding(): Nullable<Banding>;++ // /**+ // * Applies a specified row banding theme to the range. By default, the banding has header and no footer color.+ // * @param bandingTheme+ // */+ // applyRowBanding(bandingTheme: BandingTheme | IBandingProperties): Nullable<Banding>;++ // /**+ // * Applies a specified row banding theme to the range with specified header and footer settings.+ // * @param bandingTheme+ // * @param showHeader+ // * @param showFooter+ // */+ // applyRowBanding(+ // bandingTheme: BandingTheme | IBandingProperties,+ // showHeader: boolean,+ // showFooter: boolean+ // ): Nullable<Banding>;+ // applyRowBanding(...argument: any): Nullable<Banding> {++ // // default argument+ // const bandedRangeId = 'banded-range-' + Tools.generateRandomId(6);+ // const rangeData = this.getRangeData()+ // let rowProperties:IBanding = {+ // bandingTheme:argument[0] || BandingTheme.LIGHT_GRAY,+ // showHeader:argument[1] || true,+ // showFooter:argument[2] || false,+ // }++ // const { _context, _commandManager } = this;+ // // Check whether the incoming range has been set to alternate colors+ // const bandings = this.getSheet().getBandings();+ // const isIntersection =+ // bandings &&+ // bandings.find((banding: Banding) =>+ // banding.getRange().isIntersection(this)+ // );+ // if (isIntersection) {+ // console.error(+ // 'You cannot add alternating background colors to a range that already has alternating background colors.'+ // );+ // return+ // }++ // // Organize action data+ // const actionData: IAddBandingActionData = {+ // actionName: ACTION_NAMES.ADD_BANDING_ACTION,+ // bandedRange:{+ // bandedRangeId,+ // rangeData,+ // rowProperties+ // },+ // sheetId: this.getSheet().getSheetId(),+ // };++ // // Execute action+ // const command = new Command(_context.getWorkBook(), actionData);+ // _commandManager.invoke(command);++ // return this.getSheet().getBandingById(bandedRangeId)+ // }+ // /**+ // * Applies a default row banding theme to the range. By default, the banding has header and no footer color.+ // */+ // applyRowBanding(): Nullable<Banding>;++ // /**+ // * Applies a specified row banding theme to the range. By default, the banding has header and no footer color.+ // * @param bandingTheme+ // */+ // applyRowBanding(+ // bandingTheme: BandingTheme | IBandingProperties+ // ): Nullable<Banding>;++ // /**+ // * Applies a specified row banding theme to the range with specified header and footer settings.+ // * @param bandingTheme+ // * @param showHeader+ // * @param showFooter+ // */+ // applyRowBanding(+ // bandingTheme: BandingTheme | IBandingProperties,+ // showHeader: boolean,+ // showFooter: boolean+ // ): Nullable<Banding>;+ // applyRowBanding(...argument: any): Nullable<Banding> {+ // // default argument+ // const bandedRangeId = 'banded-range-' + Tools.generateRandomId(6);+ // const rangeData = this.getRangeData();+ // let rowProperties: IBanding = {+ // bandingTheme: argument[0] || BandingTheme.LIGHT_GRAY,+ // showHeader: argument[1] || true,+ // showFooter: argument[2] || false,+ // };++ // const { _worksheet } = this;+ // // Check whether the incoming range has been set to alternate colors+ // const bandedRanges = _worksheet.getConfig().bandedRanges;+ // const isIntersection =+ // bandedRanges &&+ // bandedRanges.find((bandedRange: IBandedRange) =>+ // _worksheet.getRange(bandedRange.rangeData).isIntersection(this)+ // );+ // if (isIntersection) {+ // console.error(+ // 'You cannot add alternating background colors to a range that already has alternating background colors.'+ // );+ // return;+ // }++ // return new Banding(this._worksheet).addRowBanding({+ // bandedRangeId,+ // rangeData,+ // rowProperties,+ // });+ // }++ /**+ * Creates a filter applied to the range. There can be at most one filter in a sheet.+ * @returns The new filter.+ */+ // createFilter(): Filter {+ // return new Filter(this);+ // }+}++// Alternating Colors = bandingIns, range.applyRowBanding() bandingIns.setRowBanding(XXX) // bandingIns.remove(id)diff --git a/packages/core/src/Sheets/Domain/RangeList.ts b/packages/core/src/Sheets/Domain/RangeList.tsindex cc06b6bfc4..d4b07ac643 100644--- a/packages/core/src/Sheets/Domain/RangeList.ts+++ b/packages/core/src/Sheets/Domain/RangeList.ts@@ -1,742 +1,742 @@-import { Worksheet } from './index';-import { SheetContext } from '../../Basics';-import { Command, CommandManager } from '../../Command';-import { ACTION_NAMES } from '../../Const';-import {- BooleanNumber,- HorizontalAlign,- VerticalAlign,- WrapStrategy,-} from '../../Enum';-import {- ICellData,- ICellV,- IOptionData,- IRangeData,- IRangeType,- IStyleData,- ITextDecoration,-} from '../../Interfaces';-import { Workbook } from './Workbook';-import { Nullable, ObjectMatrix, Tools, Tuples } from '../../Shared';-import {- ClearRangeAction,- IClearRangeActionData,- ISetRangeDataActionData,- ISetRangeFormattedValueActionData,- ISetRangeStyleActionData,- SetRangeDataAction,- SetRangeStyleAction,-} from '../Action';--/**- * A collection of one or more Range instances in the same sheet.- *- * @remarks- * You can use this class to apply operations on collections of non-adjacent ranges or cells.- *- * Reference from: https://developers.google.com/apps-script/reference/spreadsheet/range-list- *- */-export class RangeList {- private _rangeListId: string;-- private _commandManager: CommandManager;-- private _workbook: Workbook;-- private _context: SheetContext;-- private _worksheet: Worksheet;-- private _rangeList: IRangeData[];-- constructor(worksheet: Worksheet, rangeList: IRangeType[]) {- this._context = worksheet.getContext();- this._workbook = this._context.getWorkBook();- this._commandManager = this._context.getCommandManager();- this._worksheet = worksheet;- this._rangeList = [];-- // Convert the rangeList passed in by the user into a standard format- rangeList.forEach((range: IRangeType) => {- // this._rangeList.push(- // new TransformTool(this._workbook).transformRangeType(range)- // );- this._rangeList.push(- this._context.getWorkBook().transformRangeType(range).rangeData- );- });-- // The user entered an invalid range- if (this._rangeList[0].startRow === -1) {- console.error('Invalid range,default set startRow -1');- }- }-- getRangeList(): IRangeData[] {- return this._rangeList;- }-- /**- * Selects the list of Range instances.- *- * @returns The list of active ranges, for chaining.- */- activate(): RangeList {- const { _context, _commandManager } = this;- // The user entered an invalid range- if (this._rangeList[0].startRow === -1) {- console.error('Invalid range,default set startRow -1');- return this;- }-- this._worksheet.getSelection().setSelection({ selection: this._rangeList });-- return this;- }-- /**- * Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.- */- // TODO- // breakApart() {}-- /**- * Sets the value for each Range in the range list. The value can be numeric, string, boolean or date. If it begins with '=' it is interpreted as a formula.- *- * @param value The value for the range list.- * @returns This range list, for chaining.- */- setValue(value: string | number | boolean): RangeList {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- // collect action list- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;- let cellValue = new ObjectMatrix<ICellData>();- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- cellValue.setValue(startRow, startColumn, {- m: `${value}`,- v: value,- });- }- }-- let setValue: ISetRangeDataActionData = {- sheetId: _worksheet.getSheetId(),- actionName: SetRangeDataAction.NAME,- cellValue: cellValue.getData(),- };- return setValue;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-- /**- * Clears the range of contents, formats, and data validation rules for each Range in the range list.- *- * @returns This range list, for chaining.- */- clear(): RangeList;-- /**- * Clears the range of contents and format, as specified with the given options. By default all data is cleared.- *- * @param options A JavaScript object that specifies advanced parameters, as listed IOptionData.- * @returns This range list, for chaining.- */- clear(options: IOptionData): RangeList;- clear(...argument: any): RangeList {- const { _context, _worksheet, _commandManager, _rangeList } = this;-- // default options- let options = {- formatOnly: true,- contentsOnly: true,- };- if (Tuples.checkup(argument, Tuples.OBJECT_TYPE)) {- options = argument[0];- }-- // collect action list- const clearList = _rangeList.map((range) => {- let clearRange: IClearRangeActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ClearRangeAction.NAME,- options,- rangeData: range,- };- return clearRange;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...clearList- );- _commandManager.invoke(command);-- return this;- }-- /**- * Clears text formatting for each Range in the range list.- *- * This clears text formatting for each range, but does not reset any number formatting rules.- * @returns This range list, for chaining.- */- clearFormat(): RangeList {- return this.clear({ formatOnly: true });- }-- /**- * Clears the content of each Range in the range list, leaving the formatting intact.- *- * @returns This range list, for chaining.- */- clearContent(): RangeList {- return this.clear({ contentsOnly: true });- }-- /**- * Sets the background color for each Range in the range list.- *- * @param color The background color code in CSS notation such as '#ffffff' or 'white'; a null value resets the color.- * @returns This range list, for chaining.- */- setBackground(color: Nullable<string>): RangeList {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- // string converted to a two-dimensional array- const styleObj = {- bg: {- rgb: color,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: range,- };-- return setStyle;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets the background to the given RGB color.- *- * @param red The red value in RGB notation.- * @param green The green value in RGB notation.- * @param blue The blue value in RGB notation.- * @returns This range list, for chaining.- */- setBackgroundRGB(red: number, green: number, blue: number): RangeList {- const rgbString = `RGB(${red},${green},${blue})`;-- let { _rangeList, _context, _commandManager, _worksheet } = this;- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- // string converted to a two-dimensional array- const styleObj = {- bg: {- rgb: rgbString,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: range,- };-- return setStyle;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-- // TODO- // setBorder(top, left, bottom, right, vertical, horizontal) {}- // setBorder(top, left, bottom, right, vertical, horizontal, color, style) {}-- /**- * Sets the font color for each Range in the range list. Color is represented in in CSS notation;- *- * @param color The font color in CSS notation such as '#ffffff' or 'white'; a null value resets the color.- * @returns This range list, for chaining.- */- setFontColor(color: Nullable<string>): RangeList {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- // string converted to a two-dimensional array- const styleObj = {- cl: {- rgb: color,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: range,- };-- return setStyle;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-- /**- * Sets the font family for each Range in the range list.- *- * @param fontFamily The font family to set; a null value resets the font family.- * @returns This range list, for chaining.- */- setFontFamily(fontFamily: Nullable<string>): RangeList {- return this._setStyle(fontFamily, 'ff');- }- // setFontLine(fontLine) {}-- /**- * Sets the underline for each Range in the range list.- *- * @param fontLine The underline to set; a null value resets the underline.- * @returns This range list, for chaining.- */- setUnderline(fontLine: Nullable<boolean | BooleanNumber>): RangeList {- const textDecoration: ITextDecoration = {- s: fontLine ? BooleanNumber.TRUE : BooleanNumber.FALSE,- };- return this._setStyle(textDecoration, 'ul');- }-- /**- * Sets the Overline for each Range in the range list.- *- * @param fontLine The Overline to set; a null value resets the Overline.- * @returns This range list, for chaining.- */- setOverline(fontLine: Nullable<boolean | BooleanNumber>): RangeList {- const textDecoration: ITextDecoration = {- s: fontLine ? BooleanNumber.TRUE : BooleanNumber.FALSE,- };- return this._setStyle(textDecoration, 'ol');- }-- /**- * Sets the StrikeThrough for each Range in the range list.- *- * @param fontLine The StrikeThrough to set; a null value resets the StrikeThrough.- * @returns This range list, for chaining.- */- setStrikeThrough(fontLine: Nullable<boolean | BooleanNumber>): RangeList {- const textDecoration: ITextDecoration = {- s: fontLine ? BooleanNumber.TRUE : BooleanNumber.FALSE,- };- return this._setStyle(textDecoration, 'st');- }-- /**- * Sets the font size (in points) for each Range in the range list.- *- * @param size A font point size.- * @returns This range list, for chaining.- */- setFontSize(size: Nullable<number>): RangeList {- return this._setStyle(size, 'fs');- }-- /**- * Set the font style for each Range in the range list- *- * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.- * @returns This range list, for chaining.- */- setFontStyle(fontStyle: Nullable<boolean | BooleanNumber>): RangeList {- const fontBoolean = fontStyle ? BooleanNumber.TRUE : BooleanNumber.FALSE;- return this._setStyle(fontBoolean, 'it');- }-- /**- * Set the font style for each Range in the range list.- *- * @param fontWeight The font weight, either 'bold' or 'normal'; a null value resets the font weight.- * @returns This range list, for chaining.- */- setFontWeight(fontWeight: Nullable<boolean | BooleanNumber>): RangeList {- const fontBoolean = fontWeight ? BooleanNumber.TRUE : BooleanNumber.FALSE;- return this._setStyle(fontBoolean, 'bl');- }-- /**- * Set the horizontal alignment for each Range in the range list.- *- * @param alignment The alignment, either 'left', 'center' or 'right'; a null value resets the alignment.- * @returns This range list, for chaining.- */- setHorizontalAlignment(alignment: Nullable<HorizontalAlign>): RangeList {- return this._setStyle(alignment, 'ht');- }-- /**- * Sets the note text for each Range in the range list.- *- * @param note The note text to set; a null value removes the note.- * @returns This range list, for chaining.- */- // setNote(note: Nullable<string>): RangeList {- // let { _rangeList, _context, _commandManager, _worksheet } = this;-- // const setList = _rangeList.map((range) => {- // let { startRow, startColumn, endRow, endColumn } = range;-- // let cellValue = new ObjectMatrix<string>();- // for (let r = startRow; r <= endRow; r++) {- // for (let c = startColumn; c <= endColumn; c++) {- // cellValue.setValue(r, c, note);- // }- // }-- // let setValue: ISetRangeNoteActionData = {- // sheetId: _worksheet.getSheetId(),- // actionName: ACTION_NAMES.SET_RANGE_NOTE_ACTION,- // cellNote: cellValue.getData(),- // rangeData: range,- // };-- // return setValue;- // });-- // let command = new Command(_context.getWorkBook(), ...setList);- // _commandManager.invoke(command);- // return this;- // }-- /**- * Sets the note text for each Range in the range list.- *- * @param numberFormat A number format string.- * @returns This range list, for chaining.- */- // setNumberFormat(numberFormat: string): RangeList {- // let { _rangeList, _context, _commandManager, _worksheet } = this;-- // const setList = _rangeList.map((range) => {- // let { startRow, startColumn, endRow, endColumn } = range;-- // let cellValue = new ObjectMatrix<string>();- // for (let r = 0; r <= endRow - startRow; r++) {- // for (let c = 0; c <= endColumn - startColumn; c++) {- // const fm = {- // f: numberFormat,- // t: FormatType.NUMBER,- // };- // cellValue.setValue(r + startRow, c + startColumn, JSON.stringify(fm));- // }- // }-- // let setValue: ISetRangeFormatActionData = {- // sheetId: _worksheet.getSheetId(),- // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,- // cellFormat: cellValue.getData(),- // rangeData: range,- // };-- // return setValue;- // });-- // let command = new Command(_context.getWorkBook(), ...setList);- // _commandManager.invoke(command);- // return this;- // }-- /**- * Sets the note text for each Range in the range list.- */- // TODO- // setShowHyperlink(showHyperlink) {}-- /**- * Sets the text direction for the cells in each Range in the range list.- *- * @param direction The desired text direction; if null the direction is inferred before setting.- * @returns This range list, for chaining.- */- setTextDirection(direction: Nullable<number>): RangeList {- return this._setStyle(direction, 'td');- }-- /**- * Sets the text rotation settings for the cells in each Range in the range list.- *- * @param degrees The desired angle between the standard orientation and the desired orientation. For left to right text, positive angles are in the counterclockwise direction.- * @returns This range list, for chaining.- */- setTextRotation(degrees: number): RangeList {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- const styleObj = {- tr: {- v: 0,- a: Number(degrees),- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: range,- };-- return setStyle;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-- /**- * Set the vertical alignment for each Range in the range list.- *- * @param alignment The alignment, either 'top', 'middle' or 'bottom'; a null value resets the alignment.- * @returns This range list, for chaining.- */- setVerticalAlignment(alignment: Nullable<VerticalAlign>): RangeList {- this._setStyle(alignment, 'vt');- return this;- }-- /**- * Sets whether or not to stack the text for the cells for each Range in the range list.- *- * @param isVertical Whether or not to stack the text.- * @returns This range list, for chaining.- */- setVerticalText(isVertical: BooleanNumber): RangeList {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- const styleObj = {- tr: {- v: isVertical,- a: 0,- },- };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,- value: stylesMatrix,- rangeData: range,- };-- return setStyle;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-- /**- * Set text wrapping for each Range in the range list.- *- * @param isWrapEnabled Whether to wrap text or not.- * @returns This range list, for chaining.- */- setWrap(isWrapEnabled: BooleanNumber): RangeList {- return this._setStyle(isWrapEnabled, 'tb');- }-- /**- * Sets the text wrapping strategy for each Range in the range list.- *- * @param strategy The desired wrapping strategy.- * @returns This range list, for chaining.- */- setWrapStrategy(strategy: WrapStrategy): RangeList {- return this._setStyle(strategy, 'tb');- }-- /**- * Trims the whitespace (such as spaces, tabs, or new lines) in every cell in this range list.- *- * @returns This range list, for chaining.- */- trimWhitespace(): RangeList {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- const sheetMatrix = this._worksheet.getCellMatrix();- const regx = /\s+/g;- let cellValue = new ObjectMatrix<ICellV>();- for (let r = startRow; r < endRow + 1; r++) {- for (let c = startColumn; c < endColumn + 1; c++) {- let m = sheetMatrix.getValue(r, c)!.m!;- const value = m.replace(regx, '');- cellValue.setValue(r, c, value || '');- }- }-- let setValue: ISetRangeFormattedValueActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,- cellValue: cellValue.getData(),- rangeData: range,- };-- return setValue;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-- /**- * set style- *- * @param value style value- * @param type style type- * @returns This range list, for chaining.- * @internal @preapproved- */- private _setStyle(- value: Nullable<number | string | ITextDecoration | BooleanNumber>,- type: string- ) {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- // string converted to a two-dimensional array- const styleObj: IStyleData = { [type]: value };-- const stylesMatrix = Tools.fillObjectMatrix(- endRow - startRow + 1,- endColumn - startColumn + 1,- styleObj- );-- const setStyle: ISetRangeStyleActionData = {- sheetId: _worksheet.getSheetId(),- value: stylesMatrix,- rangeData: range,- actionName: SetRangeStyleAction.NAME,- };-- return setStyle;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-}+import { Worksheet } from './index';+import { SheetContext } from '../../Basics';+import { Command, CommandManager } from '../../Command';+import { ACTION_NAMES } from '../../Types/Const';+import {+ BooleanNumber,+ HorizontalAlign,+ VerticalAlign,+ WrapStrategy,+} from '../../Types/Enum';+import {+ ICellData,+ ICellV,+ IOptionData,+ IRangeData,+ IRangeType,+ IStyleData,+ ITextDecoration,+} from '../../Types/Interfaces';+import { Workbook } from './Workbook';+import { Nullable, ObjectMatrix, Tools, Tuples } from '../../Shared';+import {+ ClearRangeAction,+ IClearRangeActionData,+ ISetRangeDataActionData,+ ISetRangeFormattedValueActionData,+ ISetRangeStyleActionData,+ SetRangeDataAction,+ SetRangeStyleAction,+} from '../Action';++/**+ * A collection of one or more Range instances in the same sheet.+ *+ * @remarks+ * You can use this class to apply operations on collections of non-adjacent ranges or cells.+ *+ * Reference from: https://developers.google.com/apps-script/reference/spreadsheet/range-list+ *+ */+export class RangeList {+ private _rangeListId: string;++ private _commandManager: CommandManager;++ private _workbook: Workbook;++ private _context: SheetContext;++ private _worksheet: Worksheet;++ private _rangeList: IRangeData[];++ constructor(worksheet: Worksheet, rangeList: IRangeType[]) {+ this._context = worksheet.getContext();+ this._workbook = this._context.getWorkBook();+ this._commandManager = this._context.getCommandManager();+ this._worksheet = worksheet;+ this._rangeList = [];++ // Convert the rangeList passed in by the user into a standard format+ rangeList.forEach((range: IRangeType) => {+ // this._rangeList.push(+ // new TransformTool(this._workbook).transformRangeType(range)+ // );+ this._rangeList.push(+ this._context.getWorkBook().transformRangeType(range).rangeData+ );+ });++ // The user entered an invalid range+ if (this._rangeList[0].startRow === -1) {+ console.error('Invalid range,default set startRow -1');+ }+ }++ getRangeList(): IRangeData[] {+ return this._rangeList;+ }++ /**+ * Selects the list of Range instances.+ *+ * @returns The list of active ranges, for chaining.+ */+ activate(): RangeList {+ const { _context, _commandManager } = this;+ // The user entered an invalid range+ if (this._rangeList[0].startRow === -1) {+ console.error('Invalid range,default set startRow -1');+ return this;+ }++ this._worksheet.getSelection().setSelection({ selection: this._rangeList });++ return this;+ }++ /**+ * Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.+ */+ // TODO+ // breakApart() {}++ /**+ * Sets the value for each Range in the range list. The value can be numeric, string, boolean or date. If it begins with '=' it is interpreted as a formula.+ *+ * @param value The value for the range list.+ * @returns This range list, for chaining.+ */+ setValue(value: string | number | boolean): RangeList {+ let { _rangeList, _context, _commandManager, _worksheet } = this;++ // collect action list+ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;+ let cellValue = new ObjectMatrix<ICellData>();+ for (let r = startRow; r <= endRow; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ cellValue.setValue(startRow, startColumn, {+ m: `${value}`,+ v: value,+ });+ }+ }++ let setValue: ISetRangeDataActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: SetRangeDataAction.NAME,+ cellValue: cellValue.getData(),+ };+ return setValue;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Clears the range of contents, formats, and data validation rules for each Range in the range list.+ *+ * @returns This range list, for chaining.+ */+ clear(): RangeList;++ /**+ * Clears the range of contents and format, as specified with the given options. By default all data is cleared.+ *+ * @param options A JavaScript object that specifies advanced parameters, as listed IOptionData.+ * @returns This range list, for chaining.+ */+ clear(options: IOptionData): RangeList;+ clear(...argument: any): RangeList {+ const { _context, _worksheet, _commandManager, _rangeList } = this;++ // default options+ let options = {+ formatOnly: true,+ contentsOnly: true,+ };+ if (Tuples.checkup(argument, Tuples.OBJECT_TYPE)) {+ options = argument[0];+ }++ // collect action list+ const clearList = _rangeList.map((range) => {+ let clearRange: IClearRangeActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ClearRangeAction.NAME,+ options,+ rangeData: range,+ };+ return clearRange;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...clearList+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * Clears text formatting for each Range in the range list.+ *+ * This clears text formatting for each range, but does not reset any number formatting rules.+ * @returns This range list, for chaining.+ */+ clearFormat(): RangeList {+ return this.clear({ formatOnly: true });+ }++ /**+ * Clears the content of each Range in the range list, leaving the formatting intact.+ *+ * @returns This range list, for chaining.+ */+ clearContent(): RangeList {+ return this.clear({ contentsOnly: true });+ }++ /**+ * Sets the background color for each Range in the range list.+ *+ * @param color The background color code in CSS notation such as '#ffffff' or 'white'; a null value resets the color.+ * @returns This range list, for chaining.+ */+ setBackground(color: Nullable<string>): RangeList {+ let { _rangeList, _context, _commandManager, _worksheet } = this;++ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;++ // string converted to a two-dimensional array+ const styleObj = {+ bg: {+ rgb: color,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: range,+ };++ return setStyle;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets the background to the given RGB color.+ *+ * @param red The red value in RGB notation.+ * @param green The green value in RGB notation.+ * @param blue The blue value in RGB notation.+ * @returns This range list, for chaining.+ */+ setBackgroundRGB(red: number, green: number, blue: number): RangeList {+ const rgbString = `RGB(${red},${green},${blue})`;++ let { _rangeList, _context, _commandManager, _worksheet } = this;+ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;++ // string converted to a two-dimensional array+ const styleObj = {+ bg: {+ rgb: rgbString,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: range,+ };++ return setStyle;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }++ // TODO+ // setBorder(top, left, bottom, right, vertical, horizontal) {}+ // setBorder(top, left, bottom, right, vertical, horizontal, color, style) {}++ /**+ * Sets the font color for each Range in the range list. Color is represented in in CSS notation;+ *+ * @param color The font color in CSS notation such as '#ffffff' or 'white'; a null value resets the color.+ * @returns This range list, for chaining.+ */+ setFontColor(color: Nullable<string>): RangeList {+ let { _rangeList, _context, _commandManager, _worksheet } = this;++ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;++ // string converted to a two-dimensional array+ const styleObj = {+ cl: {+ rgb: color,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: range,+ };++ return setStyle;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Sets the font family for each Range in the range list.+ *+ * @param fontFamily The font family to set; a null value resets the font family.+ * @returns This range list, for chaining.+ */+ setFontFamily(fontFamily: Nullable<string>): RangeList {+ return this._setStyle(fontFamily, 'ff');+ }+ // setFontLine(fontLine) {}++ /**+ * Sets the underline for each Range in the range list.+ *+ * @param fontLine The underline to set; a null value resets the underline.+ * @returns This range list, for chaining.+ */+ setUnderline(fontLine: Nullable<boolean | BooleanNumber>): RangeList {+ const textDecoration: ITextDecoration = {+ s: fontLine ? BooleanNumber.TRUE : BooleanNumber.FALSE,+ };+ return this._setStyle(textDecoration, 'ul');+ }++ /**+ * Sets the Overline for each Range in the range list.+ *+ * @param fontLine The Overline to set; a null value resets the Overline.+ * @returns This range list, for chaining.+ */+ setOverline(fontLine: Nullable<boolean | BooleanNumber>): RangeList {+ const textDecoration: ITextDecoration = {+ s: fontLine ? BooleanNumber.TRUE : BooleanNumber.FALSE,+ };+ return this._setStyle(textDecoration, 'ol');+ }++ /**+ * Sets the StrikeThrough for each Range in the range list.+ *+ * @param fontLine The StrikeThrough to set; a null value resets the StrikeThrough.+ * @returns This range list, for chaining.+ */+ setStrikeThrough(fontLine: Nullable<boolean | BooleanNumber>): RangeList {+ const textDecoration: ITextDecoration = {+ s: fontLine ? BooleanNumber.TRUE : BooleanNumber.FALSE,+ };+ return this._setStyle(textDecoration, 'st');+ }++ /**+ * Sets the font size (in points) for each Range in the range list.+ *+ * @param size A font point size.+ * @returns This range list, for chaining.+ */+ setFontSize(size: Nullable<number>): RangeList {+ return this._setStyle(size, 'fs');+ }++ /**+ * Set the font style for each Range in the range list+ *+ * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.+ * @returns This range list, for chaining.+ */+ setFontStyle(fontStyle: Nullable<boolean | BooleanNumber>): RangeList {+ const fontBoolean = fontStyle ? BooleanNumber.TRUE : BooleanNumber.FALSE;+ return this._setStyle(fontBoolean, 'it');+ }++ /**+ * Set the font style for each Range in the range list.+ *+ * @param fontWeight The font weight, either 'bold' or 'normal'; a null value resets the font weight.+ * @returns This range list, for chaining.+ */+ setFontWeight(fontWeight: Nullable<boolean | BooleanNumber>): RangeList {+ const fontBoolean = fontWeight ? BooleanNumber.TRUE : BooleanNumber.FALSE;+ return this._setStyle(fontBoolean, 'bl');+ }++ /**+ * Set the horizontal alignment for each Range in the range list.+ *+ * @param alignment The alignment, either 'left', 'center' or 'right'; a null value resets the alignment.+ * @returns This range list, for chaining.+ */+ setHorizontalAlignment(alignment: Nullable<HorizontalAlign>): RangeList {+ return this._setStyle(alignment, 'ht');+ }++ /**+ * Sets the note text for each Range in the range list.+ *+ * @param note The note text to set; a null value removes the note.+ * @returns This range list, for chaining.+ */+ // setNote(note: Nullable<string>): RangeList {+ // let { _rangeList, _context, _commandManager, _worksheet } = this;++ // const setList = _rangeList.map((range) => {+ // let { startRow, startColumn, endRow, endColumn } = range;++ // let cellValue = new ObjectMatrix<string>();+ // for (let r = startRow; r <= endRow; r++) {+ // for (let c = startColumn; c <= endColumn; c++) {+ // cellValue.setValue(r, c, note);+ // }+ // }++ // let setValue: ISetRangeNoteActionData = {+ // sheetId: _worksheet.getSheetId(),+ // actionName: ACTION_NAMES.SET_RANGE_NOTE_ACTION,+ // cellNote: cellValue.getData(),+ // rangeData: range,+ // };++ // return setValue;+ // });++ // let command = new Command(_context.getWorkBook(), ...setList);+ // _commandManager.invoke(command);+ // return this;+ // }++ /**+ * Sets the note text for each Range in the range list.+ *+ * @param numberFormat A number format string.+ * @returns This range list, for chaining.+ */+ // setNumberFormat(numberFormat: string): RangeList {+ // let { _rangeList, _context, _commandManager, _worksheet } = this;++ // const setList = _rangeList.map((range) => {+ // let { startRow, startColumn, endRow, endColumn } = range;++ // let cellValue = new ObjectMatrix<string>();+ // for (let r = 0; r <= endRow - startRow; r++) {+ // for (let c = 0; c <= endColumn - startColumn; c++) {+ // const fm = {+ // f: numberFormat,+ // t: FormatType.NUMBER,+ // };+ // cellValue.setValue(r + startRow, c + startColumn, JSON.stringify(fm));+ // }+ // }++ // let setValue: ISetRangeFormatActionData = {+ // sheetId: _worksheet.getSheetId(),+ // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,+ // cellFormat: cellValue.getData(),+ // rangeData: range,+ // };++ // return setValue;+ // });++ // let command = new Command(_context.getWorkBook(), ...setList);+ // _commandManager.invoke(command);+ // return this;+ // }++ /**+ * Sets the note text for each Range in the range list.+ */+ // TODO+ // setShowHyperlink(showHyperlink) {}++ /**+ * Sets the text direction for the cells in each Range in the range list.+ *+ * @param direction The desired text direction; if null the direction is inferred before setting.+ * @returns This range list, for chaining.+ */+ setTextDirection(direction: Nullable<number>): RangeList {+ return this._setStyle(direction, 'td');+ }++ /**+ * Sets the text rotation settings for the cells in each Range in the range list.+ *+ * @param degrees The desired angle between the standard orientation and the desired orientation. For left to right text, positive angles are in the counterclockwise direction.+ * @returns This range list, for chaining.+ */+ setTextRotation(degrees: number): RangeList {+ let { _rangeList, _context, _commandManager, _worksheet } = this;++ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;++ const styleObj = {+ tr: {+ v: 0,+ a: Number(degrees),+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: range,+ };++ return setStyle;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Set the vertical alignment for each Range in the range list.+ *+ * @param alignment The alignment, either 'top', 'middle' or 'bottom'; a null value resets the alignment.+ * @returns This range list, for chaining.+ */+ setVerticalAlignment(alignment: Nullable<VerticalAlign>): RangeList {+ this._setStyle(alignment, 'vt');+ return this;+ }++ /**+ * Sets whether or not to stack the text for the cells for each Range in the range list.+ *+ * @param isVertical Whether or not to stack the text.+ * @returns This range list, for chaining.+ */+ setVerticalText(isVertical: BooleanNumber): RangeList {+ let { _rangeList, _context, _commandManager, _worksheet } = this;++ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;++ const styleObj = {+ tr: {+ v: isVertical,+ a: 0,+ },+ };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_STYLE_ACTION,+ value: stylesMatrix,+ rangeData: range,+ };++ return setStyle;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * Set text wrapping for each Range in the range list.+ *+ * @param isWrapEnabled Whether to wrap text or not.+ * @returns This range list, for chaining.+ */+ setWrap(isWrapEnabled: BooleanNumber): RangeList {+ return this._setStyle(isWrapEnabled, 'tb');+ }++ /**+ * Sets the text wrapping strategy for each Range in the range list.+ *+ * @param strategy The desired wrapping strategy.+ * @returns This range list, for chaining.+ */+ setWrapStrategy(strategy: WrapStrategy): RangeList {+ return this._setStyle(strategy, 'tb');+ }++ /**+ * Trims the whitespace (such as spaces, tabs, or new lines) in every cell in this range list.+ *+ * @returns This range list, for chaining.+ */+ trimWhitespace(): RangeList {+ let { _rangeList, _context, _commandManager, _worksheet } = this;++ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;++ const sheetMatrix = this._worksheet.getCellMatrix();+ const regx = /\s+/g;+ let cellValue = new ObjectMatrix<ICellV>();+ for (let r = startRow; r < endRow + 1; r++) {+ for (let c = startColumn; c < endColumn + 1; c++) {+ let m = sheetMatrix.getValue(r, c)!.m!;+ const value = m.replace(regx, '');+ cellValue.setValue(r, c, value || '');+ }+ }++ let setValue: ISetRangeFormattedValueActionData = {+ sheetId: _worksheet.getSheetId(),+ actionName: ACTION_NAMES.SET_RANGE_FORMATTED_VALUE_ACTION,+ cellValue: cellValue.getData(),+ rangeData: range,+ };++ return setValue;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }++ /**+ * set style+ *+ * @param value style value+ * @param type style type+ * @returns This range list, for chaining.+ * @internal @preapproved+ */+ private _setStyle(+ value: Nullable<number | string | ITextDecoration | BooleanNumber>,+ type: string+ ) {+ let { _rangeList, _context, _commandManager, _worksheet } = this;++ const setList = _rangeList.map((range) => {+ let { startRow, startColumn, endRow, endColumn } = range;++ // string converted to a two-dimensional array+ const styleObj: IStyleData = { [type]: value };++ const stylesMatrix = Tools.fillObjectMatrix(+ endRow - startRow + 1,+ endColumn - startColumn + 1,+ styleObj+ );++ const setStyle: ISetRangeStyleActionData = {+ sheetId: _worksheet.getSheetId(),+ value: stylesMatrix,+ rangeData: range,+ actionName: SetRangeStyleAction.NAME,+ };++ return setStyle;+ });++ let command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ ...setList+ );+ _commandManager.invoke(command);+ return this;+ }+}diff --git a/packages/core/src/Sheets/Domain/RowManager.ts b/packages/core/src/Sheets/Domain/RowManager.tsindex 8d81abdeee..452963b2ae 100644--- a/packages/core/src/Sheets/Domain/RowManager.ts+++ b/packages/core/src/Sheets/Domain/RowManager.ts@@ -1,7 +1,7 @@import { Command } from '../../Command';import { ISetRowHeightActionData, SetRowHeightAction } from '../Action';-import { BooleanNumber } from '../../Enum';-import { IRowData } from '../../Interfaces';+import { BooleanNumber } from '../../Types/Enum';+import { IRowData } from '../../Types/Interfaces';import { Nullable, ObjectArray, ObjectArrayType, Tools } from '../../Shared';import { Worksheet } from './Worksheet';diff --git a/packages/core/src/Sheets/Domain/Selection.ts b/packages/core/src/Sheets/Domain/Selection.tsindex aeba61e784..c157180ff9 100644--- a/packages/core/src/Sheets/Domain/Selection.ts+++ b/packages/core/src/Sheets/Domain/Selection.ts@@ -1,785 +1,785 @@-import { SheetContext } from '../../Basics';-import { Command, CommandManager } from '../../Command';--import {- ISetSelectionActivateActionData,- SetSelectionActivateAction,-} from '../Action';--import { DEFAULT_SELECTION } from '../../Const';-import { Direction } from '../../Enum';-import { IRangeData, IRangeType, ISelectionData } from '../../Interfaces';-import { Nullable, Tools } from '../../Shared';-import { Range } from './Range';-import { RangeList } from './RangeList';-import { Workbook } from './Workbook';-import { Worksheet } from './Worksheet';--/**- *- * Access the current active selection in the active sheet.- *- * @remarks- * A selection is the set of cells the user has highlighted in the sheet, which can be non-adjacent ranges. One cell in the selection is the current cell, where the user's current focus is. The current cell is highlighted with a darker border in the UniverSheet UI.- *- * Current selection, each worksheet contains an array of selections, the last selection is the current active selection by default, or the selection with the active field set to true is the current active selection- *- * Reference: https://developers.google.com/apps-script/reference/spreadsheet/selection- *- * @privateRemarks- * zh: 当前选区,每个工作表包含一个选区数组,默认最后一个选区为当前激活选区,或者当前激活单元格所在选区为激活选区- *- * @beta- */-export class Selection {- private _commandManager: CommandManager;-- private _context: SheetContext;-- private _workbook: Workbook;-- private _workSheet: Worksheet;-- private _activeRange: Range;-- private _currentCell: Range;-- private _activeRangeList: RangeList;-- constructor(worksheet: Worksheet) {- this._workSheet = worksheet;- this._context = worksheet.getContext();- this._commandManager = this._context.getCommandManager();- this._workbook = worksheet.getContext().getWorkBook();-- // set default selection- this._activeRangeList = this._workSheet.getRangeList([DEFAULT_SELECTION]);- this._activeRange = this._workSheet.getRange(DEFAULT_SELECTION);- this._currentCell = this._workSheet.getRange(DEFAULT_SELECTION);- }-- /**- * Determine whether the cell is in the rangeList- *- * @param rangeList- * @param cell- * @returns- */- static cellInRange(- rangeList: IRangeData[],- cell: IRangeData- ): Nullable<IRangeData> {- for (const item of rangeList) {- if (- item.startRow <= cell.startRow &&- cell.endRow <= item.endRow &&- item.startColumn <= cell.startColumn &&- cell.endColumn <= item.endColumn- ) {- return item;- }- }-- return null;- }-- setWorkSheet(workSheet: Worksheet): void {- this._workSheet = workSheet;- }-- /**- * Update the range of the selection- *- * @param param0 - selection data- * @returns- */- setSelection({ selection, cell }: ISelectionData = {}): Range {- // if (!selection && !cell){- // return console.error('Must provide selection or cell parameters');- // }-- let activeRangeList: IRangeData[];-- let activeRange: IRangeData;-- let currentCell: IRangeData;-- // selection is Range instance- if (selection instanceof Range) {- // get range data- activeRange = selection.getRangeData();-- // The user entered an invalid range- if (activeRange.startRow === -1) {- console.error('Invalid selection, default set startRow -1');- }-- // set range list- activeRangeList = [activeRange];-- // get top-left cell in active range as current cell- currentCell = {- startRow: activeRange.startRow,- endRow: activeRange.startRow,- startColumn: activeRange.startColumn,- endColumn: activeRange.startColumn,- };- } else if (selection && Workbook.isIRangeType(selection)) {- // Convert the selection passed in by the user into a standard format- // activeRange = new TransformTool(this._workbook).transformRangeType(- // selection- // );- activeRange = this._workbook.transformRangeType(selection).rangeData;- // The user entered an invalid range- if (activeRange.startRow === -1) {- console.error('Invalid selection, default set startRow -1');- }-- // set range list- activeRangeList = [activeRange];-- // get top-left cell in active range as current cell- currentCell = {- startRow: activeRange.startRow,- endRow: activeRange.startRow,- startColumn: activeRange.startColumn,- endColumn: activeRange.startColumn,- };- } else if (selection instanceof Array) {- // Array is to prevent type detection-- // Convert the selection passed in by the user into a standard format- activeRangeList = selection.map((item: IRangeType) => {- // item = new TransformTool(this._workbook).transformRangeType(item);- const itemData: IRangeData =- this._workbook.transformRangeType(item).rangeData;- // The user entered an invalid range- if (itemData.startRow === -1) {- console.error('Invalid selection, default set startRow -1');- }-- return itemData;- });-- activeRange = activeRangeList[activeRangeList.length - 1];-- currentCell = {- startRow: activeRange.startRow,- endRow: activeRange.startRow,- startColumn: activeRange.startColumn,- endColumn: activeRange.startColumn,- };- } else {- // The current selection is taken by default- activeRangeList = this._activeRangeList.getRangeList();- activeRange = this._activeRange.getRangeData();- currentCell = this._currentCell.getRangeData();- }-- // update current cell based on currentCell- if (cell) {- // currentCell = new TransformTool(this._workbook).transformRangeType(cell);- currentCell = this._workbook.transformRangeType(cell).rangeData;- const activeRangeData: Nullable<IRangeData> = Selection.cellInRange(- activeRangeList,- currentCell- );-- // if cell not in range, reset new active range and active range list based on current cell- if (!activeRangeData) {- activeRange = currentCell;- activeRangeList = [activeRange];- }- }-- const { _context, _workSheet, _commandManager } = this;- const setSelection: ISetSelectionActivateActionData = {- sheetId: _workSheet.getSheetId(),- actionName: SetSelectionActivateAction.NAME,- activeRangeList,- activeRange,- currentCell,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setSelection- );- _commandManager.invoke(command);-- // 设置后获取范围(以A1:B10形式)- const text = `${- Tools.chatAtABC(activeRange.startColumn) + (activeRange.startRow + 1)- }:${Tools.chatAtABC(activeRange.endColumn)}${activeRange.endRow + 1}`;- this._context- .getObserverManager()- .getObserver<string>('onAfterSetSelectionObservable')- ?.notifyObservers(text);- return this._activeRange;- }-- /**- * get selection from active range instance- * @returns- */- getSelection(): IRangeData {- return Tools.deepClone(this._activeRange.getRangeData());- }-- /**- * Returns the selected range in the active sheet, or null if there is no active range. If multiple ranges are selected this method returns only the last selected range.- *- * @returns- */- getActiveRange(): Range {- return this._activeRange;- }-- /**- * Returns the list of active ranges in the active sheet or null if there are no active ranges.- * If there is a single range selected, this behaves as a getActiveRange() call.- * 已迁移到SelectionManager- * @returns- */- getActiveRangeList(): RangeList {- return this._activeRangeList;- }-- /**- * Returns the active sheet in the spreadsheet.- *- * @returns- */- getActiveSheet(): Nullable<Worksheet> {- return this._workbook.getActiveSheet();- }-- /**- * Returns the current (highlighted) cell that is selected in one of the active ranges or null if there is no current cell.- *- * @returns- */- getCurrentCell(): Range {- return this._currentCell;- }-- /**- * set current cell by range data- *- * @remarks- * Provide actual methods for range.activateAsCurrentCell- * If the specified cell is not present in any existing range, then the existing selection is removed and the cell becomes the current cell and the active range.- * Note: The specified Range must consist of one cell, otherwise it throws an exception.- *- * @param range - range data- * @returns- */- setCurrentCell(range: Range | IRangeData): Selection {- if (Tools.isAssignableFrom(range, Range)) {- range = range.getRangeData();- }-- if (range?.startRow === -1) {- console.error('Invalid range,default set startRow -1');- return this;- }-- if (- !(- range.startRow === range.endRow &&- range.startColumn === range.endColumn- )- ) {- console.error('Exception: Range must have a single cell.');- return this;- }- // 2. set current cell- // this._currentCell = this._workSheet.getRange(range);- // const activeRange = this._workSheet.getRange(range);-- // 3. change active range- const activeRangeList = this._activeRangeList.getRangeList();-- // If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.- // const _range = Selection.cellInRange(rangeList, range);-- // if (_range) {- // this._activeRange = this._workSheet.getRange(_range);- // } else {- // this._activeRange = this._workSheet.getRange(range);- // this._activeRangeList = this._workSheet.getRangeList([range]);- // }-- const { _context, _workSheet, _commandManager } = this;- const setSelection: ISetSelectionActivateActionData = {- sheetId: _workSheet.getSheetId(),- actionName: SetSelectionActivateAction.NAME,- activeRangeList,- activeRange: range,- currentCell: range,- };-- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setSelection- );- _commandManager.invoke(command);-- return this;- }-- /**- * set activeRangeList, avtiveRange, currentCell- * @param activeRangeList active range list- * @param activeRange last selected range- * @param currentCell current cell range- * @returns- */- setRanges(- activeRangeList: IRangeData | IRangeData[],- activeRange: IRangeData,- currentCell: IRangeData- ): void {- // Construct selection instance-- this._activeRangeList = this._workSheet.getRangeList(- activeRangeList as IRangeType[]- );- this._activeRange = this._workSheet.getRange(activeRange);- this._currentCell = this._workSheet.getRange(currentCell);- }-- /**- * move to next range by direction- *- * @remarks- * Starting from the current cell and active range and moving in the given direction, returns an adjusted range where the appropriate edge of the range has been shifted to cover the next data cell while still covering the current cell. If the active range is unbounded along the dimension of the direction, the original active range is returned. If there is no current cell or active range, null is returned. This is equivalent to selecting a range in the editor and hitting Ctrl+Shift+[arrow key].- *- * @returns- */- getNextDataRange(direction: Direction): Range {- const expandRangeData = this._expandRange(direction);-- this.setSelection({ selection: expandRangeData });-- return this.getActiveRange();- }-- /**- * expend data range by Ctrl+Shift+[arrow key]- *- * @returns- */- private _expandRange(direction: Direction): IRangeData {- const lastColumn = this._workSheet.getColumnCount();- const lastRow = this._workSheet.getRowCount();- const range = this._activeRange.getRangeData();- let expandRangeData = DEFAULT_SELECTION;- const currentCell = this.getCurrentCell().getRangeData();-- if (direction === Direction.RIGHT) {- if (currentCell.startColumn === range.startColumn) {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, range.endColumn);- let endColumn;- if (cellValue && cellValue.v === undefined) {- for (let i = range.endColumn + 1; i <= lastColumn; i++) {- if (i === lastColumn) {- endColumn = lastColumn;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v !== undefined) {- endColumn = i;- break;- }- }- } else {- for (let i = range.endColumn + 1; i <= lastColumn; i++) {- if (i === lastColumn) {- endColumn = lastColumn;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v === undefined) {- const prevCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i - 1);- if (prevCellValue && prevCellValue.v !== undefined) {- endColumn = i - 1;- break;- }- }- }- }- expandRangeData = {- startRow: range.startRow,- endRow: range.endRow,- startColumn: range.startColumn,- endColumn: endColumn !== undefined ? endColumn : range.endColumn,- };- } else {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, range.startColumn);- let startColumn;- if (cellValue && cellValue.v === undefined) {- for (- let i = range.startColumn + 1;- i <= currentCell.startColumn;- i++- ) {- if (i === currentCell.startColumn) {- startColumn = currentCell.startColumn;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v !== undefined) {- startColumn = i;- break;- }- }- } else {- for (- let i = range.startColumn + 1;- i <= currentCell.startColumn;- i++- ) {- if (i === currentCell.startColumn) {- startColumn = currentCell.startColumn;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v === undefined) {- const prevCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i - 1);- if (prevCellValue && prevCellValue.v !== undefined) {- startColumn = i - 1;- break;- }- }- }- }- expandRangeData = {- startRow: range.startRow,- endRow: range.endRow,- startColumn: startColumn || currentCell.startColumn,- endColumn: range.endColumn,- };- }- }- if (direction === Direction.LEFT) {- let startColumn;- let endColumn;- if (currentCell.endColumn === range.endColumn) {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, range.startColumn);- if (cellValue && cellValue.v === undefined) {- for (let i = range.startColumn - 1; i >= 0; i--) {- if (i === 0) {- startColumn = 0;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v !== undefined) {- startColumn = i;- break;- }- }- } else {- for (let i = range.startColumn - 1; i >= 0; i--) {- if (i === 0) {- startColumn = 0;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v === undefined) {- const prevCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i - 1);- if (prevCellValue && prevCellValue.v !== undefined) {- startColumn = i - 1;- break;- }- }- }- }- } else {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, range.endColumn);- if (cellValue && cellValue.v === undefined) {- for (- let i = range.endColumn - 1;- i >= currentCell.startColumn;- i--- ) {- if (i === currentCell.startColumn) {- endColumn = i;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v !== undefined) {- endColumn = i;- break;- }- }- } else {- for (- let i = range.endColumn - 1;- i >= currentCell.startColumn;- i--- ) {- if (i === currentCell.startColumn) {- endColumn = i;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i);- if (curCellValue && curCellValue.v === undefined) {- const prevCellValue = this._workSheet- .getCellMatrix()- .getValue(currentCell.startRow, i - 1);- if (prevCellValue && prevCellValue.v !== undefined) {- endColumn = i - 1;- break;- }- }- }- }- }- expandRangeData = {- startRow: range.startRow,- endRow: range.endRow,- startColumn:- startColumn !== undefined ? startColumn : range.startColumn,- endColumn: endColumn !== undefined ? endColumn : range.endColumn,- };- }- if (direction === Direction.TOP) {- let startRow;- let endRow;- if (currentCell.endRow === range.endRow) {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(range.startRow, currentCell.startColumn);- if (cellValue && cellValue.v === undefined) {- for (let i = range.endRow - 1; i >= 0; i--) {- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);- if (- (curCellValue && curCellValue.v !== undefined) ||- i === 0- ) {- startRow = i;- break;- }- }- } else {- for (let i = range.startRow - 1; i >= 0; i--) {- if (i === 0) {- startRow = 0;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);- if (curCellValue && curCellValue.v === undefined) {- const prevCellValue = this._workSheet- .getCellMatrix()- .getValue(i - 1, currentCell.startColumn);- if (prevCellValue && prevCellValue.v !== undefined) {- startRow = i - 1;- break;- }- }- }- }- } else {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(range.endRow, currentCell.startColumn);- if (cellValue && cellValue.v === undefined) {- for (let i = range.endRow - 1; i >= currentCell.startRow; i--) {- if (i === currentCell.startRow) {- endRow = currentCell.startRow;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);- // if (i <= range.startRow) {- // endRow = range.startRow;- // if (i == 0) {- // startRow = 0;- // break;- // }- // if (i == range.startRow) continue;- // if (curCellValue && curCellValue.v !== undefined) {- // startRow = i;- // break;- // }- // } else {- if (curCellValue && curCellValue.v !== undefined) {- endRow = i;- break;- }- // }- }- } else {- for (let i = range.endRow - 1; i >= currentCell.startRow; i--) {- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);-- if (i === currentCell.startRow) {- endRow = currentCell.startRow;- break;- } else if (- curCellValue &&- curCellValue.v === undefined &&- i !== range.endRow - 1- ) {- const nextCellValue = this._workSheet- .getCellMatrix()- .getValue(i + 1, currentCell.startColumn);- if (nextCellValue && nextCellValue.v !== undefined) {- endRow = i + 1;- break;- }- }- }- }- }- expandRangeData = {- startRow: startRow !== undefined ? startRow : range.startRow,- endRow: endRow !== undefined ? endRow : range.endRow,- startColumn: range.startColumn,- endColumn: range.endColumn,- };- }- if (direction === Direction.BOTTOM) {- let startRow;- let endRow;- if (currentCell.startRow === range.startRow) {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(range.endRow, currentCell.startColumn);- if (cellValue && cellValue.v === undefined) {- for (let i = range.endRow + 1; i <= lastRow; i++) {- if (i === lastRow) {- endRow = lastRow;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);- if (curCellValue && curCellValue.v !== undefined) {- endRow = i;- break;- }- }- } else {- for (let i = range.endRow + 1; i <= lastRow; i++) {- if (i === lastRow) {- endRow = lastRow;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);- if (curCellValue && curCellValue.v === undefined) {- const nextCellValue = this._workSheet- .getCellMatrix()- .getValue(i + 1, currentCell.startColumn);- if (nextCellValue && nextCellValue.v !== undefined) {- endRow = i + 1;- break;- }- }- }- }- } else {- const cellValue = this._workSheet- .getCellMatrix()- .getValue(range.startRow + 1, currentCell.startColumn);- if (cellValue && cellValue.v === undefined) {- for (- let i = range.startRow + 1;- i <= currentCell.startRow;- i++- ) {- if (i === currentCell.startRow) {- startRow = currentCell.startRow;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);- if (curCellValue && curCellValue.v !== undefined) {- startRow = i;- break;- }- }- } else {- for (- let i = range.startRow + 1;- i <= currentCell.startRow;- i++- ) {- if (i === currentCell.startRow) {- startRow = currentCell.startRow;- break;- }- const curCellValue = this._workSheet- .getCellMatrix()- .getValue(i, currentCell.startColumn);- if (- curCellValue &&- curCellValue.v === undefined &&- i !== range.startRow + 1- ) {- const prevCellValue = this._workSheet- .getCellMatrix()- .getValue(i - 1, currentCell.startColumn);- if (prevCellValue && prevCellValue.v !== undefined) {- startRow = i - 1;- break;- }- }- }- }- }- expandRangeData = {- startRow: startRow !== undefined ? startRow : range.startRow,- endRow: endRow !== undefined ? endRow : range.endRow,- startColumn: range.startColumn,- endColumn: range.endColumn,- };- }- return expandRangeData;- }-}+import { SheetContext } from '../../Basics';+import { Command, CommandManager } from '../../Command';++import {+ ISetSelectionActivateActionData,+ SetSelectionActivateAction,+} from '../Action';++import { DEFAULT_SELECTION } from '../../Types/Const';+import { Direction } from '../../Types/Enum';+import { IRangeData, IRangeType, ISelectionData } from '../../Types/Interfaces';+import { Nullable, Tools } from '../../Shared';+import { Range } from './Range';+import { RangeList } from './RangeList';+import { Workbook } from './Workbook';+import { Worksheet } from './Worksheet';++/**+ *+ * Access the current active selection in the active sheet.+ *+ * @remarks+ * A selection is the set of cells the user has highlighted in the sheet, which can be non-adjacent ranges. One cell in the selection is the current cell, where the user's current focus is. The current cell is highlighted with a darker border in the UniverSheet UI.+ *+ * Current selection, each worksheet contains an array of selections, the last selection is the current active selection by default, or the selection with the active field set to true is the current active selection+ *+ * Reference: https://developers.google.com/apps-script/reference/spreadsheet/selection+ *+ * @privateRemarks+ * zh: 当前选区,每个工作表包含一个选区数组,默认最后一个选区为当前激活选区,或者当前激活单元格所在选区为激活选区+ *+ * @beta+ */+export class Selection {+ private _commandManager: CommandManager;++ private _context: SheetContext;++ private _workbook: Workbook;++ private _workSheet: Worksheet;++ private _activeRange: Range;++ private _currentCell: Range;++ private _activeRangeList: RangeList;++ constructor(worksheet: Worksheet) {+ this._workSheet = worksheet;+ this._context = worksheet.getContext();+ this._commandManager = this._context.getCommandManager();+ this._workbook = worksheet.getContext().getWorkBook();++ // set default selection+ this._activeRangeList = this._workSheet.getRangeList([DEFAULT_SELECTION]);+ this._activeRange = this._workSheet.getRange(DEFAULT_SELECTION);+ this._currentCell = this._workSheet.getRange(DEFAULT_SELECTION);+ }++ /**+ * Determine whether the cell is in the rangeList+ *+ * @param rangeList+ * @param cell+ * @returns+ */+ static cellInRange(+ rangeList: IRangeData[],+ cell: IRangeData+ ): Nullable<IRangeData> {+ for (const item of rangeList) {+ if (+ item.startRow <= cell.startRow &&+ cell.endRow <= item.endRow &&+ item.startColumn <= cell.startColumn &&+ cell.endColumn <= item.endColumn+ ) {+ return item;+ }+ }++ return null;+ }++ setWorkSheet(workSheet: Worksheet): void {+ this._workSheet = workSheet;+ }++ /**+ * Update the range of the selection+ *+ * @param param0 - selection data+ * @returns+ */+ setSelection({ selection, cell }: ISelectionData = {}): Range {+ // if (!selection && !cell){+ // return console.error('Must provide selection or cell parameters');+ // }++ let activeRangeList: IRangeData[];++ let activeRange: IRangeData;++ let currentCell: IRangeData;++ // selection is Range instance+ if (selection instanceof Range) {+ // get range data+ activeRange = selection.getRangeData();++ // The user entered an invalid range+ if (activeRange.startRow === -1) {+ console.error('Invalid selection, default set startRow -1');+ }++ // set range list+ activeRangeList = [activeRange];++ // get top-left cell in active range as current cell+ currentCell = {+ startRow: activeRange.startRow,+ endRow: activeRange.startRow,+ startColumn: activeRange.startColumn,+ endColumn: activeRange.startColumn,+ };+ } else if (selection && Workbook.isIRangeType(selection)) {+ // Convert the selection passed in by the user into a standard format+ // activeRange = new TransformTool(this._workbook).transformRangeType(+ // selection+ // );+ activeRange = this._workbook.transformRangeType(selection).rangeData;+ // The user entered an invalid range+ if (activeRange.startRow === -1) {+ console.error('Invalid selection, default set startRow -1');+ }++ // set range list+ activeRangeList = [activeRange];++ // get top-left cell in active range as current cell+ currentCell = {+ startRow: activeRange.startRow,+ endRow: activeRange.startRow,+ startColumn: activeRange.startColumn,+ endColumn: activeRange.startColumn,+ };+ } else if (selection instanceof Array) {+ // Array is to prevent type detection++ // Convert the selection passed in by the user into a standard format+ activeRangeList = selection.map((item: IRangeType) => {+ // item = new TransformTool(this._workbook).transformRangeType(item);+ const itemData: IRangeData =+ this._workbook.transformRangeType(item).rangeData;+ // The user entered an invalid range+ if (itemData.startRow === -1) {+ console.error('Invalid selection, default set startRow -1');+ }++ return itemData;+ });++ activeRange = activeRangeList[activeRangeList.length - 1];++ currentCell = {+ startRow: activeRange.startRow,+ endRow: activeRange.startRow,+ startColumn: activeRange.startColumn,+ endColumn: activeRange.startColumn,+ };+ } else {+ // The current selection is taken by default+ activeRangeList = this._activeRangeList.getRangeList();+ activeRange = this._activeRange.getRangeData();+ currentCell = this._currentCell.getRangeData();+ }++ // update current cell based on currentCell+ if (cell) {+ // currentCell = new TransformTool(this._workbook).transformRangeType(cell);+ currentCell = this._workbook.transformRangeType(cell).rangeData;+ const activeRangeData: Nullable<IRangeData> = Selection.cellInRange(+ activeRangeList,+ currentCell+ );++ // if cell not in range, reset new active range and active range list based on current cell+ if (!activeRangeData) {+ activeRange = currentCell;+ activeRangeList = [activeRange];+ }+ }++ const { _context, _workSheet, _commandManager } = this;+ const setSelection: ISetSelectionActivateActionData = {+ sheetId: _workSheet.getSheetId(),+ actionName: SetSelectionActivateAction.NAME,+ activeRangeList,+ activeRange,+ currentCell,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setSelection+ );+ _commandManager.invoke(command);++ // 设置后获取范围(以A1:B10形式)+ const text = `${+ Tools.chatAtABC(activeRange.startColumn) + (activeRange.startRow + 1)+ }:${Tools.chatAtABC(activeRange.endColumn)}${activeRange.endRow + 1}`;+ this._context+ .getObserverManager()+ .getObserver<string>('onAfterSetSelectionObservable')+ ?.notifyObservers(text);+ return this._activeRange;+ }++ /**+ * get selection from active range instance+ * @returns+ */+ getSelection(): IRangeData {+ return Tools.deepClone(this._activeRange.getRangeData());+ }++ /**+ * Returns the selected range in the active sheet, or null if there is no active range. If multiple ranges are selected this method returns only the last selected range.+ *+ * @returns+ */+ getActiveRange(): Range {+ return this._activeRange;+ }++ /**+ * Returns the list of active ranges in the active sheet or null if there are no active ranges.+ * If there is a single range selected, this behaves as a getActiveRange() call.+ * 已迁移到SelectionManager+ * @returns+ */+ getActiveRangeList(): RangeList {+ return this._activeRangeList;+ }++ /**+ * Returns the active sheet in the spreadsheet.+ *+ * @returns+ */+ getActiveSheet(): Nullable<Worksheet> {+ return this._workbook.getActiveSheet();+ }++ /**+ * Returns the current (highlighted) cell that is selected in one of the active ranges or null if there is no current cell.+ *+ * @returns+ */+ getCurrentCell(): Range {+ return this._currentCell;+ }++ /**+ * set current cell by range data+ *+ * @remarks+ * Provide actual methods for range.activateAsCurrentCell+ * If the specified cell is not present in any existing range, then the existing selection is removed and the cell becomes the current cell and the active range.+ * Note: The specified Range must consist of one cell, otherwise it throws an exception.+ *+ * @param range - range data+ * @returns+ */+ setCurrentCell(range: Range | IRangeData): Selection {+ if (Tools.isAssignableFrom(range, Range)) {+ range = range.getRangeData();+ }++ if (range?.startRow === -1) {+ console.error('Invalid range,default set startRow -1');+ return this;+ }++ if (+ !(+ range.startRow === range.endRow &&+ range.startColumn === range.endColumn+ )+ ) {+ console.error('Exception: Range must have a single cell.');+ return this;+ }+ // 2. set current cell+ // this._currentCell = this._workSheet.getRange(range);+ // const activeRange = this._workSheet.getRange(range);++ // 3. change active range+ const activeRangeList = this._activeRangeList.getRangeList();++ // If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.+ // const _range = Selection.cellInRange(rangeList, range);++ // if (_range) {+ // this._activeRange = this._workSheet.getRange(_range);+ // } else {+ // this._activeRange = this._workSheet.getRange(range);+ // this._activeRangeList = this._workSheet.getRangeList([range]);+ // }++ const { _context, _workSheet, _commandManager } = this;+ const setSelection: ISetSelectionActivateActionData = {+ sheetId: _workSheet.getSheetId(),+ actionName: SetSelectionActivateAction.NAME,+ activeRangeList,+ activeRange: range,+ currentCell: range,+ };++ const command = new Command(+ {+ WorkBookUnit: _context.getWorkBook(),+ },+ setSelection+ );+ _commandManager.invoke(command);++ return this;+ }++ /**+ * set activeRangeList, avtiveRange, currentCell+ * @param activeRangeList active range list+ * @param activeRange last selected range+ * @param currentCell current cell range+ * @returns+ */+ setRanges(+ activeRangeList: IRangeData | IRangeData[],+ activeRange: IRangeData,+ currentCell: IRangeData+ ): void {+ // Construct selection instance++ this._activeRangeList = this._workSheet.getRangeList(+ activeRangeList as IRangeType[]+ );+ this._activeRange = this._workSheet.getRange(activeRange);+ this._currentCell = this._workSheet.getRange(currentCell);+ }++ /**+ * move to next range by direction+ *+ * @remarks+ * Starting from the current cell and active range and moving in the given direction, returns an adjusted range where the appropriate edge of the range has been shifted to cover the next data cell while still covering the current cell. If the active range is unbounded along the dimension of the direction, the original active range is returned. If there is no current cell or active range, null is returned. This is equivalent to selecting a range in the editor and hitting Ctrl+Shift+[arrow key].+ *+ * @returns+ */+ getNextDataRange(direction: Direction): Range {+ const expandRangeData = this._expandRange(direction);++ this.setSelection({ selection: expandRangeData });++ return this.getActiveRange();+ }++ /**+ * expend data range by Ctrl+Shift+[arrow key]+ *+ * @returns+ */+ private _expandRange(direction: Direction): IRangeData {+ const lastColumn = this._workSheet.getColumnCount();+ const lastRow = this._workSheet.getRowCount();+ const range = this._activeRange.getRangeData();+ let expandRangeData = DEFAULT_SELECTION;+ const currentCell = this.getCurrentCell().getRangeData();++ if (direction === Direction.RIGHT) {+ if (currentCell.startColumn === range.startColumn) {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, range.endColumn);+ let endColumn;+ if (cellValue && cellValue.v === undefined) {+ for (let i = range.endColumn + 1; i <= lastColumn; i++) {+ if (i === lastColumn) {+ endColumn = lastColumn;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v !== undefined) {+ endColumn = i;+ break;+ }+ }+ } else {+ for (let i = range.endColumn + 1; i <= lastColumn; i++) {+ if (i === lastColumn) {+ endColumn = lastColumn;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v === undefined) {+ const prevCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i - 1);+ if (prevCellValue && prevCellValue.v !== undefined) {+ endColumn = i - 1;+ break;+ }+ }+ }+ }+ expandRangeData = {+ startRow: range.startRow,+ endRow: range.endRow,+ startColumn: range.startColumn,+ endColumn: endColumn !== undefined ? endColumn : range.endColumn,+ };+ } else {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, range.startColumn);+ let startColumn;+ if (cellValue && cellValue.v === undefined) {+ for (+ let i = range.startColumn + 1;+ i <= currentCell.startColumn;+ i+++ ) {+ if (i === currentCell.startColumn) {+ startColumn = currentCell.startColumn;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v !== undefined) {+ startColumn = i;+ break;+ }+ }+ } else {+ for (+ let i = range.startColumn + 1;+ i <= currentCell.startColumn;+ i+++ ) {+ if (i === currentCell.startColumn) {+ startColumn = currentCell.startColumn;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v === undefined) {+ const prevCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i - 1);+ if (prevCellValue && prevCellValue.v !== undefined) {+ startColumn = i - 1;+ break;+ }+ }+ }+ }+ expandRangeData = {+ startRow: range.startRow,+ endRow: range.endRow,+ startColumn: startColumn || currentCell.startColumn,+ endColumn: range.endColumn,+ };+ }+ }+ if (direction === Direction.LEFT) {+ let startColumn;+ let endColumn;+ if (currentCell.endColumn === range.endColumn) {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, range.startColumn);+ if (cellValue && cellValue.v === undefined) {+ for (let i = range.startColumn - 1; i >= 0; i--) {+ if (i === 0) {+ startColumn = 0;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v !== undefined) {+ startColumn = i;+ break;+ }+ }+ } else {+ for (let i = range.startColumn - 1; i >= 0; i--) {+ if (i === 0) {+ startColumn = 0;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v === undefined) {+ const prevCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i - 1);+ if (prevCellValue && prevCellValue.v !== undefined) {+ startColumn = i - 1;+ break;+ }+ }+ }+ }+ } else {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, range.endColumn);+ if (cellValue && cellValue.v === undefined) {+ for (+ let i = range.endColumn - 1;+ i >= currentCell.startColumn;+ i--+ ) {+ if (i === currentCell.startColumn) {+ endColumn = i;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v !== undefined) {+ endColumn = i;+ break;+ }+ }+ } else {+ for (+ let i = range.endColumn - 1;+ i >= currentCell.startColumn;+ i--+ ) {+ if (i === currentCell.startColumn) {+ endColumn = i;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i);+ if (curCellValue && curCellValue.v === undefined) {+ const prevCellValue = this._workSheet+ .getCellMatrix()+ .getValue(currentCell.startRow, i - 1);+ if (prevCellValue && prevCellValue.v !== undefined) {+ endColumn = i - 1;+ break;+ }+ }+ }+ }+ }+ expandRangeData = {+ startRow: range.startRow,+ endRow: range.endRow,+ startColumn:+ startColumn !== undefined ? startColumn : range.startColumn,+ endColumn: endColumn !== undefined ? endColumn : range.endColumn,+ };+ }+ if (direction === Direction.TOP) {+ let startRow;+ let endRow;+ if (currentCell.endRow === range.endRow) {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(range.startRow, currentCell.startColumn);+ if (cellValue && cellValue.v === undefined) {+ for (let i = range.endRow - 1; i >= 0; i--) {+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);+ if (+ (curCellValue && curCellValue.v !== undefined) ||+ i === 0+ ) {+ startRow = i;+ break;+ }+ }+ } else {+ for (let i = range.startRow - 1; i >= 0; i--) {+ if (i === 0) {+ startRow = 0;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);+ if (curCellValue && curCellValue.v === undefined) {+ const prevCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i - 1, currentCell.startColumn);+ if (prevCellValue && prevCellValue.v !== undefined) {+ startRow = i - 1;+ break;+ }+ }+ }+ }+ } else {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(range.endRow, currentCell.startColumn);+ if (cellValue && cellValue.v === undefined) {+ for (let i = range.endRow - 1; i >= currentCell.startRow; i--) {+ if (i === currentCell.startRow) {+ endRow = currentCell.startRow;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);+ // if (i <= range.startRow) {+ // endRow = range.startRow;+ // if (i == 0) {+ // startRow = 0;+ // break;+ // }+ // if (i == range.startRow) continue;+ // if (curCellValue && curCellValue.v !== undefined) {+ // startRow = i;+ // break;+ // }+ // } else {+ if (curCellValue && curCellValue.v !== undefined) {+ endRow = i;+ break;+ }+ // }+ }+ } else {+ for (let i = range.endRow - 1; i >= currentCell.startRow; i--) {+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);++ if (i === currentCell.startRow) {+ endRow = currentCell.startRow;+ break;+ } else if (+ curCellValue &&+ curCellValue.v === undefined &&+ i !== range.endRow - 1+ ) {+ const nextCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i + 1, currentCell.startColumn);+ if (nextCellValue && nextCellValue.v !== undefined) {+ endRow = i + 1;+ break;+ }+ }+ }+ }+ }+ expandRangeData = {+ startRow: startRow !== undefined ? startRow : range.startRow,+ endRow: endRow !== undefined ? endRow : range.endRow,+ startColumn: range.startColumn,+ endColumn: range.endColumn,+ };+ }+ if (direction === Direction.BOTTOM) {+ let startRow;+ let endRow;+ if (currentCell.startRow === range.startRow) {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(range.endRow, currentCell.startColumn);+ if (cellValue && cellValue.v === undefined) {+ for (let i = range.endRow + 1; i <= lastRow; i++) {+ if (i === lastRow) {+ endRow = lastRow;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);+ if (curCellValue && curCellValue.v !== undefined) {+ endRow = i;+ break;+ }+ }+ } else {+ for (let i = range.endRow + 1; i <= lastRow; i++) {+ if (i === lastRow) {+ endRow = lastRow;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);+ if (curCellValue && curCellValue.v === undefined) {+ const nextCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i + 1, currentCell.startColumn);+ if (nextCellValue && nextCellValue.v !== undefined) {+ endRow = i + 1;+ break;+ }+ }+ }+ }+ } else {+ const cellValue = this._workSheet+ .getCellMatrix()+ .getValue(range.startRow + 1, currentCell.startColumn);+ if (cellValue && cellValue.v === undefined) {+ for (+ let i = range.startRow + 1;+ i <= currentCell.startRow;+ i+++ ) {+ if (i === currentCell.startRow) {+ startRow = currentCell.startRow;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);+ if (curCellValue && curCellValue.v !== undefined) {+ startRow = i;+ break;+ }+ }+ } else {+ for (+ let i = range.startRow + 1;+ i <= currentCell.startRow;+ i+++ ) {+ if (i === currentCell.startRow) {+ startRow = currentCell.startRow;+ break;+ }+ const curCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i, currentCell.startColumn);+ if (+ curCellValue &&+ curCellValue.v === undefined &&+ i !== range.startRow + 1+ ) {+ const prevCellValue = this._workSheet+ .getCellMatrix()+ .getValue(i - 1, currentCell.startColumn);+ if (prevCellValue && prevCellValue.v !== undefined) {+ startRow = i - 1;+ break;+ }+ }+ }+ }+ }+ expandRangeData = {+ startRow: startRow !== undefined ? startRow : range.startRow,+ endRow: endRow !== undefined ? endRow : range.endRow,+ startColumn: range.startColumn,+ endColumn: range.endColumn,+ };+ }+ return expandRangeData;+ }+}diff --git a/packages/core/src/Sheets/Domain/Styles.ts b/packages/core/src/Sheets/Domain/Styles.tsindex 4ed7b0b56a..73be0d254d 100644--- a/packages/core/src/Sheets/Domain/Styles.ts+++ b/packages/core/src/Sheets/Domain/Styles.ts@@ -1,71 +1,71 @@-import { ICellData, IStyleData } from '../../Interfaces';-import { IKeyType, Nullable, Tools } from '../../Shared';--/**- * Styles in a workbook, cells locate styles based on style IDs- */-export class Styles {- private _styles: IKeyType<Nullable<IStyleData>>;-- constructor(styles: IKeyType<Nullable<IStyleData>> = {}) {- this._styles = styles;- }-- each(- callback: (- value: [string, Nullable<IStyleData>],- index: number,- array: Array<[string, Nullable<IStyleData>]>- ) => void- ) {- Object.entries(this._styles).forEach(callback);- return this;- }-- search(data: IStyleData): string {- const { _styles } = this;-- for (const id in _styles) {- if (Tools.diffValue(_styles[id], data)) {- return id;- }- }- return '-1';- }-- get(id: string | Nullable<IStyleData>): Nullable<IStyleData> {- id = String(id);- if (typeof id !== 'string') return id;- return this._styles[id];- }-- add(data: IStyleData): string {- const id = Tools.generateRandomId(6);- this._styles[id] = data;- return id;- }-- setValue(data: Nullable<IStyleData>): Nullable<string> {- if (data == null) return;- const result = this.search(data);- if (result !== '-1') {- return result;- }- return this.add(data);- }-- toJSON(): IKeyType<Nullable<IStyleData>> {- return this._styles;- }-- getStyleByCell(cell: Nullable<ICellData>): Nullable<IStyleData> {- let style;- if (cell && Tools.isObject(cell.s)) {- style = cell.s as IStyleData;- } else {- style = cell?.s && this.get(cell.s);- }-- return style as IStyleData;- }-}+import { ICellData, IStyleData } from '../../Types/Interfaces';+import { IKeyType, Nullable, Tools } from '../../Shared';++/**+ * Styles in a workbook, cells locate styles based on style IDs+ */+export class Styles {+ private _styles: IKeyType<Nullable<IStyleData>>;++ constructor(styles: IKeyType<Nullable<IStyleData>> = {}) {+ this._styles = styles;+ }++ each(+ callback: (+ value: [string, Nullable<IStyleData>],+ index: number,+ array: Array<[string, Nullable<IStyleData>]>+ ) => void+ ) {+ Object.entries(this._styles).forEach(callback);+ return this;+ }++ search(data: IStyleData): string {+ const { _styles } = this;++ for (const id in _styles) {+ if (Tools.diffValue(_styles[id], data)) {+ return id;+ }+ }+ return '-1';+ }++ get(id: string | Nullable<IStyleData>): Nullable<IStyleData> {+ id = String(id);+ if (typeof id !== 'string') return id;+ return this._styles[id];+ }++ add(data: IStyleData): string {+ const id = Tools.generateRandomId(6);+ this._styles[id] = data;+ return id;+ }++ setValue(data: Nullable<IStyleData>): Nullable<string> {+ if (data == null) return;+ const result = this.search(data);+ if (result !== '-1') {+ return result;+ }+ return this.add(data);+ }++ toJSON(): IKeyType<Nullable<IStyleData>> {+ return this._styles;+ }++ getStyleByCell(cell: Nullable<ICellData>): Nullable<IStyleData> {+ let style;+ if (cell && Tools.isObject(cell.s)) {+ style = cell.s as IStyleData;+ } else {+ style = cell?.s && this.get(cell.s);+ }++ return style as IStyleData;+ }+}diff --git a/packages/core/src/Sheets/Domain/Workbook.ts b/packages/core/src/Sheets/Domain/Workbook.tsindex e1cab2c980..ed215d6441 100644--- a/packages/core/src/Sheets/Domain/Workbook.ts+++ b/packages/core/src/Sheets/Domain/Workbook.ts@@ -2,9 +2,9 @@ import {DEFAULT_RANGE_ARRAY,DEFAULT_WORKBOOK,DEFAULT_WORKSHEET,-} from '../../Const';+} from '../../Types/Const';-import { BooleanNumber } from '../../Enum';+import { BooleanNumber } from '../../Types/Enum';import { SheetContext, Univer } from '../../Basics';import {@@ -26,7 +26,7 @@ import {IRowStartEndData,IWorkbookConfig,IWorksheetConfig,-} from '../../Interfaces';+} from '../../Types/Interfaces';import { Nullable, Tools, Tuples } from '../../Shared';import { RangeList } from './RangeList';diff --git a/packages/core/src/Sheets/Domain/Worksheet.ts b/packages/core/src/Sheets/Domain/Worksheet.tsindex c969ca86d0..1dd8ad5a6d 100644--- a/packages/core/src/Sheets/Domain/Worksheet.ts+++ b/packages/core/src/Sheets/Domain/Worksheet.ts@@ -41,8 +41,8 @@ import {SetWorkSheetNameAction,SetWorkSheetStatusAction,} from '../Action';-import { DEFAULT_WORKSHEET } from '../../Const';-import { Direction, BooleanNumber, SheetTypes } from '../../Enum';+import { DEFAULT_WORKSHEET } from '../../Types/Const';+import { Direction, BooleanNumber, SheetTypes } from '../../Types/Enum';import {IBorderStyleData,ICellData,@@ -53,7 +53,7 @@ import {ISelectionData,IStyleData,IWorksheetConfig,-} from '../../Interfaces';+} from '../../Types/Interfaces';import { Nullable, ObjectMatrix, Tools, Tuples } from '../../Shared';import { ColumnManager } from './ColumnManager';import { Merges } from './Merges';diff --git a/packages/core/src/Slides/Domain/SlideModel.ts b/packages/core/src/Slides/Domain/SlideModel.tsindex 2cfeb67f9b..8dbb68f9dc 100644--- a/packages/core/src/Slides/Domain/SlideModel.ts+++ b/packages/core/src/Slides/Domain/SlideModel.ts@@ -1,6 +1,6 @@import { SlideContext } from '../../Basics/SlideContext';-import { DEFAULT_SLIDE } from '../../Const';-import { ISlideData, ISlidePage, PageType } from '../../Interfaces';+import { DEFAULT_SLIDE } from '../../Types/Const';+import { ISlideData, ISlidePage, PageType } from '../../Types/Interfaces';import { Tools } from '../../Shared';export class SlideModel {diff --git a/packages/core/src/Const/ACTION_NAMES.ts b/packages/core/src/Types/Const/ACTION_NAMES.tssimilarity index 100%rename from packages/core/src/Const/ACTION_NAMES.tsrename to packages/core/src/Types/Const/ACTION_NAMES.tsdiff --git a/packages/core/src/Const/CONST.ts b/packages/core/src/Types/Const/CONST.tssimilarity index 94%rename from packages/core/src/Const/CONST.tsrename to packages/core/src/Types/Const/CONST.tsindex 339cbbcac4..feb7af0651 100644--- a/packages/core/src/Const/CONST.ts+++ b/packages/core/src/Types/Const/CONST.ts@@ -1,220 +1,220 @@-import {- BooleanNumber,- HorizontalAlign,- LocaleType,- SheetTypes,- TextDirection,- VerticalAlign,- WrapStrategy,-} from '../Enum';-import { IStyleData, IWorkbookConfig, IWorksheetConfig } from '../Interfaces';--/**- * Used as an illegal range array return value- */-export const DEFAULT_RANGE_ARRAY = {- sheetId: '',- rangeData: {- startRow: -1,- endRow: -1,- startColumn: -1,- endColumn: -1,- },-};--/**- * Used as an illegal range return value- */-export const DEFAULT_RANGE = {- startRow: -1,- startColumn: -1,- endRow: -1,- endColumn: -1,-};--/**- * Used as an init selection return value- */-export const DEFAULT_SELECTION = {- startRow: 0,- startColumn: 0,- endRow: 0,- endColumn: 0,-};-/**- * Used as an init cell return value- */-export const DEFAULT_CELL = {- row: 0,- column: 0,-};--/**- * Used as an init workbook return value- */-export const DEFAULT_WORKBOOK: IWorkbookConfig = {- extensions: [],- id: '',- sheetOrder: [],- socketEnable: BooleanNumber.FALSE,- socketUrl: '',- name: '',- timeZone: '',- appVersion: '',- theme: '',- skin: '',- locale: LocaleType.EN,- creator: '',- styles: {},- sheets: {},- lastModifiedBy: '',- createdTime: '',- modifiedTime: '',- pluginMeta: {},- namedRanges: [],-};--/**- * Used as an init worksheet return value- */-export const DEFAULT_WORKSHEET: IWorksheetConfig = {- type: SheetTypes.GRID,- name: 'Sheet1',- id: 'sheet-01',- tabColor: '',- hidden: BooleanNumber.FALSE,- freezeColumn: -1,- rowCount: 1000,- columnCount: 100,- freezeRow: -1,- zoomRatio: 1,- scrollTop: 0,- scrollLeft: 0,- defaultColumnWidth: 73,- defaultRowHeight: 19,- mergeData: [],- hideRow: [],- hideColumn: [],- cellData: {},- rowData: {},- columnData: {},- status: BooleanNumber.FALSE,- showGridlines: BooleanNumber.TRUE,- rowTitle: {- width: 46,- hidden: BooleanNumber.FALSE,- },- columnTitle: {- height: 20,- hidden: BooleanNumber.FALSE,- },- selections: ['A1'],- rightToLeft: BooleanNumber.FALSE,- pluginMeta: {},-};--/**- * Default styles- */-export const DEFAULT_STYLES: IStyleData = {- /**- * fontFamily- */- ff: 'Times New Roman',- /**- * fontSize- */- fs: 14,- /**- * italic- * 0: false- * 1: true- */- it: BooleanNumber.FALSE,- /**- * bold- * 0: false- * 1: true- */- bl: BooleanNumber.FALSE,- /**- * underline- */- ul: {- s: BooleanNumber.FALSE,- },- /**- * strikethrough- */- st: {- s: BooleanNumber.FALSE,- },- /**- * overline- */- ol: {- s: BooleanNumber.FALSE,- },- /**- * textRotation- */- tr: {- a: 0,- /**- * true : 1- * false : 0- */- v: BooleanNumber.FALSE,- },- /** *- * textDirection- */- td: TextDirection.UNSPECIFIED,- /**- * color- */- cl: {- rgb: '#000',- },- /**- * background- */- bg: {- rgb: '#fff',- },- /**- * horizontalAlignment- */- ht: HorizontalAlign.UNSPECIFIED,- /**- * verticalAlignment- */- vt: VerticalAlign.UNSPECIFIED,- /**- * wrapStrategy- */- tb: WrapStrategy.UNSPECIFIED,- /**- * padding- */- pd: {- t: 0,- r: 0,- b: 0,- l: 0,- },-};--export const DEFAULT_DOC = {- id: 'default_doc',- documentStyle: {},-};--export const DEFAULT_SLIDE = {- id: 'default_slide',- title: 'defaultSlide',- pageSize: {- width: 300,- height: 300,- },-};+import {+ BooleanNumber,+ HorizontalAlign,+ LocaleType,+ SheetTypes,+ TextDirection,+ VerticalAlign,+ WrapStrategy,+} from '../Enum';+import { IStyleData, IWorkbookConfig, IWorksheetConfig } from '../Interfaces';++/**+ * Used as an illegal range array return value+ */+export const DEFAULT_RANGE_ARRAY = {+ sheetId: '',+ rangeData: {+ startRow: -1,+ endRow: -1,+ startColumn: -1,+ endColumn: -1,+ },+};++/**+ * Used as an illegal range return value+ */+export const DEFAULT_RANGE = {+ startRow: -1,+ startColumn: -1,+ endRow: -1,+ endColumn: -1,+};++/**+ * Used as an init selection return value+ */+export const DEFAULT_SELECTION = {+ startRow: 0,+ startColumn: 0,+ endRow: 0,+ endColumn: 0,+};+/**+ * Used as an init cell return value+ */+export const DEFAULT_CELL = {+ row: 0,+ column: 0,+};++/**+ * Used as an init workbook return value+ */+export const DEFAULT_WORKBOOK: IWorkbookConfig = {+ extensions: [],+ id: '',+ sheetOrder: [],+ socketEnable: BooleanNumber.FALSE,+ socketUrl: '',+ name: '',+ timeZone: '',+ appVersion: '',+ theme: '',+ skin: '',+ locale: LocaleType.EN,+ creator: '',+ styles: {},+ sheets: {},+ lastModifiedBy: '',+ createdTime: '',+ modifiedTime: '',+ pluginMeta: {},+ namedRanges: [],+};++/**+ * Used as an init worksheet return value+ */+export const DEFAULT_WORKSHEET: IWorksheetConfig = {+ type: SheetTypes.GRID,+ name: 'Sheet1',+ id: 'sheet-01',+ tabColor: '',+ hidden: BooleanNumber.FALSE,+ freezeColumn: -1,+ rowCount: 1000,+ columnCount: 100,+ freezeRow: -1,+ zoomRatio: 1,+ scrollTop: 0,+ scrollLeft: 0,+ defaultColumnWidth: 73,+ defaultRowHeight: 19,+ mergeData: [],+ hideRow: [],+ hideColumn: [],+ cellData: {},+ rowData: {},+ columnData: {},+ status: BooleanNumber.FALSE,+ showGridlines: BooleanNumber.TRUE,+ rowTitle: {+ width: 46,+ hidden: BooleanNumber.FALSE,+ },+ columnTitle: {+ height: 20,+ hidden: BooleanNumber.FALSE,+ },+ selections: ['A1'],+ rightToLeft: BooleanNumber.FALSE,+ pluginMeta: {},+};++/**+ * Default styles+ */+export const DEFAULT_STYLES: IStyleData = {+ /**+ * fontFamily+ */+ ff: 'Times New Roman',+ /**+ * fontSize+ */+ fs: 14,+ /**+ * italic+ * 0: false+ * 1: true+ */+ it: BooleanNumber.FALSE,+ /**+ * bold+ * 0: false+ * 1: true+ */+ bl: BooleanNumber.FALSE,+ /**+ * underline+ */+ ul: {+ s: BooleanNumber.FALSE,+ },+ /**+ * strikethrough+ */+ st: {+ s: BooleanNumber.FALSE,+ },+ /**+ * overline+ */+ ol: {+ s: BooleanNumber.FALSE,+ },+ /**+ * textRotation+ */+ tr: {+ a: 0,+ /**+ * true : 1+ * false : 0+ */+ v: BooleanNumber.FALSE,+ },+ /** *+ * textDirection+ */+ td: TextDirection.UNSPECIFIED,+ /**+ * color+ */+ cl: {+ rgb: '#000',+ },+ /**+ * background+ */+ bg: {+ rgb: '#fff',+ },+ /**+ * horizontalAlignment+ */+ ht: HorizontalAlign.UNSPECIFIED,+ /**+ * verticalAlignment+ */+ vt: VerticalAlign.UNSPECIFIED,+ /**+ * wrapStrategy+ */+ tb: WrapStrategy.UNSPECIFIED,+ /**+ * padding+ */+ pd: {+ t: 0,+ r: 0,+ b: 0,+ l: 0,+ },+};++export const DEFAULT_DOC = {+ id: 'default_doc',+ documentStyle: {},+};++export const DEFAULT_SLIDE = {+ id: 'default_slide',+ title: 'defaultSlide',+ pageSize: {+ width: 300,+ height: 300,+ },+};diff --git a/packages/core/src/Const/DOC_ACTION_NAMES.ts b/packages/core/src/Types/Const/DOC_ACTION_NAMES.tssimilarity index 100%rename from packages/core/src/Const/DOC_ACTION_NAMES.tsrename to packages/core/src/Types/Const/DOC_ACTION_NAMES.tsdiff --git a/packages/core/src/Const/EXTENSION_NAMES.ts b/packages/core/src/Types/Const/EXTENSION_NAMES.tssimilarity index 100%rename from packages/core/src/Const/EXTENSION_NAMES.tsrename to packages/core/src/Types/Const/EXTENSION_NAMES.tsdiff --git a/packages/core/src/Const/KEYBOARD_KEYS.ts b/packages/core/src/Types/Const/KEYBOARD_KEYS.tssimilarity index 100%rename from packages/core/src/Const/KEYBOARD_KEYS.tsrename to packages/core/src/Types/Const/KEYBOARD_KEYS.tsdiff --git a/packages/core/src/Const/PLUGIN_NAMES.ts b/packages/core/src/Types/Const/PLUGIN_NAMES.tssimilarity index 100%rename from packages/core/src/Const/PLUGIN_NAMES.tsrename to packages/core/src/Types/Const/PLUGIN_NAMES.tsdiff --git a/packages/core/src/Const/THEME_COLOR_MAP.ts b/packages/core/src/Types/Const/THEME_COLOR_MAP.tssimilarity index 100%rename from packages/core/src/Const/THEME_COLOR_MAP.tsrename to packages/core/src/Types/Const/THEME_COLOR_MAP.tsdiff --git a/packages/core/src/Const/index.ts b/packages/core/src/Types/Const/index.tssimilarity index 100%rename from packages/core/src/Const/index.tsrename to packages/core/src/Types/Const/index.tsdiff --git a/packages/core/src/Enum/AutoFillSeries.ts b/packages/core/src/Types/Enum/AutoFillSeries.tssimilarity index 100%rename from packages/core/src/Enum/AutoFillSeries.tsrename to packages/core/src/Types/Enum/AutoFillSeries.tsdiff --git a/packages/core/src/Enum/BooleanCriteria.ts b/packages/core/src/Types/Enum/BooleanCriteria.tssimilarity index 100%rename from packages/core/src/Enum/BooleanCriteria.tsrename to packages/core/src/Types/Enum/BooleanCriteria.tsdiff --git a/packages/core/src/Enum/BorderStyleTypes.ts b/packages/core/src/Types/Enum/BorderStyleTypes.tssimilarity index 100%rename from packages/core/src/Enum/BorderStyleTypes.tsrename to packages/core/src/Types/Enum/BorderStyleTypes.tsdiff --git a/packages/core/src/Enum/ColorType.ts b/packages/core/src/Types/Enum/ColorType.tssimilarity index 100%rename from packages/core/src/Enum/ColorType.tsrename to packages/core/src/Types/Enum/ColorType.tsdiff --git a/packages/core/src/Enum/CommonHideTypes.ts b/packages/core/src/Types/Enum/CommonHideTypes.tssimilarity index 100%rename from packages/core/src/Enum/CommonHideTypes.tsrename to packages/core/src/Types/Enum/CommonHideTypes.tsdiff --git a/packages/core/src/Enum/ConditionType.ts b/packages/core/src/Types/Enum/ConditionType.tssimilarity index 100%rename from packages/core/src/Enum/ConditionType.tsrename to packages/core/src/Types/Enum/ConditionType.tsdiff --git a/packages/core/src/Enum/CopyPasteType.ts b/packages/core/src/Types/Enum/CopyPasteType.tssimilarity index 100%rename from packages/core/src/Enum/CopyPasteType.tsrename to packages/core/src/Types/Enum/CopyPasteType.tsdiff --git a/packages/core/src/Enum/DeveloperMetadataVisibility.ts b/packages/core/src/Types/Enum/DeveloperMetadataVisibility.tssimilarity index 100%rename from packages/core/src/Enum/DeveloperMetadataVisibility.tsrename to packages/core/src/Types/Enum/DeveloperMetadataVisibility.tsdiff --git a/packages/core/src/Enum/Dimension.ts b/packages/core/src/Types/Enum/Dimension.tssimilarity index 100%rename from packages/core/src/Enum/Dimension.tsrename to packages/core/src/Types/Enum/Dimension.tsdiff --git a/packages/core/src/Enum/Direction.ts b/packages/core/src/Types/Enum/Direction.tssimilarity index 100%rename from packages/core/src/Enum/Direction.tsrename to packages/core/src/Types/Enum/Direction.tsdiff --git a/packages/core/src/Enum/FormatType.ts b/packages/core/src/Types/Enum/FormatType.tssimilarity index 100%rename from packages/core/src/Enum/FormatType.tsrename to packages/core/src/Types/Enum/FormatType.tsdiff --git a/packages/core/src/Enum/GroupControlTogglePosition.ts b/packages/core/src/Types/Enum/GroupControlTogglePosition.tssimilarity index 100%rename from packages/core/src/Enum/GroupControlTogglePosition.tsrename to packages/core/src/Types/Enum/GroupControlTogglePosition.tsdiff --git a/packages/core/src/Enum/InterpolationPointType.ts b/packages/core/src/Types/Enum/InterpolationPointType.tssimilarity index 100%rename from packages/core/src/Enum/InterpolationPointType.tsrename to packages/core/src/Types/Enum/InterpolationPointType.tsdiff --git a/packages/core/src/Enum/KeyCode.ts b/packages/core/src/Types/Enum/KeyCode.tssimilarity index 100%rename from packages/core/src/Enum/KeyCode.tsrename to packages/core/src/Types/Enum/KeyCode.tsdiff --git a/packages/core/src/Enum/LocaleType.ts b/packages/core/src/Types/Enum/LocaleType.tssimilarity index 100%rename from packages/core/src/Enum/LocaleType.tsrename to packages/core/src/Types/Enum/LocaleType.tsdiff --git a/packages/core/src/Enum/PlaceHolderType.ts b/packages/core/src/Types/Enum/PlaceHolderType.tssimilarity index 100%rename from packages/core/src/Enum/PlaceHolderType.tsrename to packages/core/src/Types/Enum/PlaceHolderType.tsdiff --git a/packages/core/src/Enum/ProtectionType.ts b/packages/core/src/Types/Enum/ProtectionType.tssimilarity index 100%rename from packages/core/src/Enum/ProtectionType.tsrename to packages/core/src/Types/Enum/ProtectionType.tsdiff --git a/packages/core/src/Enum/RelativeDate.ts b/packages/core/src/Types/Enum/RelativeDate.tssimilarity index 100%rename from packages/core/src/Enum/RelativeDate.tsrename to packages/core/src/Types/Enum/RelativeDate.tsdiff --git a/packages/core/src/Enum/ShapeType.ts b/packages/core/src/Types/Enum/ShapeType.tssimilarity index 100%rename from packages/core/src/Enum/ShapeType.tsrename to packages/core/src/Types/Enum/ShapeType.tsdiff --git a/packages/core/src/Enum/SheetTypes.ts b/packages/core/src/Types/Enum/SheetTypes.tssimilarity index 100%rename from packages/core/src/Enum/SheetTypes.tsrename to packages/core/src/Types/Enum/SheetTypes.tsdiff --git a/packages/core/src/Enum/TextStyle.ts b/packages/core/src/Types/Enum/TextStyle.tssimilarity index 100%rename from packages/core/src/Enum/TextStyle.tsrename to packages/core/src/Types/Enum/TextStyle.tsdiff --git a/packages/core/src/Enum/ThemeColorType.ts b/packages/core/src/Types/Enum/ThemeColorType.tssimilarity index 100%rename from packages/core/src/Enum/ThemeColorType.tsrename to packages/core/src/Types/Enum/ThemeColorType.tsdiff --git a/packages/core/src/Enum/index.ts b/packages/core/src/Types/Enum/index.tssimilarity index 100%rename from packages/core/src/Enum/index.tsrename to packages/core/src/Types/Enum/index.tsdiff --git a/packages/core/src/Interfaces/ICellData.ts b/packages/core/src/Types/Interfaces/ICellData.tssimilarity index 95%rename from packages/core/src/Interfaces/ICellData.tsrename to packages/core/src/Types/Interfaces/ICellData.tsindex 1f2c0eb00a..83b4bb668e 100644--- a/packages/core/src/Interfaces/ICellData.ts+++ b/packages/core/src/Types/Interfaces/ICellData.ts@@ -1,7 +1,7 @@-import { IDocumentData } from '.';+import { IDocumentData } from './index';import { FormatType } from '../Enum/FormatType';import { CellValueType } from '../Enum/TextStyle';-import { Nullable } from '../Shared/Types';+import { Nullable } from '../../Shared/Types';import { IStyleData } from './IStyleData';/**@@ -40,7 +40,7 @@ export interface ICellData {* 3. rangeId* 4. range* 5. email- *+ ** u: "Formula!A1" // urlm: "" // messaget: "link" // typediff --git a/packages/core/src/Interfaces/IColumnData.ts b/packages/core/src/Types/Interfaces/IColumnData.tssimilarity index 100%rename from packages/core/src/Interfaces/IColumnData.tsrename to packages/core/src/Types/Interfaces/IColumnData.tsdiff --git a/packages/core/src/Interfaces/IDocumentData.ts b/packages/core/src/Types/Interfaces/IDocumentData.tssimilarity index 100%rename from packages/core/src/Interfaces/IDocumentData.tsrename to packages/core/src/Types/Interfaces/IDocumentData.tsdiff --git a/packages/core/src/Interfaces/IImageProperties.ts b/packages/core/src/Types/Interfaces/IImageProperties.tssimilarity index 100%rename from packages/core/src/Interfaces/IImageProperties.tsrename to packages/core/src/Types/Interfaces/IImageProperties.tsdiff --git a/packages/core/src/Interfaces/INamedRange.ts b/packages/core/src/Types/Interfaces/INamedRange.tssimilarity index 100%rename from packages/core/src/Interfaces/INamedRange.tsrename to packages/core/src/Types/Interfaces/INamedRange.tsdiff --git a/packages/core/src/Interfaces/IObserveData.ts b/packages/core/src/Types/Interfaces/IObserveData.tssimilarity index 59%rename from packages/core/src/Interfaces/IObserveData.tsrename to packages/core/src/Types/Interfaces/IObserveData.tsindex fa62b27238..52a0e9312e 100644--- a/packages/core/src/Interfaces/IObserveData.ts+++ b/packages/core/src/Types/Interfaces/IObserveData.ts@@ -1,5 +1,5 @@-import { Worksheet } from '../Sheets/Domain';-import { Observable } from '../Observer';+import { Worksheet } from '../../Sheets/Domain';+import { Observable } from '../../Observer';/*** Worksheet Observable Datadiff --git a/packages/core/src/Interfaces/IPlaceholder.ts b/packages/core/src/Types/Interfaces/IPlaceholder.tssimilarity index 100%rename from packages/core/src/Interfaces/IPlaceholder.tsrename to packages/core/src/Types/Interfaces/IPlaceholder.tsdiff --git a/packages/core/src/Interfaces/IRangeData.ts b/packages/core/src/Types/Interfaces/IRangeData.tssimilarity index 100%rename from packages/core/src/Interfaces/IRangeData.tsrename to packages/core/src/Types/Interfaces/IRangeData.tsdiff --git a/packages/core/src/Interfaces/IRowData.ts b/packages/core/src/Types/Interfaces/IRowData.tssimilarity index 100%rename from packages/core/src/Interfaces/IRowData.tsrename to packages/core/src/Types/Interfaces/IRowData.tsdiff --git a/packages/core/src/Interfaces/ISelectionData.ts b/packages/core/src/Types/Interfaces/ISelectionData.tssimilarity index 96%rename from packages/core/src/Interfaces/ISelectionData.tsrename to packages/core/src/Types/Interfaces/ISelectionData.tsindex 756ec07015..b052011632 100644--- a/packages/core/src/Interfaces/ISelectionData.ts+++ b/packages/core/src/Types/Interfaces/ISelectionData.ts@@ -1,4 +1,4 @@-import { Range } from '../Sheets/Domain';+import { Range } from '../../Sheets/Domain';import { IRangeData, IRangeType } from './IRangeData';/**diff --git a/packages/core/src/Interfaces/IServiceData.ts b/packages/core/src/Types/Interfaces/IServiceData.tssimilarity index 100%rename from packages/core/src/Interfaces/IServiceData.tsrename to packages/core/src/Types/Interfaces/IServiceData.tsdiff --git a/packages/core/src/Interfaces/IShapeProperties.ts b/packages/core/src/Types/Interfaces/IShapeProperties.tssimilarity index 100%rename from packages/core/src/Interfaces/IShapeProperties.tsrename to packages/core/src/Types/Interfaces/IShapeProperties.tsdiff --git a/packages/core/src/Interfaces/ISlideData.ts b/packages/core/src/Types/Interfaces/ISlideData.tssimilarity index 94%rename from packages/core/src/Interfaces/ISlideData.tsrename to packages/core/src/Types/Interfaces/ISlideData.tsindex 3f9afffcc3..c04588b073 100644--- a/packages/core/src/Interfaces/ISlideData.ts+++ b/packages/core/src/Types/Interfaces/ISlideData.ts@@ -1,184 +1,184 @@-import { LocaleType, ThemeColorType } from '../Enum';-import { ShapeType } from '../Enum/ShapeType';-import { IKeyType, Nullable } from '../Shared/Types';-import { ICustomBlock, IDocumentData, ILists, ISizeData } from './IDocumentData';-import { IImageProperties } from './IImageProperties';-import { IPlaceholder } from './IPlaceholder';-import { IShapeProperties } from './IShapeProperties';-import { IColorStyle, IStyleBase, IStyleData } from './IStyleData';-import { IWorksheetConfig } from './IWorksheetData';--export interface ISize {- width?: number;- height?: number;-}--export interface IScale {- scaleX?: number;- scaleY?: number;-}--export interface IOffset {- left?: number;- top?: number;-}--export interface ITransformState extends IOffset, ISize, IScale {- angle?: number;- skewX?: number;- skewY?: number;- flipX?: boolean;- flipY?: boolean;-}--export interface ISlideData extends IReferenceSource {- id: string; // unit id- locale?: LocaleType;- title: string;- pageSize: ISizeData;- body?: ISlidePageBody;-}--interface IReferenceSource {- master?: { [id: string]: ISlidePage };- handoutMaster?: { [id: string]: ISlidePage };- notesMaster?: { [id: string]: ISlidePage };- layouts?: { [id: string]: ISlidePage };- lists?: ILists;-}--interface ISlidePageBody {- pages: { [id: string]: ISlidePage };- pageOrder: string[];-}--export interface ISlidePage {- id: string;- pageType: PageType;- zIndex: number;- title: string;- description: string;- pageBackgroundFill: IColorStyle;- colorScheme?: ThemeColorType;- pageElements: { [elementId: string]: IPageElement };- // Union field properties. Properties that are specific for each page type. Masters do not require any additional properties. properties can be only one of the following:- slideProperties?: ISlideProperties;- layoutProperties?: ILayoutProperties;- notesProperties?: INotesProperties;- handoutProperties?: IHandoutProperties;- masterProperties?: IMasterProperties;-}--interface ISlideProperties {- layoutObjectId: string;- masterObjectId: string;- isSkipped: boolean;-}--interface ILayoutProperties {- masterObjectId: string;- name: string;-}--interface INotesProperties {- name: string;-}--interface IHandoutProperties {- name: string;-}--interface IMasterProperties {- name: string;-}--export interface IRichTextProps extends ITransformState, IStyleBase {- text?: string;- rich?: IDocumentData;-}--export interface IPageElement {- id: string;- zIndex: number;- left?: number;- top?: number;- width?: number;- height?: number;- angle?: number;- scaleX?: number;- scaleY?: number;- skewX?: number;- skewY?: number;- flipX?: boolean;- flipY?: boolean;-- title: string;- description: string;-- type: PageElementType;-- // Union field element_kind can be only one of the following:- // elementGroup: IGroup;- shape?: IShape;- image?: IImage;- richText?: IRichTextProps;- spreadsheet?: {- worksheet: IWorksheetConfig;- styles: IKeyType<Nullable<IStyleData>>;- };- document?: IDocumentData;- slide?: ISlideData;- // video: IVideo;- // line: ILine;- // table: ITable;- // chart: IChartProperties;- customBlock?: ICustomBlock; // customBlock 用户通过插件自定义的block-}--export enum PageType {- SLIDE, // A slide page.- MASTER, // A master slide page.- LAYOUT, // A layout page.- HANDOUT_MASTER, // A handout master page.- NOTES_MASTER, // A notes master page.-}--export enum PageElementType {- SHAPE,- IMAGE,- TEXT,- SPREADSHEET,- DOCUMENT,- SLIDE,-}--/**- * IShape- */-export interface IShape {- shapeType: ShapeType;- text: string;- shapeProperties: IShapeProperties;- placeholder?: IPlaceholder;- link?: ILink;-}--export interface IImage {- imageProperties?: IImageProperties;- placeholder?: IPlaceholder;- link?: ILink;-}--interface ILink {- relativeLink: RelativeSlideLink;- pageId?: string;- slideIndex?: number;-}--export enum RelativeSlideLink {- RELATIVE_SLIDE_LINK_UNSPECIFIED, // An unspecified relative slide link.- NEXT_SLIDE, // A link to the next slide.- PREVIOUS_SLIDE, // A link to the previous slide.- FIRST_SLIDE, // A link to the first slide in the presentation.- LAST_SLIDE, // A link to the last slide in the presentation.-}+import { LocaleType, ThemeColorType } from '../Enum';+import { ShapeType } from '../Enum/ShapeType';+import { IKeyType, Nullable } from '../../Shared/Types';+import { ICustomBlock, IDocumentData, ILists, ISizeData } from './IDocumentData';+import { IImageProperties } from './IImageProperties';+import { IPlaceholder } from './IPlaceholder';+import { IShapeProperties } from './IShapeProperties';+import { IColorStyle, IStyleBase, IStyleData } from './IStyleData';+import { IWorksheetConfig } from './IWorksheetData';++export interface ISize {+ width?: number;+ height?: number;+}++export interface IScale {+ scaleX?: number;+ scaleY?: number;+}++export interface IOffset {+ left?: number;+ top?: number;+}++export interface ITransformState extends IOffset, ISize, IScale {+ angle?: number;+ skewX?: number;+ skewY?: number;+ flipX?: boolean;+ flipY?: boolean;+}++export interface ISlideData extends IReferenceSource {+ id: string; // unit id+ locale?: LocaleType;+ title: string;+ pageSize: ISizeData;+ body?: ISlidePageBody;+}++interface IReferenceSource {+ master?: { [id: string]: ISlidePage };+ handoutMaster?: { [id: string]: ISlidePage };+ notesMaster?: { [id: string]: ISlidePage };+ layouts?: { [id: string]: ISlidePage };+ lists?: ILists;+}++interface ISlidePageBody {+ pages: { [id: string]: ISlidePage };+ pageOrder: string[];+}++export interface ISlidePage {+ id: string;+ pageType: PageType;+ zIndex: number;+ title: string;+ description: string;+ pageBackgroundFill: IColorStyle;+ colorScheme?: ThemeColorType;+ pageElements: { [elementId: string]: IPageElement };+ // Union field properties. Properties that are specific for each page type. Masters do not require any additional properties. properties can be only one of the following:+ slideProperties?: ISlideProperties;+ layoutProperties?: ILayoutProperties;+ notesProperties?: INotesProperties;+ handoutProperties?: IHandoutProperties;+ masterProperties?: IMasterProperties;+}++interface ISlideProperties {+ layoutObjectId: string;+ masterObjectId: string;+ isSkipped: boolean;+}++interface ILayoutProperties {+ masterObjectId: string;+ name: string;+}++interface INotesProperties {+ name: string;+}++interface IHandoutProperties {+ name: string;+}++interface IMasterProperties {+ name: string;+}++export interface IRichTextProps extends ITransformState, IStyleBase {+ text?: string;+ rich?: IDocumentData;+}++export interface IPageElement {+ id: string;+ zIndex: number;+ left?: number;+ top?: number;+ width?: number;+ height?: number;+ angle?: number;+ scaleX?: number;+ scaleY?: number;+ skewX?: number;+ skewY?: number;+ flipX?: boolean;+ flipY?: boolean;++ title: string;+ description: string;++ type: PageElementType;++ // Union field element_kind can be only one of the following:+ // elementGroup: IGroup;+ shape?: IShape;+ image?: IImage;+ richText?: IRichTextProps;+ spreadsheet?: {+ worksheet: IWorksheetConfig;+ styles: IKeyType<Nullable<IStyleData>>;+ };+ document?: IDocumentData;+ slide?: ISlideData;+ // video: IVideo;+ // line: ILine;+ // table: ITable;+ // chart: IChartProperties;+ customBlock?: ICustomBlock; // customBlock 用户通过插件自定义的block+}++export enum PageType {+ SLIDE, // A slide page.+ MASTER, // A master slide page.+ LAYOUT, // A layout page.+ HANDOUT_MASTER, // A handout master page.+ NOTES_MASTER, // A notes master page.+}++export enum PageElementType {+ SHAPE,+ IMAGE,+ TEXT,+ SPREADSHEET,+ DOCUMENT,+ SLIDE,+}++/**+ * IShape+ */+export interface IShape {+ shapeType: ShapeType;+ text: string;+ shapeProperties: IShapeProperties;+ placeholder?: IPlaceholder;+ link?: ILink;+}++export interface IImage {+ imageProperties?: IImageProperties;+ placeholder?: IPlaceholder;+ link?: ILink;+}++interface ILink {+ relativeLink: RelativeSlideLink;+ pageId?: string;+ slideIndex?: number;+}++export enum RelativeSlideLink {+ RELATIVE_SLIDE_LINK_UNSPECIFIED, // An unspecified relative slide link.+ NEXT_SLIDE, // A link to the next slide.+ PREVIOUS_SLIDE, // A link to the previous slide.+ FIRST_SLIDE, // A link to the first slide in the presentation.+ LAST_SLIDE, // A link to the last slide in the presentation.+}diff --git a/packages/core/src/Interfaces/IStyleData.ts b/packages/core/src/Types/Interfaces/IStyleData.tssimilarity index 92%rename from packages/core/src/Interfaces/IStyleData.tsrename to packages/core/src/Types/Interfaces/IStyleData.tsindex ed7bd874e8..c28c9069c0 100644--- a/packages/core/src/Interfaces/IStyleData.ts+++ b/packages/core/src/Types/Interfaces/IStyleData.ts@@ -1,186 +1,186 @@-import { BorderStyleTypes } from '../Enum/BorderStyleTypes';-import {- BooleanNumber,- HorizontalAlign,- TextDecoration,- TextDirection,- BaselineOffset,- VerticalAlign,- WrapStrategy,-} from '../Enum/TextStyle';-import { ThemeColorType } from '../Enum/ThemeColorType';-import { Nullable } from '../Shared/Types';--/**- * Properties of text decoration- */-export interface ITextDecoration {- s: BooleanNumber; // show- cl?: IColorStyle; // color- t?: TextDecoration; // lineType-}--/**- * RGB color or theme color- */-export interface IColorStyle {- // rgb?: Nullable<IColor | string>;- rgb?: Nullable<string>;- th?: ThemeColorType;-}--/**- * Format of RBGA color- */-export interface IColor {- r: number; // Red- g: number; // Green- b: number; // Blue- a?: number; // Alpha-}--/**- * Style properties of border- */-export interface IBorderStyleData {- s: BorderStyleTypes;- cl: IColorStyle;-}--/**- * Style properties of top, bottom, left and right border- */-export interface IBorderData {- t?: Nullable<IBorderStyleData>;- r?: Nullable<IBorderStyleData>;- b?: Nullable<IBorderStyleData>;- l?: Nullable<IBorderStyleData>;-}--// export interface IFormatData {-// /**-// * format-// */-// f: string;-// /**-// * 数字 n-// * 字符串 g-// * 时间 d-// * 富文本 r-// */-// t: string;-// }--export interface ITextRotation {- /**- * angle- */- a: number;- /**- * vertical- * true : 1- * false : 0- */- v?: BooleanNumber;-}--/**- * Top,right,bottom,left padding- */-export interface IPaddingData {- t?: number;- r?: number;- b?: number;- l?: number;-}--/**- * Basics properties of cell style- */-export interface IStyleBase {- /**- * fontFamily- */- ff?: Nullable<string>;- /**- * fontSize- *- * pt- */- fs?: number;- /**- * italic- * 0: false- * 1: true- */- it?: BooleanNumber;- /**- * bold- * 0: false- * 1: true- */- bl?: BooleanNumber;-- /**- * underline- */- ul?: ITextDecoration;- /**- * strikethrough- */- st?: ITextDecoration;- /**- * overline- */- ol?: ITextDecoration;-- /**- * background- */- bg?: IColorStyle;-- /**- * border- */- bd?: IBorderData;-- /**- * foreground- */- cl?: IColorStyle;-- /**- * (Subscript 下标 /Superscript上标 Text)- */- va?: BaselineOffset;-}--/**- * Properties of cell style- */-export interface IStyleData extends IStyleBase {- /**- * textRotation- */- tr?: Nullable<ITextRotation>;- /** *- * textDirection- */- td?: Nullable<TextDirection>;- /**- * horizontalAlignment- */- ht?: Nullable<HorizontalAlign>;- /**- * verticalAlignment- */- vt?: Nullable<VerticalAlign>;- /**- * wrapStrategy- */- tb?: Nullable<WrapStrategy>;- /**- * padding- */- pd?: Nullable<IPaddingData>;-}+import { BorderStyleTypes } from '../Enum/BorderStyleTypes';+import {+ BooleanNumber,+ HorizontalAlign,+ TextDecoration,+ TextDirection,+ BaselineOffset,+ VerticalAlign,+ WrapStrategy,+} from '../Enum/TextStyle';+import { ThemeColorType } from '../Enum/ThemeColorType';+import { Nullable } from '../../Shared/Types';++/**+ * Properties of text decoration+ */+export interface ITextDecoration {+ s: BooleanNumber; // show+ cl?: IColorStyle; // color+ t?: TextDecoration; // lineType+}++/**+ * RGB color or theme color+ */+export interface IColorStyle {+ // rgb?: Nullable<IColor | string>;+ rgb?: Nullable<string>;+ th?: ThemeColorType;+}++/**+ * Format of RBGA color+ */+export interface IColor {+ r: number; // Red+ g: number; // Green+ b: number; // Blue+ a?: number; // Alpha+}++/**+ * Style properties of border+ */+export interface IBorderStyleData {+ s: BorderStyleTypes;+ cl: IColorStyle;+}++/**+ * Style properties of top, bottom, left and right border+ */+export interface IBorderData {+ t?: Nullable<IBorderStyleData>;+ r?: Nullable<IBorderStyleData>;+ b?: Nullable<IBorderStyleData>;+ l?: Nullable<IBorderStyleData>;+}++// export interface IFormatData {+// /**+// * format+// */+// f: string;+// /**+// * 数字 n+// * 字符串 g+// * 时间 d+// * 富文本 r+// */+// t: string;+// }++export interface ITextRotation {+ /**+ * angle+ */+ a: number;+ /**+ * vertical+ * true : 1+ * false : 0+ */+ v?: BooleanNumber;+}++/**+ * Top,right,bottom,left padding+ */+export interface IPaddingData {+ t?: number;+ r?: number;+ b?: number;+ l?: number;+}++/**+ * Basics properties of cell style+ */+export interface IStyleBase {+ /**+ * fontFamily+ */+ ff?: Nullable<string>;+ /**+ * fontSize+ *+ * pt+ */+ fs?: number;+ /**+ * italic+ * 0: false+ * 1: true+ */+ it?: BooleanNumber;+ /**+ * bold+ * 0: false+ * 1: true+ */+ bl?: BooleanNumber;++ /**+ * underline+ */+ ul?: ITextDecoration;+ /**+ * strikethrough+ */+ st?: ITextDecoration;+ /**+ * overline+ */+ ol?: ITextDecoration;++ /**+ * background+ */+ bg?: IColorStyle;++ /**+ * border+ */+ bd?: IBorderData;++ /**+ * foreground+ */+ cl?: IColorStyle;++ /**+ * (Subscript 下标 /Superscript上标 Text)+ */+ va?: BaselineOffset;+}++/**+ * Properties of cell style+ */+export interface IStyleData extends IStyleBase {+ /**+ * textRotation+ */+ tr?: Nullable<ITextRotation>;+ /** *+ * textDirection+ */+ td?: Nullable<TextDirection>;+ /**+ * horizontalAlignment+ */+ ht?: Nullable<HorizontalAlign>;+ /**+ * verticalAlignment+ */+ vt?: Nullable<VerticalAlign>;+ /**+ * wrapStrategy+ */+ tb?: Nullable<WrapStrategy>;+ /**+ * padding+ */+ pd?: Nullable<IPaddingData>;+}diff --git a/packages/core/src/Interfaces/IUniverData.ts b/packages/core/src/Types/Interfaces/IUniverData.tssimilarity index 100%rename from packages/core/src/Interfaces/IUniverData.tsrename to packages/core/src/Types/Interfaces/IUniverData.tsdiff --git a/packages/core/src/Interfaces/IWorkbookData.ts b/packages/core/src/Types/Interfaces/IWorkbookData.tssimilarity index 92%rename from packages/core/src/Interfaces/IWorkbookData.tsrename to packages/core/src/Types/Interfaces/IWorkbookData.tsindex 64530cae58..5238742e90 100644--- a/packages/core/src/Interfaces/IWorkbookData.ts+++ b/packages/core/src/Types/Interfaces/IWorkbookData.ts@@ -1,4 +1,4 @@-import { IKeyType, IKeyValue, Nullable } from '../Shared/Types';+import { IKeyType, IKeyValue, Nullable } from '../../Shared/Types';import { BooleanNumber, LocaleType } from '../Enum';import { IStyleData } from './IStyleData';import { IWorksheetConfig } from './IWorksheetData';diff --git a/packages/core/src/Interfaces/IWorksheetData.ts b/packages/core/src/Types/Interfaces/IWorksheetData.tssimilarity index 91%rename from packages/core/src/Interfaces/IWorksheetData.tsrename to packages/core/src/Types/Interfaces/IWorksheetData.tsindex 15d06745c3..51cb5834bb 100644--- a/packages/core/src/Interfaces/IWorksheetData.ts+++ b/packages/core/src/Types/Interfaces/IWorksheetData.ts@@ -1,7 +1,7 @@import { BooleanNumber, SheetTypes } from '../Enum';-import { IKeyValue } from '../Shared';-import { ObjectArrayType } from '../Shared/ObjectArray';-import { ObjectMatrixPrimitiveType } from '../Shared/ObjectMatrix';+import { IKeyValue } from '../../Shared';+import { ObjectArrayType } from '../../Shared/ObjectArray';+import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { ICellData } from './ICellData';import { IColumnData } from './IColumnData';import { IRangeData, IRangeType } from './IRangeData';diff --git a/packages/core/src/Interfaces/IWorksheetOrderData.ts b/packages/core/src/Types/Interfaces/IWorksheetOrderData.tssimilarity index 100%rename from packages/core/src/Interfaces/IWorksheetOrderData.tsrename to packages/core/src/Types/Interfaces/IWorksheetOrderData.tsdiff --git a/packages/core/src/Interfaces/index.ts b/packages/core/src/Types/Interfaces/index.tssimilarity index 100%rename from packages/core/src/Interfaces/index.tsrename to packages/core/src/Types/Interfaces/index.tsdiff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex fc49eee7d7..fc1eb50ae4 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -17,11 +17,11 @@ import './Docs/Action';export * from './Basics';export * from './Command';-export * from './Const';+export * from './Types/Const';export * from './DI';export * from './Docs/Domain';-export * from './Enum';-export * from './Interfaces';+export * from './Types/Enum';+export * from './Types/Interfaces';export * from './Observer';export * from './Plugin';export * from './Server';diff --git a/packages/core/test/Command/RemoveMergeAction.test.ts b/packages/core/test/Command/RemoveMergeAction.test.tsindex 8c82f5a68a..f032c2c6a2 100644--- a/packages/core/test/Command/RemoveMergeAction.test.ts+++ b/packages/core/test/Command/RemoveMergeAction.test.ts@@ -9,7 +9,7 @@ import {RemoveMergeAction,} from '../../src/Command';import { createCoreTestContainer } from '../ContainerStartUp';-import { IRangeData } from '../../src/Interfaces';+import { IRangeData } from '../../src/Types/Interfaces';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Command/SetWorkSheetHideAction.test.ts b/packages/core/test/Command/SetWorkSheetHideAction.test.tsindex 3ce98182b6..aa415ee05a 100644--- a/packages/core/test/Command/SetWorkSheetHideAction.test.ts+++ b/packages/core/test/Command/SetWorkSheetHideAction.test.ts@@ -3,9 +3,9 @@*/import { SheetContext } from '../../src/Basics';import { CommandManager, SetWorkSheetHideAction } from '../../src/Command';-import { ACTION_NAMES } from '../../src/Const';+import { ACTION_NAMES } from '../../src/Types/Const';import { Workbook, Worksheet } from '../../src/Sheets/Domain';-import { BooleanNumber } from '../../src/Enum';+import { BooleanNumber } from '../../src/Types/Enum';import { createCoreTestContainer } from '../ContainerStartUp';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Command/SetWorkSheetNameAction.test.ts b/packages/core/test/Command/SetWorkSheetNameAction.test.tsindex f8f84140de..832087a9a6 100644--- a/packages/core/test/Command/SetWorkSheetNameAction.test.ts+++ b/packages/core/test/Command/SetWorkSheetNameAction.test.ts@@ -5,7 +5,7 @@ import { Workbook, Worksheet } from '../../src/Sheets/Domain';import { SheetContext } from '../../src/Basics';import { createCoreTestContainer } from '../ContainerStartUp';import { CommandManager, SetWorkSheetNameAction } from '../../src/Command';-import { ACTION_NAMES } from '../../src/Const';+import { ACTION_NAMES } from '../../src/Types/Const';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Command/SetWorkSheetStatusAction.test.ts b/packages/core/test/Command/SetWorkSheetStatusAction.test.tsindex bc614c7a99..a7ed675cf5 100644--- a/packages/core/test/Command/SetWorkSheetStatusAction.test.ts+++ b/packages/core/test/Command/SetWorkSheetStatusAction.test.ts@@ -3,7 +3,7 @@*/import { SheetContext } from '../../src/Basics';import { CommandManager, SetWorkSheetStatusAction } from '../../src/Command';-import { ACTION_NAMES } from '../../src/Const';+import { ACTION_NAMES } from '../../src/Types/Const';import { Workbook, Worksheet } from '../../src/Sheets/Domain';import { createCoreTestContainer } from '../ContainerStartUp';diff --git a/packages/core/test/ContainerStartUp.ts b/packages/core/test/ContainerStartUp.tsindex 55c242a5ca..15e6cca704 100644--- a/packages/core/test/ContainerStartUp.ts+++ b/packages/core/test/ContainerStartUp.ts@@ -1,8 +1,8 @@import { SheetContext, Environment } from '../src/Basics';import { CommandManager, UndoManager } from '../src/Command';import { Workbook, Worksheet } from '../src/Sheets/Domain';-import { BooleanNumber } from '../src/Enum';-import { IWorkbookConfig, IWorksheetConfig } from '../src/Interfaces';+import { BooleanNumber } from '../src/Types/Enum';+import { IWorkbookConfig, IWorksheetConfig } from '../src/Types/Interfaces';import { HooksManager } from '../src/Observer/HooksManager';import { ObserverManager } from '../src/Observer/ObserverManager';import { PluginManager } from '../src/Plugin';diff --git a/packages/core/test/Domain/Color.test.ts b/packages/core/test/Domain/Color.test.tsindex 09ba2bb5c3..b6e4fc1955 100644--- a/packages/core/test/Domain/Color.test.ts+++ b/packages/core/test/Domain/Color.test.ts@@ -1,60 +1,60 @@-import { ThemeColorType } from '../../src/Enum';-import { Color, RgbColor, ThemeColor } from '../../src/Sheets/Domain/Color';-import { ColorBuilder } from '../../src/Sheets/Domain/ColorBuilder';--jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));--test('Test Color RgbColor', () => {- const builder = new ColorBuilder();- builder.setRgbColor('rgb(0,10,100)');- const rgb = builder.build() as RgbColor;- expect(rgb.getRed()).toEqual(0);- expect(rgb.getGreen()).toEqual(10);- expect(rgb.getBlue()).toEqual(100);- expect(rgb.getAlpha()).toEqual(1);-- const hex = Color.rgbColorToHexValue(rgb);- const hRgb = Color.hexValueToRgbColor(hex);- console.log(hex);- console.log(hRgb);-- builder.setRgbColor('rgba(0,10,100, 0.2)');- const rgba = builder.build() as RgbColor;- expect(rgba.getRed()).toEqual(0);- expect(rgba.getGreen()).toEqual(10);- expect(rgba.getBlue()).toEqual(100);- expect(rgba.getAlpha()).toEqual(0.2);-});--test('Test Color themeColor Office', () => {- const builder = new ColorBuilder();- builder.setThemeColor(ThemeColorType.ACCENT1);- const color = builder.build() as ThemeColor;- const rgba = color.asRgbColor();- expect(rgba.getRed()).toEqual(68);- expect(rgba.getGreen()).toEqual(114);- expect(rgba.getBlue()).toEqual(196);- expect(rgba.getAlpha()).toEqual(1);-});--test('Test Color themeColor', () => {- const builder = new ColorBuilder();- builder.setThemeColor(ThemeColorType.ACCENT1);- const color = builder.build() as ThemeColor;- expect(color.getThemeColorType()).toEqual(ThemeColorType.ACCENT1);-});--test('Test Color RgbColor Dark', () => {- const builder = new ColorBuilder();- builder.setRgbColor('rgb(8,255,0)');- const rgb = builder.build() as RgbColor;- expect(rgb.getRed()).toEqual(8);- expect(rgb.getGreen()).toEqual(255);- expect(rgb.getBlue()).toEqual(0);- expect(rgb.getAlpha()).toEqual(1);- RgbColor.RGB_COLOR_AMT = -100;- expect(rgb.getRed()).toEqual(0);- expect(rgb.getGreen()).toEqual(155);- expect(rgb.getBlue()).toEqual(0);- expect(rgb.getAlpha()).toEqual(1);-});+import { ThemeColorType } from '../../src/Types/Enum';+import { Color, RgbColor, ThemeColor } from '../../src/Sheets/Domain/Color';+import { ColorBuilder } from '../../src/Sheets/Domain/ColorBuilder';++jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));++test('Test Color RgbColor', () => {+ const builder = new ColorBuilder();+ builder.setRgbColor('rgb(0,10,100)');+ const rgb = builder.build() as RgbColor;+ expect(rgb.getRed()).toEqual(0);+ expect(rgb.getGreen()).toEqual(10);+ expect(rgb.getBlue()).toEqual(100);+ expect(rgb.getAlpha()).toEqual(1);++ const hex = Color.rgbColorToHexValue(rgb);+ const hRgb = Color.hexValueToRgbColor(hex);+ console.log(hex);+ console.log(hRgb);++ builder.setRgbColor('rgba(0,10,100, 0.2)');+ const rgba = builder.build() as RgbColor;+ expect(rgba.getRed()).toEqual(0);+ expect(rgba.getGreen()).toEqual(10);+ expect(rgba.getBlue()).toEqual(100);+ expect(rgba.getAlpha()).toEqual(0.2);+});++test('Test Color themeColor Office', () => {+ const builder = new ColorBuilder();+ builder.setThemeColor(ThemeColorType.ACCENT1);+ const color = builder.build() as ThemeColor;+ const rgba = color.asRgbColor();+ expect(rgba.getRed()).toEqual(68);+ expect(rgba.getGreen()).toEqual(114);+ expect(rgba.getBlue()).toEqual(196);+ expect(rgba.getAlpha()).toEqual(1);+});++test('Test Color themeColor', () => {+ const builder = new ColorBuilder();+ builder.setThemeColor(ThemeColorType.ACCENT1);+ const color = builder.build() as ThemeColor;+ expect(color.getThemeColorType()).toEqual(ThemeColorType.ACCENT1);+});++test('Test Color RgbColor Dark', () => {+ const builder = new ColorBuilder();+ builder.setRgbColor('rgb(8,255,0)');+ const rgb = builder.build() as RgbColor;+ expect(rgb.getRed()).toEqual(8);+ expect(rgb.getGreen()).toEqual(255);+ expect(rgb.getBlue()).toEqual(0);+ expect(rgb.getAlpha()).toEqual(1);+ RgbColor.RGB_COLOR_AMT = -100;+ expect(rgb.getRed()).toEqual(0);+ expect(rgb.getGreen()).toEqual(155);+ expect(rgb.getBlue()).toEqual(0);+ expect(rgb.getAlpha()).toEqual(1);+});diff --git a/packages/core/test/Domain/Range.test.ts b/packages/core/test/Domain/Range.test.tsindex 27ac7580f5..0067eaa0d9 100644--- a/packages/core/test/Domain/Range.test.ts+++ b/packages/core/test/Domain/Range.test.ts@@ -16,8 +16,8 @@ import {ThemeColorType,VerticalAlign,WrapStrategy,-} from '../../src/Enum';-import { ICellData, ICellV } from '../../src/Interfaces';+} from '../../src/Types/Enum';+import { ICellData, ICellV } from '../../src/Types/Interfaces';import { createCoreTestContainer } from '../ContainerStartUp';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Domain/RangeList.test.ts b/packages/core/test/Domain/RangeList.test.tsindex 59dc38eff1..8b3687ba25 100644--- a/packages/core/test/Domain/RangeList.test.ts+++ b/packages/core/test/Domain/RangeList.test.ts@@ -4,7 +4,7 @@import { SheetContext } from '../../src/Basics/SheetContext';import { Workbook } from '../../src/Sheets/Domain/Workbook';import { Worksheet } from '../../src/Sheets/Domain/Worksheet';-import { BooleanNumber, WrapStrategy } from '../../src/Enum';+import { BooleanNumber, WrapStrategy } from '../../src/Types/Enum';import { TestInit } from '../ContainerStartUp';import { createCoreTestContainer } from './Range.test';diff --git a/packages/core/test/Domain/WorkBook.test.ts b/packages/core/test/Domain/WorkBook.test.tsindex dca6f19b22..4162acf2d9 100644--- a/packages/core/test/Domain/WorkBook.test.ts+++ b/packages/core/test/Domain/WorkBook.test.ts@@ -6,7 +6,7 @@ import { SheetContext } from '../../src/Basics/SheetContext';import { Range } from '../../src/Sheets/Domain/Range';import { Workbook } from '../../src/Sheets/Domain/Workbook';import { Worksheet } from '../../src/Sheets/Domain/Worksheet';-import { BooleanNumber } from '../../src/Enum';+import { BooleanNumber } from '../../src/Types/Enum';import { createCoreTestContainer } from './Range.test';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Module/NamedRange/Action/AddNamedRangeAction.test.ts b/packages/core/test/Module/NamedRange/Action/AddNamedRangeAction.test.tsindex 5b4cae874c..1e0e770c54 100644--- a/packages/core/test/Module/NamedRange/Action/AddNamedRangeAction.test.ts+++ b/packages/core/test/Module/NamedRange/Action/AddNamedRangeAction.test.ts@@ -5,7 +5,7 @@ import { ACTION_NAMES } from '../../../../src';import { SheetContext } from '../../../../src/Basics';import { ActionObservers, AddNamedRangeAction } from '../../../../src/Command';import { Workbook, Worksheet } from '../../../../src/Sheets/Domain';-import { INamedRange } from '../../../../src/Interfaces/INamedRange';+import { INamedRange } from '../../../../src/Types/Interfaces/INamedRange';import { createCoreTestContainer } from '../../../ContainerStartUp';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Module/NamedRange/Action/DeleteNamedRangeAction.test.ts b/packages/core/test/Module/NamedRange/Action/DeleteNamedRangeAction.test.tsindex f739e46921..0f4af733db 100644--- a/packages/core/test/Module/NamedRange/Action/DeleteNamedRangeAction.test.ts+++ b/packages/core/test/Module/NamedRange/Action/DeleteNamedRangeAction.test.ts@@ -9,7 +9,7 @@ import {} from '../../../../src';import { SheetContext } from '../../../../src/Basics';import { Workbook, Worksheet } from '../../../../src/Sheets/Domain';-import { INamedRange } from '../../../../src/Interfaces/INamedRange';+import { INamedRange } from '../../../../src/Types/Interfaces/INamedRange';import { createCoreTestContainer } from '../../../ContainerStartUp';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Module/NamedRange/Action/SetNamedRangeAction.test.ts b/packages/core/test/Module/NamedRange/Action/SetNamedRangeAction.test.tsindex 7e714d90c6..06ef539ff3 100644--- a/packages/core/test/Module/NamedRange/Action/SetNamedRangeAction.test.ts+++ b/packages/core/test/Module/NamedRange/Action/SetNamedRangeAction.test.ts@@ -10,7 +10,7 @@ import {import { SheetContext } from '../../../../src/Basics';import { Workbook, Worksheet } from '../../../../src/Sheets/Domain';-import { INamedRange } from '../../../../src/Interfaces/INamedRange';+import { INamedRange } from '../../../../src/Types/Interfaces/INamedRange';import { createCoreTestContainer } from '../../../ContainerStartUp';jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));diff --git a/packages/core/test/Module/NamedRange/NamedRange.test.ts b/packages/core/test/Module/NamedRange/NamedRange.test.tsindex d2ff6dd9e3..8d6605787b 100644--- a/packages/core/test/Module/NamedRange/NamedRange.test.ts+++ b/packages/core/test/Module/NamedRange/NamedRange.test.ts@@ -5,7 +5,7 @@ import { SheetContext, Workbook, Worksheet } from '../../../src';import {DEFAULT_NAMED_RANGE,INamedRange,-} from '../../../src/Interfaces/INamedRange';+} from '../../../src/Types/Interfaces/INamedRange';import { NamedRange } from '../../../src/Sheets/Domain/NamedRange';import { createCoreTestContainer } from '../../ContainerStartUp';