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
feat: update sheets-table facade example (#5229)
wpxp12345692988fb41911
diff --git a/packages/sheets-table/src/facade/f-workbook.ts b/packages/sheets-table/src/facade/f-workbook.tsindex 5511cfd64c..5bd67f5308 100644--- a/packages/sheets-table/src/facade/f-workbook.ts+++ b/packages/sheets-table/src/facade/f-workbook.ts@@ -29,41 +29,51 @@ export interface IFWorkbookSheetsTableMixin {* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const id = await fWorkbook.addTable(subUnitId, 'name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo(id);- * console.log('debugger tableInfo',tableInfo);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }* ```*/getTableInfo(tableId: string): ITableInfoWithUnitId | undefined;/*** Get table information by name- * @param tableName The table name+ * @param {string} tableName The table name* @returns {ITableInfo} The table information* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const id = await fWorkbook.addTable(subUnitId, 'name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfoByName('name-1');- * console.log('debugger tableInfo',tableInfo);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * const tableInfo = fWorkbook.getTableInfoByName('name-1');+ * console.log('debugger tableInfo', tableInfo);+ * }* ```*/getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefined;@@ -74,18 +84,8 @@ export interface IFWorkbookSheetsTableMixin {* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const id = await fWorkbook.addTable(subUnitId, 'name-1',{- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1',{- * showHeader: true- * })- * const tableList = fWorkbook.getTableList(fWorkbook.getId());- * console.log('debugger tableList', tableList);+ * const tables = fWorkbook.getTableList();+ * console.log('debugger tables', tables);* ```*/getTableList(): ITableInfo[];@@ -95,24 +95,30 @@ export interface IFWorkbookSheetsTableMixin {* @param {string} subUnitId The sub unit id* @param {string} tableName The table name* @param {ITableRange} rangeInfo The table range information- * @param {string} tableId The table id- * @param {ITableOptions} options The table options+ * @param {string} [tableId] The table id+ * @param {ITableOptions} [options] The table options* @returns {string} The table id* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const unitId = fWorkbook.getId();- * const id = await fWorkbook.addTable(subUnitId, 'name-1',{- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1',{- * showHeader: true- * })- * console.log('tableId:', id)+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const id = await fWorkbook.addTable(+ * fWorksheet.getSheetId(),+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (id) {+ * const tableInfo = fWorkbook.getTableInfo(id);+ * console.log('debugger tableInfo', tableInfo);+ * }* ```*/addTable(subUnitId: string, tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise<string | undefined>;@@ -120,32 +126,40 @@ export interface IFWorkbookSheetsTableMixin {/*** set table filter* @param {string} tableId The table id- * @param {number} column The column index+ * @param {number} column The column index, starting from 0.* @param {ITableFilterItem} filter The filter item* @returns {Promise<boolean>} The result of set table filter* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const id = await fWorkbook.addTable(subUnitId, 'name-1',{- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1',{- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo(id);- * console.log('debugger tableInfo',tableInfo);- * const result = await fWorkbook.setTableFilter(id, 1, {- * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,- * filterInfo: {- * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,- * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,- * expectedValue: 10,- * }- * })+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * // Set the filter for the second column+ * await fWorkbook.setTableFilter('id-1', 1, {+ * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,+ * filterInfo: {+ * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,+ * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,+ * expectedValue: 10,+ * },+ * });+ *+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }+ * ```*/setTableFilter(tableId: string, column: number, filter: ITableFilterItem | undefined): void;@@ -156,19 +170,13 @@ export interface IFWorkbookSheetsTableMixin {* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const id = await fWorkbook.addTable(subUnitId, 'name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const removedSuccess = await fWorkbook.removeTable(id);- * const tableInfo = fWorkbook.getTableInfo('id-1')- * console.log('debugger tableInfo is undefined', tableInfo)+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ *+ * if (tableInfo) {+ * // Remove the table with the specified id+ * await fWorkbook.removeTable('id-1');+ * }* ```*/removeTable(tableId: string): Promise<boolean>;diff --git a/packages/sheets-table/src/facade/f-worksheet.ts b/packages/sheets-table/src/facade/f-worksheet.tsindex 8a52f42324..cb84e8a172 100644--- a/packages/sheets-table/src/facade/f-worksheet.ts+++ b/packages/sheets-table/src/facade/f-worksheet.ts@@ -27,140 +27,159 @@ import { FWorksheet } from '@univerjs/sheets/facade';export interface IFWorkSheetTableMixin {/*** Add a table to the worksheet- * @param tableName The table name- * @param rangeInfo The table range information- * @param tableId The table id- * @param options The table options+ * @param {string} tableName The table name+ * @param {ITableRange} rangeInfo The table range information+ * @param {string} [tableId] The table id+ * @param {ITableOptions} [options] The table options* @returns {Promise<boolean>} Whether the table was added successfully* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo', tableInfo);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }* ```*/addTable(tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise<boolean>;/**- *- * @param tableId The table id- * @param column The column index- * @param filter The filter item+ * Set the filter for a table column+ * @param {string} tableId The table id+ * @param {number} column The table column index, starting from 0. For example, the first column is 0, the second column is 1, and so on.+ * @param {ITableFilterItem} filter The filter item* @returns {Promise<boolean>} Whether the table filter was set successfully* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo',tableInfo);- * const result = await fSheet.setTableFilter('id-1', 1, {- * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,- * filterInfo: {- * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,- * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,- * expectedValue: 10,- * }- * });- * console.log('debugger result',result);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * // Set the filter for the second column+ * await fWorksheet.setTableFilter('id-1', 1, {+ * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,+ * filterInfo: {+ * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,+ * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,+ * expectedValue: 10,+ * },+ * });+ *+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }+ * ```*/setTableFilter(tableId: string, column: number, filter: ITableFilterItem): Promise<boolean>;/*** Remove a table from the worksheet- * @param tableId The table id+ * @param {string} tableId The table id* @returns {Promise<boolean>} Whether the table was removed successfully* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })+ * const fWorksheet = fWorkbook.getActiveSheet();* const tableInfo = fWorkbook.getTableInfo('id-1');* console.log('debugger tableInfo', tableInfo);- * const result = await fSheet.removeTable('id-1');- * console.log('debugger result', result);+ *+ * if (tableInfo) {+ * // Remove the table with the specified id+ * await fWorksheet.removeTable('id-1');+ * }+ * ```*/removeTable(tableId: string): Promise<boolean>;/*** Set the range of a table- * @param tableId The table id- * @param rangeInfo The new range information+ * @param {string} tableId The table id+ * @param {ITableRange} rangeInfo The new range information* @returns {Promise<boolean>} Whether the table range was set successfully* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo', tableInfo);- * const result = await fSheet.setTableRange('id-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 20,- * endColumn: 5,- * })- * console.log('debugger result', result);- * const tableInfo2 = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo2', tableInfo2);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * // Update the table range to B2:F21 after 3 seconds+ * setTimeout(async () => {+ * const newRange = fWorksheet.getRange('B2:F21');+ * await fWorksheet.setTableRange('id-1', newRange.getRange());+ *+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }, 3000);+ * }* ```*/setTableRange(tableId: string, rangeInfo: ITableRange): Promise<boolean>;/*** Set the name of a table- * @param tableId The table id- * @param tableName The new table name+ * @param {string} tableId The table id+ * @param {string} tableName The new table name* @returns {Promise<boolean>} Whether the table name was set successfully* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const result = await fSheet.setTableName('id-1', 'new-name');- * console.log('debugger result',result);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * // Update the table name after 3 seconds+ * setTimeout(async () => {+ * await fWorksheet.setTableName('id-1', 'new-name');+ *+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }, 3000);+ * }* ```*/setTableName(tableId: string, tableName: string): Promise<boolean>;@@ -171,131 +190,127 @@ export interface IFWorkSheetTableMixin {* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableList = fSheet.getSubTableInfos();- * console.log('debugger tableList',tableList);+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const tables = fWorksheet.getSubTableInfos();+ * console.log('debugger tables', tables);* ```*/getSubTableInfos(): ITableInfoWithUnitId[];/*** Reset the column filter of a table- * @param tableId The table id- * @param column The column index+ * @param {string} tableId The table id+ * @param {number} column The column index, starting from 0. For example, the first column is 0, the second column is 1, and so on.* @returns {Promise<boolean>} Whether the table filter was reset successfully* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo',tableInfo);- * const result = await fSheet.setTableFilter('id-1', 1, {- * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,- * filterInfo: {- * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,- * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,- * expectedValue: 10,- * }- * })- * console.log('debugger result',result);- * const result2 = await fSheet.resetFilter('id-1', 1);- * console.log('debugger result2',result2);- * const tableInfo2 = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo2',tableInfo2);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * // Set the filter for the second column+ * await fWorksheet.setTableFilter('id-1', 1, {+ * filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,+ * filterInfo: {+ * conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,+ * compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,+ * expectedValue: 10,+ * },+ * });+ *+ * // Reset the filter for the second column after 3 seconds+ * setTimeout(async () => {+ * await fWorksheet.resetFilter('id-1', 1);+ * }, 3000);+ *+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }* ```*/resetFilter(tableId: string, column: number): Promise<boolean>;/*** Get the table information by cell position- * @param row The row index- * @param column The column index+ * @param {number} row The cell row index, starting from 0.+ * @param {number} column The cell column index, starting from 0.* @returns {ITableInfoWithUnitId | undefined} The table information or undefined if not found* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo',tableInfo);- * const tableInfo2 = fSheet.getTableByCell(1, 1);- * console.log('debugger tableInfo2',tableInfo2);+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * const cellB2 = fWorksheet.getRange('B2');+ * const row = cellB2.getRow();+ * const column = cellB2.getColumn();+ * console.log('debugger tableInfo', fWorksheet.getTableByCell(row, column));+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ * console.log('debugger tableInfo2', fWorksheet.getTableByCell(row, column));* ```*/getTableByCell(row: number, column: number): ITableInfoWithUnitId | undefined;/*** Add a theme to the table- * @param tableId The table id- * @param themeStyleJSON The theme style JSON+ * @param {string} tableId The table id+ * @param {IRangeThemeStyleJSON} themeStyleJSON The theme style JSON* @returns {Promise<boolean>} Whether the theme was added successfully* @example* ```typescript* const fWorkbook = univerAPI.getActiveWorkbook();- * const fSheet = fWorkbook.getActiveSheet();- * const subUnitId = fSheet.getSheetId();- * const res = await fSheet.addTable('name-1', {- * startRow: 1,- * startColumn: 1,- * endRow: 10,- * endColumn: 5,- * }, 'id-1', {- * showHeader: true- * })- * const tableInfo = fWorkbook.getTableInfo('id-1');- * console.log('debugger tableInfo', tableInfo);- * const result = await fSheet.addTableTheme('id-1', {- * name: "table-custom-1",- * headerRowStyle: {- * bd: {- * t: {- * s: 1,- * cl: {- * rgb: "rgb(95 101 116)"- * }- * }+ * const fWorksheet = fWorkbook.getActiveSheet();+ *+ * // Insert a table in the range B2:F11+ * const fRange = fWorksheet.getRange('B2:F11');+ * const success = await fWorksheet.addTable(+ * 'name-1',+ * fRange.getRange(),+ * 'id-1',+ * {+ * showHeader: true,+ * }+ * );+ *+ * if (success) {+ * await fWorksheet.addTableTheme('id-1', {+ * name: 'table-custom-1',+ * headerRowStyle: {+ * bg: {+ * rgb: '#145f82',+ * },+ * },+ * firstRowStyle: {+ * bg: {+ * rgb: '#c0e4f5',+ * },* },- * bg: {- * rgb: 'rgb(255,123,65)'- * }- * },- * lastRowStyle: {- * bd: {- * b: {- * s: 1,- * cl: {- * rgb: "rgb(95 101 116)"- * }- * }- * }- * },- * });+ * });+ *+ * const tableInfo = fWorkbook.getTableInfo('id-1');+ * console.log('debugger tableInfo', tableInfo);+ * }+ * ```*/addTableTheme(tableId: string, themeStyleJSON: IRangeThemeStyleJSON): Promise<boolean>;}