@univerjs/sheets 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { CellValue, ICellData, IObjectMatrixPrimitiveType, IRange, IStyleData, Nullable, Workbook, Worksheet, FBaseInitialable, ICommandService, Injector, WrapStrategy } from '@univerjs/core';
1
+ import { CellValue, CustomData, ICellData, IDocumentData, IObjectMatrixPrimitiveType, IRange, IStyleData, Nullable, Workbook, Worksheet, FBaseInitialable, ICommandService, Injector, RichTextValue, WrapStrategy } from '@univerjs/core';
2
2
  import { SplitDelimiterEnum } from '@univerjs/sheets';
3
3
  import { FHorizontalAlignment, FVerticalAlignment } from './utils';
4
4
  import { FormulaDataModel } from '@univerjs/engine-formula';
@@ -15,51 +15,44 @@ export declare class FRange extends FBaseInitialable {
15
15
  constructor(_workbook: Workbook, _worksheet: Worksheet, _range: IRange, _injector: Injector, _commandService: ICommandService, _formulaDataModel: FormulaDataModel);
16
16
  /**
17
17
  * Get the unit ID of the current workbook
18
- *
19
- * @return The unit ID of the workbook
18
+ * @returns The unit ID of the workbook
20
19
  */
21
20
  getUnitId(): string;
22
21
  /**
23
22
  * Gets the name of the worksheet
24
- *
25
- * @return The name of the worksheet
23
+ * @returns The name of the worksheet
26
24
  */
27
25
  getSheetName(): string;
26
+ /**
27
+ * Gets the ID of the worksheet
28
+ * @returns The ID of the worksheet
29
+ */
30
+ getSheetId(): string;
28
31
  /**
29
32
  * Gets the area where the statement is applied
30
- *
31
- * @return The area where the statement is applied
33
+ * @returns The area where the statement is applied
32
34
  */
33
35
  getRange(): IRange;
34
36
  /**
35
37
  * Gets the starting row number of the applied area
36
- *
37
- * @return The starting row number of the area
38
+ * @returns The starting row number of the area
38
39
  */
39
40
  getRow(): number;
40
41
  /**
41
42
  * Gets the starting column number of the applied area
42
- *
43
- * @return The starting column number of the area
43
+ * @returns The starting column number of the area
44
44
  */
45
45
  getColumn(): number;
46
46
  /**
47
47
  * Gets the width of the applied area
48
- *
49
- * @return The width of the area
48
+ * @returns The width of the area
50
49
  */
51
50
  getWidth(): number;
52
51
  /**
53
52
  * Gets the height of the applied area
54
- *
55
- * @return The height of the area
53
+ * @returns The height of the area
56
54
  */
57
55
  getHeight(): number;
58
- /**
59
- * Return first cell model data in this range
60
- * @returns The cell model data
61
- */
62
- getCellData(): ICellData | null;
63
56
  /**
64
57
  * Return range whether this range is merged
65
58
  * @returns if true is merged
@@ -67,72 +60,243 @@ export declare class FRange extends FBaseInitialable {
67
60
  isMerged(): boolean;
68
61
  /**
69
62
  * Return first cell style data in this range
70
- * @returns The cell style data
63
+ * @returns {IStyleData | null} The cell style data
71
64
  */
72
65
  getCellStyleData(): IStyleData | null;
73
66
  /**
74
67
  * Returns the value of the cell at the start of this range.
75
- * @returns The value of the cell.
68
+ * @returns {CellValue | null} The value of the cell.
76
69
  */
77
70
  getValue(): CellValue | null;
78
71
  /**
79
72
  * Returns the rectangular grid of values for this range.
80
73
  * Returns a two-dimensional array of values, indexed by row, then by column.
81
- * @returns A two-dimensional array of values.
74
+ * @returns {Nullable<CellValue>[][]} A two-dimensional array of values.
82
75
  */
83
76
  getValues(): Nullable<CellValue>[][];
77
+ /**
78
+ * Return first cell model data in this range
79
+ * @returns {ICellData | null} The cell model data
80
+ * @example
81
+ * ```
82
+ * univerAPI.getActiveWorkbook()
83
+ * .getActiveSheet()
84
+ * .getActiveRange()
85
+ * .getCellData()
86
+ * ```
87
+ */
88
+ getCellData(): ICellData | null;
84
89
  /**
85
90
  * Returns the cell data for the cells in the range.
86
- * @returns A two-dimensional array of cell data.
91
+ * @returns {Nullable<ICellData>[][]} A two-dimensional array of cell data.
92
+ * @example
93
+ * ```
94
+ * univerAPI.getActiveWorkbook()
95
+ * .getActiveSheet()
96
+ * .getActiveRange()
97
+ * .getCellDatas()
98
+ * ```
99
+ */
100
+ getCellDatas(): Nullable<ICellData>[][];
101
+ /**
102
+ * @deprecated use `getCellDatas` instead.
87
103
  */
88
104
  getCellDataGrid(): Nullable<ICellData>[][];
105
+ /**
106
+ * Returns the rich text value for the cell at the start of this range.
107
+ * @returns {Nullable<RichTextValue>} The rich text value
108
+ * @example
109
+ * ```
110
+ * univerAPI.getActiveWorkbook()
111
+ * .getActiveSheet()
112
+ * .getActiveRange()
113
+ * .getRichTextValue()
114
+ * ```
115
+ */
116
+ getRichTextValue(): Nullable<RichTextValue>;
117
+ /**
118
+ * Returns the rich text value for the cells in the range.
119
+ * @returns {Nullable<RichTextValue>[][]} A two-dimensional array of RichTextValue objects.
120
+ * @example
121
+ * ```
122
+ * univerAPI.getActiveWorkbook()
123
+ * .getActiveSheet()
124
+ * .getActiveRange()
125
+ * .getRichTextValues()
126
+ * ```
127
+ */
128
+ getRichTextValues(): Nullable<RichTextValue>[][];
129
+ /**
130
+ * Returns the value and rich text value for the cell at the start of this range.
131
+ * @returns {Nullable<CellValue | RichTextValue>} The value and rich text value
132
+ * @example
133
+ * ```
134
+ * univerAPI.getActiveWorkbook()
135
+ * .getActiveSheet()
136
+ * .getActiveRange()
137
+ * .getValueAndRichTextValue()
138
+ * ```
139
+ */
140
+ getValueAndRichTextValue(): Nullable<CellValue | RichTextValue>;
141
+ /**
142
+ * Returns the value and rich text value for the cells in the range.
143
+ * @returns {Nullable<CellValue | RichTextValue>[][]} A two-dimensional array of value and rich text value
144
+ * @example
145
+ * ```
146
+ * univerAPI.getActiveWorkbook()
147
+ * .getActiveSheet()
148
+ * .getActiveRange()
149
+ * .getValueAndRichTextValues()
150
+ * ```
151
+ */
152
+ getValueAndRichTextValues(): Nullable<CellValue | RichTextValue>[][];
89
153
  /**
90
154
  * Returns the formulas (A1 notation) for the cells in the range. Entries in the 2D array are empty strings for cells with no formula.
91
- * @returns A two-dimensional array of formulas in string format.
155
+ * @returns {string[][]} A two-dimensional array of formulas in string format.
156
+ * @example
157
+ * ```ts
158
+ * univerAPI.getActiveWorkbook()
159
+ * .getActiveSheet()
160
+ * .getActiveRange()
161
+ * .getFormulas()
162
+ * ```
92
163
  */
93
164
  getFormulas(): string[][];
94
165
  getWrap(): boolean;
95
166
  getWrapStrategy(): WrapStrategy;
96
167
  getHorizontalAlignment(): string;
97
168
  getVerticalAlignment(): string;
169
+ /**
170
+ * Set custom meta data for first cell in current range.
171
+ * @param {CustomData} data The custom meta data
172
+ * @returns {FRange} This range, for chaining
173
+ * ```ts
174
+ * univerAPI.getActiveWorkbook()
175
+ * .getActiveSheet()
176
+ * .getActiveRange()
177
+ * .setCustomMetaData({ key: 'value' });
178
+ * ```
179
+ */
180
+ setCustomMetaData(data: CustomData): FRange;
181
+ /**
182
+ * Set custom meta data for current range.
183
+ * @param {CustomData[][]} datas The custom meta data
184
+ * @returns {FRange} This range, for chaining
185
+ * ```ts
186
+ * univerAPI.getActiveWorkbook()
187
+ * .getActiveSheet()
188
+ * .getActiveRange()
189
+ * .setCustomMetaDatas([[{ key: 'value' }]]);
190
+ * ```
191
+ */
192
+ setCustomMetaDatas(datas: CustomData[][]): FRange;
193
+ /**
194
+ * Returns the custom meta data for the cell at the start of this range.
195
+ * @returns {CustomData | null} The custom meta data
196
+ * @example
197
+ * ```
198
+ * univerAPI.getActiveWorkbook()
199
+ * .getActiveSheet()
200
+ * .getActiveRange()
201
+ * .getCustomMetaData()
202
+ * ```
203
+ */
204
+ getCustomMetaData(): CustomData | null;
205
+ /**
206
+ * Returns the custom meta data for the cells in the range.
207
+ * @returns {CustomData[][]} A two-dimensional array of custom meta data
208
+ * @example
209
+ * ```
210
+ * univerAPI.getActiveWorkbook()
211
+ * .getActiveSheet()
212
+ * .getActiveRange()
213
+ * .getCustomMetaDatas()
214
+ * ```
215
+ */
216
+ getCustomMetaDatas(): Nullable<CustomData>[][];
98
217
  /**
99
218
  * Set background color for current range.
100
219
  * @param color {string}
101
220
  * @example
102
221
  * ```
103
- * univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackgroundColor('red')
222
+ * univerAPI.getActiveWorkbook()
223
+ * .getActiveSheet()
224
+ * .getActiveRange()
225
+ * .setBackgroundColor('red')
104
226
  * ```
105
227
  */
106
228
  setBackgroundColor(color: string): FRange;
107
229
  /**
108
230
  * Set background color for current range.
109
231
  * @example
110
- * ```
232
+ * ```typescript
111
233
  * univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')
112
234
  * ```
113
235
  * @param color {string}
114
236
  */
115
237
  setBackground(color: string): FRange;
116
238
  /**
117
- * The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
118
- * @param value
239
+ * Set new value for current cell, first cell in this range.
240
+ * @param {CellValue | ICellData} value The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
119
241
  */
120
242
  setValue(value: CellValue | ICellData): FRange;
243
+ /**
244
+ * Set new value for current cell, first cell in this range.
245
+ * @param {CellValue | ICellData} value The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
246
+ * ```ts
247
+ * univerAPI.getActiveWorkbook()
248
+ * .getActiveSheet()
249
+ * .getActiveRange()
250
+ * .setValueForCell(1);
251
+ * ```
252
+ */
253
+ setValueForCell(value: CellValue | ICellData): FRange;
254
+ /**
255
+ * Set the rich text value for the cell at the start of this range.
256
+ * @param {RichTextValue | IDocumentData} value The rich text value
257
+ * @returns {FRange} The range
258
+ * @example
259
+ * ```
260
+ * univerAPI.getActiveWorkbook()
261
+ * .getActiveSheet()
262
+ * .getActiveRange()
263
+ * .setRichTextValueForCell(new RichTextValue().insertText('Hello'));
264
+ * ```
265
+ */
266
+ setRichTextValueForCell(value: RichTextValue | IDocumentData): FRange;
267
+ /**
268
+ * Set the rich text value for the cells in the range.
269
+ * @param {RichTextValue[][]} values The rich text value
270
+ * @returns {FRange} The range
271
+ * @example
272
+ * ```ts
273
+ * univerAPI
274
+ * .getActiveWorkbook()
275
+ * .getActiveSheet()
276
+ * .getActiveRange()
277
+ * .setRichTextValues([[new RichTextValue().insertText('Hello')]]);
278
+ * ```
279
+ */
280
+ setRichTextValues(values: (RichTextValue | IDocumentData)[][]): FRange;
121
281
  /**
122
282
  * Set the cell wrap of the given range.
123
283
  * Cells with wrap enabled (the default) resize to display their full content. Cells with wrap disabled display as much as possible in the cell without resizing or running to multiple lines.
284
+ * @param isWrapEnabled
124
285
  */
125
286
  setWrap(isWrapEnabled: boolean): FRange;
126
287
  /**
127
288
  * Sets the text wrapping strategy for the cells in the range.
289
+ * @param strategy
128
290
  */
129
291
  setWrapStrategy(strategy: WrapStrategy): FRange;
130
292
  /**
131
293
  * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).
294
+ * @param alignment
132
295
  */
133
296
  setVerticalAlignment(alignment: FVerticalAlignment): FRange;
134
297
  /**
135
298
  * Set the horizontal (left to right) alignment for the given range (left/center/right).
299
+ * @param alignment
136
300
  */
137
301
  setHorizontalAlignment(alignment: FHorizontalAlignment): FRange;
138
302
  /**
@@ -157,10 +321,12 @@ export declare class FRange extends FBaseInitialable {
157
321
  setFontLine(fontLine: FontLine | null): this;
158
322
  /**
159
323
  * Sets the font underline style of the given ITextDecoration
324
+ * @param value
160
325
  */
161
326
  private _setFontUnderline;
162
327
  /**
163
328
  * Sets the font strikethrough style of the given ITextDecoration
329
+ * @param value
164
330
  */
165
331
  private _setFontStrikethrough;
166
332
  /**
@@ -180,36 +346,80 @@ export declare class FRange extends FBaseInitialable {
180
346
  setFontColor(color: string | null): this;
181
347
  /**
182
348
  * Merge cells in a range into one merged cell
183
- *
184
349
  * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
185
- *
186
350
  * @returns This range, for chaining
351
+ * @example
352
+ * ```ts
353
+ * const workbook = univerAPI.getActiveWorkbook();
354
+ * const worksheet = workbook.getActiveSheet();
355
+ * const range = worksheet.getRange(0, 0, 2, 2);
356
+ * const merge = range.merge();
357
+ * const isMerged = merge.isMerged();
358
+ * console.log('debugger', isMerged);
359
+ * ```
187
360
  */
188
361
  merge(defaultMerge?: boolean): FRange;
189
362
  /**
190
363
  * Merges cells in a range horizontally.
191
- *
192
364
  * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
193
- *
194
365
  * @returns This range, for chaining
366
+ * @example
367
+ * ```ts
368
+ * const workbook = univerAPI.getActiveWorkbook();
369
+ * const worksheet = workbook.getActiveSheet();
370
+ * const range = worksheet.getRange(2, 2, 2, 2);
371
+ * const merge = range.mergeAcross();
372
+ * const allMerge = worksheet.getMergeData();
373
+ * console.log(allMerge.length); // There will be two merged cells.
374
+ * ```
195
375
  */
196
376
  mergeAcross(defaultMerge?: boolean): FRange;
197
377
  /**
198
378
  * Merges cells in a range vertically.
199
- *
200
379
  * @param [defaultMerge] - If true, only the value in the upper left cell is retained.
201
- *
202
380
  * @returns This range, for chaining
381
+ * @example
382
+ * ```ts
383
+ * const workbook = univerAPI.getActiveWorkbook();
384
+ * const worksheet = workbook.getActiveSheet();
385
+ * const range = worksheet.getRange(4, 4, 2, 2);
386
+ * const merge = range.mergeVertically();
387
+ * const allMerge = worksheet.getMergeData();
388
+ * console.log(allMerge.length); // There will be two merged cells.
389
+ * ```
203
390
  */
204
391
  mergeVertically(defaultMerge?: boolean): FRange;
205
392
  /**
206
393
  * Returns true if cells in the current range overlap a merged cell.
207
394
  * @returns {boolean} is overlap with a merged cell
395
+ * @example
396
+ * ```ts
397
+ * const workbook = univerAPI.getActiveWorkbook();
398
+ * const worksheet = workbook.getActiveSheet();
399
+ * const range = worksheet.getRange(0,0,2,2);
400
+ * const merge = range.merge();
401
+ * const anchor = worksheet.getRange(0,0);
402
+ * const isPartOfMerge = anchor.isPartOfMerge();
403
+ * console.log('debugger, isPartOfMerge) // true
404
+ * ```
208
405
  */
209
406
  isPartOfMerge(): boolean;
210
407
  /**
211
408
  * Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.
212
409
  * @returns This range, for chaining
410
+ * @example
411
+ * ```ts
412
+ * const workbook = univerAPI.getActiveWorkbook();
413
+ * const worksheet = workbook.getActiveSheet();
414
+ * const range = worksheet.getRange(0,0,2,2);
415
+ * const merge = range.merge();
416
+ * const anchor = worksheet.getRange(0,0);
417
+ * const isPartOfMergeFirst = anchor.isPartOfMerge();
418
+ * console.log('debugger' isPartOfMergeFirst) // true
419
+ * range.breakApart();
420
+ * const isPartOfMergeSecond = anchor.isPartOfMerge();
421
+ * console.log('debugger' isPartOfMergeSecond) // false
422
+ * ```
213
423
  */
214
424
  breakApart(): FRange;
215
425
  /**
@@ -230,6 +440,7 @@ export declare class FRange extends FBaseInitialable {
230
440
  forEach(callback: (row: number, col: number, cell: ICellData) => void): void;
231
441
  /**
232
442
  * Returns a string description of the range, in A1 notation.
443
+ * @param withSheet
233
444
  * @returns {string} The A1 notation of the range.
234
445
  * ```ts
235
446
  * const fWorkbook = univerAPI.getActiveWorkbook();
@@ -1,39 +1,43 @@
1
- import { IDisposable, Injector, IWorkbookData, FUniver } from '@univerjs/core';
1
+ import { ICommandInfo, IDisposable, Injector, IWorkbookData, Nullable, FUniver } from '@univerjs/core';
2
+ import { FWorksheet } from './f-worksheet';
2
3
  import { FDefinedNameBuilder } from './f-defined-name';
3
4
  import { FPermission } from './f-permission';
4
5
  import { FWorkbook } from './f-workbook';
5
6
  export interface IFUniverSheetsMixin {
7
+ /**
8
+ * @deprecated use `univerAPI.createWorkbook` instead.
9
+ */
10
+ createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
6
11
  /**
7
12
  * Create a new spreadsheet and get the API handler of that spreadsheet.
8
- *
9
13
  * @param {Partial<IWorkbookData>} data The snapshot of the spreadsheet.
10
14
  * @returns {FWorkbook} FWorkbook API instance.
11
15
  * @example
12
16
  * ```ts
13
- * univerAPI.createUniverSheet({ id: 'Sheet1', name: 'Sheet1' });
17
+ * univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' });
14
18
  * ```
15
19
  */
16
- createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
20
+ createWorkbook(data: Partial<IWorkbookData>): FWorkbook;
17
21
  /**
18
22
  * Get the currently focused Univer spreadsheet.
19
23
  * @returns {FWorkbook | null} The currently focused Univer spreadsheet.
20
24
  * @example
21
25
  * ```ts
22
- * univerAPI.getActiveUniverSheet();
26
+ * univerAPI.getActiveWorkbook();
23
27
  * ```
24
28
  */
25
- getActiveUniverSheet(): FWorkbook | null;
29
+ getActiveWorkbook(): FWorkbook | null;
26
30
  /**
27
- * @deprecated use `getActiveUniverSheet` as instead.
31
+ * @deprecated use `univerAPI.getActiveWorkbook` instead
28
32
  */
29
- getActiveWorkbook(): FWorkbook | null;
33
+ getActiveUniverSheet(): FWorkbook | null;
30
34
  /**
31
35
  * Get the spreadsheet API handler by the spreadsheet id.
32
- *
33
36
  * @param {string} id The spreadsheet id.
34
37
  * @returns {FWorkbook | null} The spreadsheet API instance.
35
38
  */
36
39
  getUniverSheet(id: string): FWorkbook | null;
40
+ getWorkbook(id: string): FWorkbook | null;
37
41
  /**
38
42
  * Get the PermissionInstance.
39
43
  * @deprecated This function is deprecated and will be removed in version 0.6.0. Please use the function with the same name on the `FWorkbook` instance instead.
@@ -46,20 +50,61 @@ export interface IFUniverSheetsMixin {
46
50
  /**
47
51
  * Create a new defined name builder.
48
52
  * @returns {FDefinedNameBuilder} - The defined name builder.
49
- *
50
53
  * @example
51
54
  * ```ts
52
55
  * univerAPI.newDefinedName();
53
56
  * ```
54
57
  */
55
58
  newDefinedName(): FDefinedNameBuilder;
59
+ /**
60
+ * Get the target of the sheet.
61
+ * @param {string} unitId - The unitId of the sheet.
62
+ * @param {string} subUnitId - The subUnitId of the sheet.
63
+ * @returns {Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>} - The target of the sheet.
64
+ * @example
65
+ * ```ts
66
+ * univerAPI.getSheetTarget('unitId', 'subUnitId');
67
+ * ```
68
+ */
69
+ getSheetTarget(unitId: string, subUnitId: string): Nullable<{
70
+ workbook: FWorkbook;
71
+ worksheet: FWorksheet;
72
+ }>;
73
+ /**
74
+ * Get the target of the sheet.
75
+ * @param {ICommandInfo<object>} commandInfo - The commandInfo of the command.
76
+ * @returns {Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>} - The target of the sheet.
77
+ * @example
78
+ * ```ts
79
+ * univerAPI.addEvent(univerAPI.event.CommandExecuted, (commandInfo) => {
80
+ * const target = univerAPI.getCommandSheetTarget(commandInfo);
81
+ * if (!target) return;
82
+ * const { workbook, worksheet } = target;
83
+ * });
84
+ * ```
85
+ */
86
+ getCommandSheetTarget(commandInfo: ICommandInfo<object>): Nullable<{
87
+ workbook: FWorkbook;
88
+ worksheet: FWorksheet;
89
+ }>;
56
90
  }
57
91
  export declare class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
92
+ getCommandSheetTarget(commandInfo: ICommandInfo<object>): Nullable<{
93
+ workbook: FWorkbook;
94
+ worksheet: FWorksheet;
95
+ }>;
96
+ getSheetTarget(unitId: string, subUnitId: string): Nullable<{
97
+ workbook: FWorkbook;
98
+ worksheet: FWorksheet;
99
+ }>;
100
+ private _initWorkbookEvent;
58
101
  _initialize(injector: Injector): void;
59
102
  createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
60
- getActiveUniverSheet(): FWorkbook | null;
103
+ createWorkbook(data: Partial<IWorkbookData>): FWorkbook;
61
104
  getActiveWorkbook(): FWorkbook | null;
105
+ getActiveUniverSheet(): FWorkbook | null;
62
106
  getUniverSheet(id: string): FWorkbook | null;
107
+ getWorkbook(id: string): FWorkbook | null;
63
108
  getPermission(): FPermission;
64
109
  onUniverSheetCreated(callback: (workbook: FWorkbook) => void): IDisposable;
65
110
  newDefinedName(): FDefinedNameBuilder;