@guiexpert/table 1.1.97 → 1.1.99
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.
- package/README.md +12 -0
- package/css/main.css +381 -27
- package/css/table-classes.css +33 -9
- package/css/table-clipboard.css +41 -0
- package/css/table-color-vars.css +56 -0
- package/css/table-fill-batch.css +9 -2
- package/css/table-master-detail.css +20 -0
- package/css/table-sheet-editing.css +149 -0
- package/css/table-spreadsheet.css +50 -0
- package/css/table-tree.css +23 -16
- package/index.cjs +54 -67
- package/index.d.ts +52 -0
- package/index.js +18968 -11475
- package/lib/table/action/action-id.type.d.ts +1 -1
- package/lib/table/action/shortcut.service.d.ts +9 -0
- package/lib/table/aria/aria-texts.d.ts +26 -0
- package/lib/table/aria/aria-texts.if.d.ts +196 -0
- package/lib/table/batch-edit/batch-edit-service.d.ts +22 -0
- package/lib/table/batch-edit/cell-change.if.d.ts +6 -2
- package/lib/table/batch-edit/pending-cell-changes.d.ts +7 -0
- package/lib/table/batch-edit/write-row-value.d.ts +14 -0
- package/lib/table/calc/column-values.d.ts +2 -0
- package/lib/table/clipboard/clipboard-html.d.ts +41 -0
- package/lib/table/clipboard/clipboard-keymap.d.ts +18 -0
- package/lib/table/clipboard/clipboard-options.d.ts +30 -0
- package/lib/table/clipboard/clipboard-options.if.d.ts +67 -0
- package/lib/table/clipboard/clipboard-service.d.ts +122 -0
- package/lib/table/clipboard/input-pipes.d.ts +59 -0
- package/lib/table/clipboard/paste-plan.d.ts +96 -0
- package/lib/table/clipboard/tsv.d.ts +31 -0
- package/lib/table/crud/crud-object-edit.d.ts +2 -0
- package/lib/table/crud/crud-object-view.d.ts +2 -0
- package/lib/table/crud/crud-table-model-factory.d.ts +2 -0
- package/lib/table/data/common/event/ge-edit-event.d.ts +46 -0
- package/lib/table/data/common/event/ge-row-drag-event.d.ts +2 -2
- package/lib/table/data/common/event/ge-undo-event.d.ts +29 -0
- package/lib/table/data/options/table-options.d.ts +34 -0
- package/lib/table/data/options/table-options.if.d.ts +116 -1
- package/lib/table/data/tablemodel/areamodel/abstract-area-model.d.ts +11 -2
- package/lib/table/data/tablemodel/areamodel/area-model-array-of-arrays.d.ts +14 -0
- package/lib/table/data/tablemodel/areamodel/area-model-object-array.d.ts +14 -0
- package/lib/table/data/tablemodel/areamodel/area-model.if.d.ts +11 -0
- package/lib/table/data/tablemodel/column/column-def.d.ts +13 -0
- package/lib/table/data/tablemodel/column/column-def.if.d.ts +36 -1
- package/lib/table/data/tablemodel/column/default-editable.d.ts +18 -0
- package/lib/table/ele-scope.d.ts +37 -0
- package/lib/table/event-adapter.d.ts +6 -0
- package/lib/table/event-listener-hub.d.ts +10 -0
- package/lib/table/event-listener.if.d.ts +16 -0
- package/lib/table/factory/pivot-factory.d.ts +1 -1
- package/lib/table/factory/row-group-factory.d.ts +1 -1
- package/lib/table/factory/table-factory.d.ts +14 -0
- package/lib/table/formula/formula-ast.if.d.ts +32 -2
- package/lib/table/formula/formula-error.d.ts +4 -2
- package/lib/table/formula/parser.d.ts +5 -2
- package/lib/table/formula/tokenizer.d.ts +5 -2
- package/lib/table/input-handler.d.ts +8 -0
- package/lib/table/master-detail/master-detail-service.d.ts +9 -0
- package/lib/table/render-scope.d.ts +40 -0
- package/lib/table/row-drag/row-drag-service.d.ts +3 -2
- package/lib/table/rtl/rtl-util.d.ts +126 -0
- package/lib/table/rtl/table-direction.type.d.ts +23 -0
- package/lib/table/selection/selection-service.d.ts +48 -0
- package/lib/table/service/convenience-dom.service.d.ts +49 -1
- package/lib/table/service/excel-export-options.if.d.ts +23 -0
- package/lib/table/service/excel-service.d.ts +12 -2
- package/lib/table/service/excel-service.if.d.ts +38 -1
- package/lib/table/sheet/cell-address.d.ts +100 -0
- package/lib/table/sheet/cell-formula-options.d.ts +27 -0
- package/lib/table/sheet/cell-formula-options.if.d.ts +27 -0
- package/lib/table/sheet/excel-formula.d.ts +20 -0
- package/lib/table/sheet/format-formula.d.ts +19 -0
- package/lib/table/sheet/sheet-cells.if.d.ts +17 -0
- package/lib/table/sheet/sheet-compiler.d.ts +47 -0
- package/lib/table/sheet/sheet-engine.d.ts +207 -0
- package/lib/table/sheet/sheet-function-info.d.ts +25 -0
- package/lib/table/sheet/sheet-functions.d.ts +27 -0
- package/lib/table/sheet/sheet-values.d.ts +154 -0
- package/lib/table/sheet/shift-formula.d.ts +71 -0
- package/lib/table/sheet/table-sheet.d.ts +214 -0
- package/lib/table/sheet-editing/cell-editor-service.d.ts +105 -0
- package/lib/table/sheet-editing/cell-editor.if.d.ts +110 -0
- package/lib/table/sheet-editing/editing-keymap.d.ts +17 -0
- package/lib/table/sheet-editing/editing-options.d.ts +34 -0
- package/lib/table/sheet-editing/editing-options.if.d.ts +49 -0
- package/lib/table/sheet-editing/editors/date-cell-editor.d.ts +23 -0
- package/lib/table/sheet-editing/editors/number-cell-editor.d.ts +18 -0
- package/lib/table/sheet-editing/editors/select-cell-editor.d.ts +36 -0
- package/lib/table/sheet-editing/editors/text-cell-editor.d.ts +35 -0
- package/lib/table/sheet-editing/formula-assist.d.ts +103 -0
- package/lib/table/sheet-editing/formula-text.d.ts +61 -0
- package/lib/table/sheet-editing/sheet-navigation.d.ts +26 -0
- package/lib/table/spreadsheet/area-model-sheet.d.ts +170 -0
- package/lib/table/spreadsheet/formula-bar.d.ts +53 -0
- package/lib/table/spreadsheet/spreadsheet-factory.d.ts +111 -0
- package/lib/table/spreadsheet/spreadsheet-options.if.d.ts +28 -0
- package/lib/table/spreadsheet/spreadsheet-preset.d.ts +37 -0
- package/lib/table/spreadsheet/structure-edit.d.ts +35 -0
- package/lib/table/table-api.d.ts +533 -4
- package/lib/table/table-scope.d.ts +299 -1
- package/lib/table/undo/cell-changes-undoable.d.ts +34 -0
- package/lib/table/undo/model-rows.d.ts +17 -0
- package/lib/table/undo/pending-changes-undoable.d.ts +35 -0
- package/lib/table/undo/undo-keymap.d.ts +17 -0
- package/lib/table/undo/undo-options.d.ts +26 -0
- package/lib/table/undo/undo-options.if.d.ts +30 -0
- package/lib/table/undo/undo-service.d.ts +103 -0
- package/lib/table/undo/undo-stack.d.ts +62 -0
- package/lib/table/undo/undoable.if.d.ts +36 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The writing direction of a table ({@link TableOptionsIf.direction}):
|
|
3
|
+
*
|
|
4
|
+
* - `"ltr"` (default): left to right – the first column on the left.
|
|
5
|
+
* - `"rtl"`: right to left (Arabic, Hebrew, Persian, Urdu …) – the first column on the right, horizontal scrolling,
|
|
6
|
+
* fixed columns, tree indent, resize handles and arrow keys mirrored.
|
|
7
|
+
* - `"auto"`: the direction of the page where the table is created (`dir="rtl"` on `<html>`, a parent element or the
|
|
8
|
+
* host itself → `"rtl"`).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const tableOptions: TableOptionsIf = { ...new TableOptions(), direction: "rtl" };
|
|
12
|
+
*
|
|
13
|
+
* @since 1.1.98
|
|
14
|
+
* @category Options
|
|
15
|
+
*/
|
|
16
|
+
export type TableDirection = "ltr" | "rtl" | "auto";
|
|
17
|
+
/**
|
|
18
|
+
* A resolved writing direction – what {@link TableApi.getDirection} returns (`"auto"` is already decided).
|
|
19
|
+
*
|
|
20
|
+
* @since 1.1.98
|
|
21
|
+
* @category Options
|
|
22
|
+
*/
|
|
23
|
+
export type ResolvedTableDirection = "ltr" | "rtl";
|
|
@@ -20,6 +20,10 @@ export declare class SelectionService implements OnActionTriggeredIf {
|
|
|
20
20
|
protected anchorRanges: CellRange[];
|
|
21
21
|
/** The selection before a Ctrl/⌘-drag – each drag frame replaces only the dragged rectangle. */
|
|
22
22
|
protected dragSnapshot?: SelectionSnapshot;
|
|
23
|
+
/** The cell a Shift+click or Shift+arrow range starts at (the last click, or the active cell). @since 1.1.99 */
|
|
24
|
+
protected anchor?: [number, number];
|
|
25
|
+
/** The moving corner of the range of Shift+arrows (Excel); `undefined` = the anchor. @since 1.1.99 */
|
|
26
|
+
protected extent?: [number, number];
|
|
23
27
|
constructor(tableScope: TableScope);
|
|
24
28
|
/**
|
|
25
29
|
* Called on mouse down: a new gesture starts.
|
|
@@ -51,8 +55,52 @@ export declare class SelectionService implements OnActionTriggeredIf {
|
|
|
51
55
|
*/
|
|
52
56
|
onMouseClicked(evt: GeMouseEvent, _previousEvt: GeMouseEvent | undefined): boolean;
|
|
53
57
|
onActionTriggered(actionId: ActionId): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The cell a Shift+click or Shift+arrow range starts at: the last clicked cell or the active cell set by the
|
|
60
|
+
* keyboard ({@link collapseTo}).
|
|
61
|
+
*
|
|
62
|
+
* @returns {[number, number] | undefined} row and column, `undefined` before the first click/keyboard move
|
|
63
|
+
* @since 1.1.99
|
|
64
|
+
*/
|
|
65
|
+
getAnchor(): [number, number] | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* The moving corner of the range Shift+arrows grow (the anchor if there is none).
|
|
68
|
+
*
|
|
69
|
+
* @returns {[number, number] | undefined} row and column
|
|
70
|
+
* @since 1.1.99
|
|
71
|
+
*/
|
|
72
|
+
getExtent(): [number, number] | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Excel-style editing: the active cell moved (arrow keys, Tab, Enter) – the selection becomes this one cell and it
|
|
75
|
+
* is the new anchor. Selection types other than `"range"`/`"cell"` only get the anchor.
|
|
76
|
+
*
|
|
77
|
+
* @param {number} rowIndex - display row index
|
|
78
|
+
* @param {number} columnIndex - model column index
|
|
79
|
+
* @since 1.1.99
|
|
80
|
+
*/
|
|
81
|
+
collapseTo(rowIndex: number, columnIndex: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* Excel-style editing (Shift+arrows): the last range is spanned from the anchor to `(rowIndex, columnIndex)`;
|
|
84
|
+
* other ranges (Ctrl/⌘-clicks) stay. Only for the selection type `"range"`.
|
|
85
|
+
*
|
|
86
|
+
* @param {number} rowIndex - the new moving corner (display row index)
|
|
87
|
+
* @param {number} columnIndex - model column index
|
|
88
|
+
* @returns {CellRange | undefined} the new range, `undefined` without a range selection
|
|
89
|
+
* @since 1.1.99
|
|
90
|
+
*/
|
|
91
|
+
extendTo(rowIndex: number, columnIndex: number): CellRange | undefined;
|
|
92
|
+
private static rangeBetween;
|
|
54
93
|
/** True if the column is a row number column ({@link RowNumberColumnDef}). */
|
|
55
94
|
private isRowNumberColumn;
|
|
95
|
+
/** True for a cell of a header row with column letters (spreadsheet) – not over row numbers. */
|
|
96
|
+
private isColumnLetterCell;
|
|
97
|
+
/**
|
|
98
|
+
* A click on a column letter (selection type "range"): the whole column – Shift: the columns from the last letter
|
|
99
|
+
* (or the active cell), Ctrl/⌘: added. The active cell goes into the column.
|
|
100
|
+
*/
|
|
101
|
+
private clickColumnLetter;
|
|
102
|
+
/** The column of the last click on a letter (Shift+click spans from it). */
|
|
103
|
+
private letterAnchor?;
|
|
56
104
|
/** A click on the header cell of the row numbers: everything (selection types "row" and "range"). */
|
|
57
105
|
private selectAllByRowNumberHeader;
|
|
58
106
|
/** Selection type "range", click on a row number: the whole row – new, toggled (Ctrl/⌘) or removed (Ctrl/⌘+Alt). */
|
|
@@ -10,6 +10,7 @@ import { SideIdent } from '../data/side-ident.type.js';
|
|
|
10
10
|
import { SortState } from '../data/common/sort-state.type.js';
|
|
11
11
|
import { SortedOptionsIf } from '../data/options/sorted-options.if.js';
|
|
12
12
|
import { HtmlStyle } from './data/html-style.type.js';
|
|
13
|
+
import { ResolvedTableDirection } from '../rtl/table-direction.type.js';
|
|
13
14
|
|
|
14
15
|
/** @category DOM */
|
|
15
16
|
export interface AddColumnDivPara {
|
|
@@ -37,7 +38,54 @@ export declare class ConvenienceDomService {
|
|
|
37
38
|
readonly domService: DomServiceIf;
|
|
38
39
|
/** Width of the focus frame of a cell in px (WCAG 2.4.7: visible focus, not only a color). @since 1.1.91 */
|
|
39
40
|
static focusBorderWidthInPx: number;
|
|
41
|
+
/** Right-to-left: `left` is written as `right` and vice versa (see {@link setDirection}). */
|
|
42
|
+
private rtl;
|
|
43
|
+
/** The physical CSS property of the inline start (`left`, right-to-left `right`). */
|
|
44
|
+
private startKey;
|
|
45
|
+
/** The physical CSS property of the inline end (`right`, right-to-left `left`). */
|
|
46
|
+
private endKey;
|
|
40
47
|
constructor(domService: DomServiceIf);
|
|
48
|
+
/**
|
|
49
|
+
* Sets the writing direction of the table. All positions of the table are computed from the **start** of a row
|
|
50
|
+
* (x = 0 is the first column); in right-to-left this service writes them as `right` instead of `left` – in
|
|
51
|
+
* {@link setStyle}, {@link applyStyle}, {@link applyStyleInPx} and all `add…` methods – so that the whole table is
|
|
52
|
+
* mirrored. Called once by the table before anything is positioned.
|
|
53
|
+
*
|
|
54
|
+
* @param {ResolvedTableDirection} direction - `"ltr"` or `"rtl"`
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const dom = new ConvenienceDomService(new SimpleDomService());
|
|
58
|
+
* dom.setDirection("rtl");
|
|
59
|
+
* const div = document.createElement("div");
|
|
60
|
+
* dom.setStyle(div, "left", "20px"); // div.style.right = "20px"
|
|
61
|
+
*
|
|
62
|
+
* @since 1.1.98
|
|
63
|
+
*/
|
|
64
|
+
setDirection(direction: ResolvedTableDirection): void;
|
|
65
|
+
/**
|
|
66
|
+
* The writing direction set with {@link setDirection} (default `"ltr"`).
|
|
67
|
+
*
|
|
68
|
+
* @returns {ResolvedTableDirection} `"ltr"` or `"rtl"`
|
|
69
|
+
* @since 1.1.98
|
|
70
|
+
*/
|
|
71
|
+
getDirection(): ResolvedTableDirection;
|
|
72
|
+
/**
|
|
73
|
+
* The physical CSS property for a logical position key: in right-to-left `left` ↔ `right`, everything else as is.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} key - a CSS property
|
|
76
|
+
* @returns {string} the property to write
|
|
77
|
+
* @since 1.1.98
|
|
78
|
+
*/
|
|
79
|
+
toPhysicalStyleKey(key: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* The position of an element from the inline start in px, as written by this service (`style.left`, right-to-left
|
|
82
|
+
* `style.right`); 0 if it has none.
|
|
83
|
+
*
|
|
84
|
+
* @param {HTMLElement} ele - an element positioned by this service
|
|
85
|
+
* @returns {number} px
|
|
86
|
+
* @since 1.1.98
|
|
87
|
+
*/
|
|
88
|
+
getInlineStart(ele: HTMLElement): number;
|
|
41
89
|
setStyle(el: any, style: string, value: any): any;
|
|
42
90
|
applyStyle(ele: HTMLDivElement, style: HtmlStyle): HTMLDivElement;
|
|
43
91
|
applyDisplayNoneStyle(ele: HTMLDivElement): HTMLDivElement;
|
|
@@ -46,7 +94,7 @@ export declare class ConvenienceDomService {
|
|
|
46
94
|
applyStylePosistionRelative(ele: HTMLDivElement): HTMLDivElement;
|
|
47
95
|
applyStylePosistionAbsolute(ele: HTMLDivElement): HTMLDivElement;
|
|
48
96
|
applyStyleFullSize(ele: HTMLDivElement): HTMLDivElement;
|
|
49
|
-
applyStyleOverflowAuto(overflowX: "
|
|
97
|
+
applyStyleOverflowAuto(overflowX: "auto" | "scroll" | undefined, overflowY: "auto" | "scroll" | undefined, ele: HTMLDivElement): HTMLDivElement;
|
|
50
98
|
applyStyleNoPadding(ele: HTMLDivElement): HTMLDivElement;
|
|
51
99
|
appendRelativeChildDiv(parent: HTMLDivElement): DivScope;
|
|
52
100
|
appendText(parent: HTMLDivElement, text: string): HTMLElement;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options of an Excel export ({@link ExcelService.downloadExcel}, {@link ExcelService.createExcelBlob}).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // an Arabic sheet: column A on the right, like the table
|
|
6
|
+
* await new ExcelService().downloadExcel(matrix, "sales.xlsx", "", { rightToLeft: true });
|
|
7
|
+
*
|
|
8
|
+
* @since 1.1.98
|
|
9
|
+
* @category Export & clipboard
|
|
10
|
+
*/
|
|
11
|
+
export interface ExcelExportOptionsIf {
|
|
12
|
+
/**
|
|
13
|
+
* The worksheet runs from right to left (`<sheetView rightToLeft="1">`): column A on the right.
|
|
14
|
+
* {@link TableApi.downloadExcel} sets it for a right-to-left table ({@link TableOptionsIf.direction}).
|
|
15
|
+
*/
|
|
16
|
+
rightToLeft?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* {@link TableApi.downloadExcel}: cell formulas ({@link TableOptionsIf.cellFormulas}) become Excel formulas with their
|
|
19
|
+
* calculated values (otherwise: values). Only if the export is the sheet itself – no filter hides rows, no sorting,
|
|
20
|
+
* every data column visible; otherwise values and a warning. Since 1.1.99.
|
|
21
|
+
*/
|
|
22
|
+
cellFormulas?: boolean;
|
|
23
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ExcelExportOptionsIf } from './excel-export-options.if.js';
|
|
1
2
|
import { ExcelServiceIf } from './excel-service.if.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -26,26 +27,35 @@ import { ExcelServiceIf } from './excel-service.if.js';
|
|
|
26
27
|
export declare class ExcelService implements ExcelServiceIf {
|
|
27
28
|
/** Understands cells `{ value, numberFormat }` ({@link ExcelFormattedValueIf}), since 1.1.95. */
|
|
28
29
|
readonly supportsNumberFormats = true;
|
|
30
|
+
/** Understands cells `{ formula, value }` ({@link ExcelFormulaCellIf}), since 1.1.99. */
|
|
31
|
+
readonly supportsFormulas = true;
|
|
29
32
|
/**
|
|
30
33
|
* Downloads a matrix data as an Excel file.
|
|
31
34
|
*
|
|
32
35
|
* @param {Array<Array<any>>} matrix - A 2D array representing the data to be included in the Excel file. Each inner array corresponds to a row in the sheet.
|
|
33
36
|
* @param {string} [filename='file.xlsx'] - The name of the Excel file to be downloaded. Defaults to 'file.xlsx'.
|
|
34
37
|
* @param {string} [author=''] - The author's name to include as metadata in the Excel file. Optional parameter.
|
|
38
|
+
* @param {ExcelExportOptionsIf} [options] - e.g. `{ rightToLeft: true }` for a sheet from right to left (since 1.1.98)
|
|
35
39
|
* @return {void} Does not return a value.
|
|
36
40
|
* @throws {Error} Throws an error if the input matrix is not a valid 2D array or if the filename is an empty string.
|
|
37
41
|
*/
|
|
38
|
-
downloadExcel(matrix: Array<Array<any>>, filename?: string, author?: string): Promise<void>;
|
|
42
|
+
downloadExcel(matrix: Array<Array<any>>, filename?: string, author?: string, options?: ExcelExportOptionsIf): Promise<void>;
|
|
39
43
|
/**
|
|
40
44
|
* Creates the .xlsx file as a Blob (compressed), e.g. to upload it instead of downloading it.
|
|
41
45
|
*
|
|
42
46
|
* @example
|
|
43
47
|
* const blob = await new ExcelService().createExcelBlob([["Name", "City"], ["Ann", "Berlin"]]);
|
|
44
48
|
* await fetch("/api/upload", { method: "POST", body: blob });
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // a sheet from right to left (column A on the right), since 1.1.98
|
|
52
|
+
* const rtlBlob = await new ExcelService().createExcelBlob([["المدينة"], ["الرياض"]], "", { rightToLeft: true });
|
|
45
53
|
*/
|
|
46
|
-
createExcelBlob(matrix: Array<Array<any>>, author?: string): Promise<Blob>;
|
|
54
|
+
createExcelBlob(matrix: Array<Array<any>>, author?: string, options?: ExcelExportOptionsIf): Promise<Blob>;
|
|
47
55
|
private generateMap;
|
|
48
56
|
private getX1WorksheetsSheet1Xml;
|
|
57
|
+
/** A formula cell: `<f>` plus the cached value with its type (`str`, `b`, `e`; numbers and dates without). */
|
|
58
|
+
private formulaCellXml;
|
|
49
59
|
/** Number format → cell style index (1-based; 0 = default), filled by withNumberFormats() before the sheet is written. */
|
|
50
60
|
private numberFormatStyles;
|
|
51
61
|
/** Adds one cell style per number format used in the matrix (`<numFmts>` + `<cellXfs>`); unchanged without formats. */
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ExcelExportOptionsIf } from './excel-export-options.if.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Writes an Excel file from a matrix of values. The default implementation is {@link ExcelService};
|
|
3
5
|
* pass your own as last argument of the `TableScope` constructor to change how {@link TableApi.downloadExcel} exports.
|
|
@@ -6,14 +8,49 @@
|
|
|
6
8
|
*/
|
|
7
9
|
export interface ExcelServiceIf {
|
|
8
10
|
/** Creates the file from `matrix` (rows of values) and hands it to the browser as download. */
|
|
9
|
-
downloadExcel(matrix: Array<Array<any>>, filename: string, author?: string): void | Promise<void>;
|
|
11
|
+
downloadExcel(matrix: Array<Array<any>>, filename: string, author?: string, options?: ExcelExportOptionsIf): void | Promise<void>;
|
|
10
12
|
/**
|
|
11
13
|
* True if the service understands cells of the form {@link ExcelFormattedValueIf} (`{ value, numberFormat }`).
|
|
12
14
|
* Only then {@link TableApi.downloadExcel} exports percentages of „Show values as“ columns with the format `0.0%`;
|
|
13
15
|
* otherwise a service gets plain numbers (since 1.1.95).
|
|
14
16
|
*/
|
|
15
17
|
readonly supportsNumberFormats?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* True if the service understands cells of the form {@link ExcelFormulaCellIf} (`{ formula, value }`). Only then
|
|
20
|
+
* {@link TableApi.downloadExcel} with `{ cellFormulas: true }` exports cell formulas as formulas (since 1.1.99).
|
|
21
|
+
*/
|
|
22
|
+
readonly supportsFormulas?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A cell of an Excel matrix with a formula (`<f>`) and its calculated value (`<v>`, shown until Excel recalculates).
|
|
26
|
+
* Understood by {@link ExcelService}; {@link TableApi.downloadExcel} writes them for cell formulas with
|
|
27
|
+
* `{ cellFormulas: true }`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* await new ExcelService().downloadExcel([[2, 3, { formula: "A1*B1", value: 6 }]], "sheet.xlsx");
|
|
31
|
+
*
|
|
32
|
+
* @since 1.1.99
|
|
33
|
+
* @category Export & clipboard
|
|
34
|
+
*/
|
|
35
|
+
export interface ExcelFormulaCellIf {
|
|
36
|
+
/** The formula without `=`, with Excel's function names (`"SUM(D2:D4)"`, `"_xlfn.XLOOKUP(…)"`). */
|
|
37
|
+
formula: string;
|
|
38
|
+
/** The calculated value: a number, text, boolean, `Date` or an error value. */
|
|
39
|
+
value: unknown;
|
|
16
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* True for a cell of the form {@link ExcelFormulaCellIf}.
|
|
43
|
+
*
|
|
44
|
+
* @param {unknown} cell - a cell of an Excel matrix
|
|
45
|
+
* @returns {boolean} whether it is a formula cell
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* isExcelFormulaCell({ formula: "A1*2", value: 4 }); // true
|
|
49
|
+
*
|
|
50
|
+
* @since 1.1.99
|
|
51
|
+
* @category Export & clipboard
|
|
52
|
+
*/
|
|
53
|
+
export declare function isExcelFormulaCell(cell: unknown): cell is ExcelFormulaCellIf;
|
|
17
54
|
/**
|
|
18
55
|
* A cell of an Excel matrix with a number format, e.g. a share shown as percentage. Understood by
|
|
19
56
|
* {@link ExcelService} (`supportsNumberFormats`).
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Rows of a sheet (like Excel): 1 … 1 048 576. */
|
|
2
|
+
export declare const SHEET_MAX_ROWS = 1048576;
|
|
3
|
+
/** Columns of a sheet (like Excel): A … XFD = 16 384. */
|
|
4
|
+
export declare const SHEET_MAX_COLUMNS = 16384;
|
|
5
|
+
/**
|
|
6
|
+
* The letters of a column (0-based): 0 → `"A"`, 25 → `"Z"`, 26 → `"AA"`, 16 383 → `"XFD"`.
|
|
7
|
+
*
|
|
8
|
+
* @param {number} columnIndex - 0-based column
|
|
9
|
+
* @returns {string} the letters (`""` for an index outside 0 … 16 383)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* columnLetter(27); // "AB"
|
|
13
|
+
*
|
|
14
|
+
* @category Spreadsheet
|
|
15
|
+
* @since 1.1.99
|
|
16
|
+
*/
|
|
17
|
+
export declare function columnLetter(columnIndex: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* The 0-based column of letters: `"A"` → 0, `"ab"` → 27 (case does not matter).
|
|
20
|
+
*
|
|
21
|
+
* @param {string} letters - column letters
|
|
22
|
+
* @returns {number} the column, `-1` if invalid or beyond `XFD`
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* columnIndexOfLetter("XFD"); // 16383
|
|
26
|
+
*
|
|
27
|
+
* @category Spreadsheet
|
|
28
|
+
* @since 1.1.99
|
|
29
|
+
*/
|
|
30
|
+
export declare function columnIndexOfLetter(letters: string): number;
|
|
31
|
+
/**
|
|
32
|
+
* A parsed cell address: 0-based row and column, `$` = absolute.
|
|
33
|
+
*
|
|
34
|
+
* @category Spreadsheet
|
|
35
|
+
* @since 1.1.99
|
|
36
|
+
*/
|
|
37
|
+
export interface CellAddressIf {
|
|
38
|
+
row: number;
|
|
39
|
+
col: number;
|
|
40
|
+
absRow: boolean;
|
|
41
|
+
absCol: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The address of a cell: `toCellAddress(2, 1)` → `"B3"`, with `$` for absolute parts.
|
|
45
|
+
*
|
|
46
|
+
* @param {number} row - 0-based row
|
|
47
|
+
* @param {number} col - 0-based column
|
|
48
|
+
* @param {{ absRow?: boolean, absCol?: boolean }} [abs] - `$` before the row / column
|
|
49
|
+
* @returns {string} the address, `"#REF!"` outside the sheet
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* toCellAddress(0, 5, { absRow: true, absCol: true }); // "$F$1"
|
|
53
|
+
*
|
|
54
|
+
* @category Spreadsheet
|
|
55
|
+
* @since 1.1.99
|
|
56
|
+
*/
|
|
57
|
+
export declare function toCellAddress(row: number, col: number, abs?: {
|
|
58
|
+
absRow?: boolean;
|
|
59
|
+
absCol?: boolean;
|
|
60
|
+
}): string;
|
|
61
|
+
/**
|
|
62
|
+
* Parses a cell address like `"B3"`, `"$B$3"`, `"b$3"`.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} address - the address
|
|
65
|
+
* @returns {CellAddressIf | undefined} row, column (0-based) and the absolute parts; `undefined` if invalid
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* parseCellAddress("$B3"); // { row: 2, col: 1, absRow: false, absCol: true }
|
|
69
|
+
*
|
|
70
|
+
* @category Spreadsheet
|
|
71
|
+
* @since 1.1.99
|
|
72
|
+
*/
|
|
73
|
+
export declare function parseCellAddress(address: string): CellAddressIf | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* A parsed range: first and last cell (0-based, inclusive). A whole column (`"A:A"`) has the rows 0 … 1 048 575 and
|
|
76
|
+
* `wholeColumns: true`, a whole row (`"3:3"`) the columns 0 … 16 383 and `wholeRows: true`.
|
|
77
|
+
*
|
|
78
|
+
* @category Spreadsheet
|
|
79
|
+
* @since 1.1.99
|
|
80
|
+
*/
|
|
81
|
+
export interface RangeAddressIf {
|
|
82
|
+
from: CellAddressIf;
|
|
83
|
+
to: CellAddressIf;
|
|
84
|
+
wholeColumns?: boolean;
|
|
85
|
+
wholeRows?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parses a range like `"A1:B5"`, `"$A$1:B5"`, `"A:A"`, `"B:D"`, `"3:3"` or a single cell `"C7"`. The corners are
|
|
89
|
+
* sorted (`"B5:A1"` = `"A1:B5"`).
|
|
90
|
+
*
|
|
91
|
+
* @param {string} address - the range
|
|
92
|
+
* @returns {RangeAddressIf | undefined} the range; `undefined` if invalid
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* parseRangeAddress("A:A")?.to.row; // 1048575
|
|
96
|
+
*
|
|
97
|
+
* @category Spreadsheet
|
|
98
|
+
* @since 1.1.99
|
|
99
|
+
*/
|
|
100
|
+
export declare function parseRangeAddress(address: string): RangeAddressIf | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FormulaFunction } from '../formula/formula-options.if.js';
|
|
2
|
+
import { CellFormulaOptionsIf } from './cell-formula-options.if.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The defaults of {@link CellFormulaOptionsIf} (cell formulas).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* CellFormulaOptions.create(true)?.maxRangeCells; // 10000000
|
|
9
|
+
*
|
|
10
|
+
* @category Spreadsheet
|
|
11
|
+
* @since 1.1.99
|
|
12
|
+
*/
|
|
13
|
+
export declare class CellFormulaOptions implements CellFormulaOptionsIf {
|
|
14
|
+
functions: Record<string, FormulaFunction>;
|
|
15
|
+
isoDatesAsDates: boolean;
|
|
16
|
+
maxRangeCells: number;
|
|
17
|
+
rejectInvalidFormulas: boolean;
|
|
18
|
+
columns?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* The options of {@link TableOptionsIf.cellFormulas}: `undefined`/`false` = off, `true` = the defaults, an object =
|
|
21
|
+
* the defaults overridden by its values (`undefined` keeps the default).
|
|
22
|
+
*
|
|
23
|
+
* @param {boolean | Partial<CellFormulaOptionsIf>} [option] - the option
|
|
24
|
+
* @returns {CellFormulaOptionsIf | undefined} complete options, `undefined` if off
|
|
25
|
+
*/
|
|
26
|
+
static create(option?: boolean | Partial<CellFormulaOptionsIf>): CellFormulaOptionsIf | undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FormulaFunction } from '../formula/formula-options.if.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cell formulas like in Excel ({@link TableOptionsIf.cellFormulas}, {@link SheetEngine}): `=B2*C2`, `=SUM(D2:D100)`.
|
|
5
|
+
* `cellFormulas: true` uses the defaults of {@link CellFormulaOptions}; an object overrides single values.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const engine = SheetEngine.fromArrays(data, { functions: { VAT: (net) => Number(net) * 0.19 } });
|
|
9
|
+
*
|
|
10
|
+
* @category Spreadsheet
|
|
11
|
+
* @since 1.1.99
|
|
12
|
+
*/
|
|
13
|
+
export interface CellFormulaOptionsIf {
|
|
14
|
+
/**
|
|
15
|
+
* Own functions by name (case-insensitive); they may replace built-in ones. A range argument (`A1:B5`) arrives as
|
|
16
|
+
* {@link FormulaRange}, a date as its serial number.
|
|
17
|
+
*/
|
|
18
|
+
functions: Record<string, FormulaFunction>;
|
|
19
|
+
/** ISO text (`"2026-10-16"`) counts as date in arithmetic (`=A2+1`) and date functions. Default `true`. */
|
|
20
|
+
isoDatesAsDates: boolean;
|
|
21
|
+
/** Larger ranges are `#ERROR!` (`A1:XFD1048576`). Default `10_000_000`. */
|
|
22
|
+
maxRangeCells: number;
|
|
23
|
+
/** The table refuses formulas with a syntax error instead of storing them (`#ERROR!`). Default `false`. */
|
|
24
|
+
rejectInvalidFormulas: boolean;
|
|
25
|
+
/** Only these properties hold formulas (the other columns keep `=…` as text). Default: every data column. */
|
|
26
|
+
columns?: string[];
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Where the data of the sheet lie in the file: rows above, columns in front, and their number. */
|
|
2
|
+
export interface ExcelSheetPlacementIf {
|
|
3
|
+
dRow: number;
|
|
4
|
+
dCol: number;
|
|
5
|
+
rows: number;
|
|
6
|
+
cols: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The formula of a cell formula for an Excel file: all references moved by the offset of the sheet (header rows,
|
|
10
|
+
* leading columns – also absolute parts), whole columns/rows bounded to the data (the file holds headers and totals
|
|
11
|
+
* around them), newer functions with `_xlfn.`. `undefined` for a formula Excel cannot read: a syntax error or a field
|
|
12
|
+
* (`[price]`). Text without `=`.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} input - the cell formula (with `=`)
|
|
15
|
+
* @param {ExcelSheetPlacementIf} at - where the data are in the file
|
|
16
|
+
* @returns {string | undefined} the Excel formula
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function toExcelFormula(input: string, at: ExcelSheetPlacementIf): string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FormulaNode, FormulaRefNode } from '../formula/formula-ast.if.js';
|
|
2
|
+
|
|
3
|
+
/** A reference as text: `B3`, `$B$3`; whole columns/rows in ranges. */
|
|
4
|
+
export declare function formatRef(ref: FormulaRefNode): string;
|
|
5
|
+
/**
|
|
6
|
+
* The canonical text of a formula AST (without `=`): functions and references in capitals, `,` between arguments,
|
|
7
|
+
* texts with `""` for a quotation mark, parentheses only where needed. Used for moving formulas and the Excel export.
|
|
8
|
+
*
|
|
9
|
+
* @param {FormulaNode} ast - the syntax tree
|
|
10
|
+
* @returns {string} the formula text
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* formatFormula({ kind: "binary", op: "*", left: { kind: "ref", row: 1, col: 1, absRow: false, absCol: false },
|
|
14
|
+
* right: { kind: "literal", value: 2 } }); // "B2*2"
|
|
15
|
+
*
|
|
16
|
+
* @category Spreadsheet
|
|
17
|
+
* @since 1.1.99
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatFormula(ast: FormulaNode): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The link between the body model and the cell formulas of a table ({@link TableOptionsIf.cellFormulas}): the model
|
|
3
|
+
* asks it for the value of every text input – an `=…` cell of a formula column gives its result. Set by the table.
|
|
4
|
+
*
|
|
5
|
+
* @category Internals
|
|
6
|
+
* @since 1.1.99
|
|
7
|
+
*/
|
|
8
|
+
export interface SheetCellsIf {
|
|
9
|
+
/** The value of a cell of an array row (`AreaModelArrayOfArrays`): the result for a formula, otherwise `input`. */
|
|
10
|
+
valueAt(row: unknown, columnIndex: number, input: string): unknown;
|
|
11
|
+
/** The value of a property of a row object: the result for a formula, otherwise `input`. */
|
|
12
|
+
valueOfProperty(row: unknown, property: string, input: string): unknown;
|
|
13
|
+
/** True if the column of this property may hold formulas. */
|
|
14
|
+
isFormulaProperty(property: string): boolean;
|
|
15
|
+
/** True if the column may hold formulas. */
|
|
16
|
+
isFormulaColumnIndex(columnIndex: number): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FormulaFunction } from '../formula/formula-options.if.js';
|
|
2
|
+
import { FormulaError } from '../formula/formula-error.js';
|
|
3
|
+
import { SheetFnContext } from './sheet-functions.js';
|
|
4
|
+
import { SheetValue } from './sheet-values.js';
|
|
5
|
+
|
|
6
|
+
/** A range a formula reads (0-based, inclusive, already cut to the sheet). */
|
|
7
|
+
export interface RangeRef {
|
|
8
|
+
r1: number;
|
|
9
|
+
c1: number;
|
|
10
|
+
r2: number;
|
|
11
|
+
c2: number;
|
|
12
|
+
}
|
|
13
|
+
/** What the compiled formula of a cell needs from the engine. */
|
|
14
|
+
export interface SheetCompileEnv {
|
|
15
|
+
/** The value of a cell (formula result or data). */
|
|
16
|
+
read(row: number, col: number): SheetValue;
|
|
17
|
+
/** Rows of the data (ranges are cut there). */
|
|
18
|
+
rowCount(): number;
|
|
19
|
+
/** The column of a data field (`[price]`), -1 if it is none. */
|
|
20
|
+
fieldColumn(name: string): number;
|
|
21
|
+
/** Own functions (upper case names). */
|
|
22
|
+
functions: Map<string, FormulaFunction>;
|
|
23
|
+
/** Largest range (cells) – larger ones are #ERROR!. */
|
|
24
|
+
maxRangeCells: number;
|
|
25
|
+
fn: SheetFnContext;
|
|
26
|
+
}
|
|
27
|
+
/** A compiled cell formula: evaluation and the cells it reads. */
|
|
28
|
+
export interface CompiledCellFormula {
|
|
29
|
+
evaluate(): SheetValue;
|
|
30
|
+
/** Single cells read (`row * 16384 + col`). */
|
|
31
|
+
readonly singles: number[];
|
|
32
|
+
readonly ranges: RangeRef[];
|
|
33
|
+
readonly volatile: boolean;
|
|
34
|
+
/** Syntax error or unknown function – the evaluation returns it. */
|
|
35
|
+
readonly error?: FormulaError;
|
|
36
|
+
}
|
|
37
|
+
/** The key of a cell in maps. */
|
|
38
|
+
export declare function cellKey(row: number, col: number): number;
|
|
39
|
+
/**
|
|
40
|
+
* Compiles the formula of a cell (`=B2*C2`) into closures over the engine – no `eval`, no `new Function`.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} source - the formula with `=`
|
|
43
|
+
* @param {number} row - the row of the cell (for `[field]`)
|
|
44
|
+
* @param {SheetCompileEnv} env - the engine
|
|
45
|
+
* @returns {CompiledCellFormula} the compiled formula
|
|
46
|
+
*/
|
|
47
|
+
export declare function compileCellFormula(source: string, row: number, env: SheetCompileEnv): CompiledCellFormula;
|