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(facade): add getSheetBySheetId API on FWorkbook (#1762)
FMW436b1b47f846
diff --git a/packages/facade/src/apis/__tests__/facade.spec.ts b/packages/facade/src/apis/__tests__/facade.spec.tsindex aae8cc497a..ab995bcd12 100644--- a/packages/facade/src/apis/__tests__/facade.spec.ts+++ b/packages/facade/src/apis/__tests__/facade.spec.ts@@ -208,4 +208,9 @@ describe('Test FUniver', () => {expect(mainExtension).toBeUndefined();});++ it('Function getSheetBySheetId', () => {+ const worksheet = univerAPI.getActiveWorkbook()?.getSheetBySheetId('sheet1');+ expect(worksheet!.getId()).toBe('sheet1');+ });});diff --git a/packages/facade/src/apis/sheets/f-workbook.ts b/packages/facade/src/apis/sheets/f-workbook.tsindex 9f685e342a..c75cca9eb4 100644--- a/packages/facade/src/apis/sheets/f-workbook.ts+++ b/packages/facade/src/apis/sheets/f-workbook.ts@@ -97,6 +97,20 @@ export class FWorkbook {return this._injector.createInstance(FWorksheet, this._workbook, this._workbook.getActiveSheet());}+ /**+ * Get a worksheet by sheet id.+ * @param sheetId id of the worksheet+ * @return the worksheet with given sheet id+ */+ getSheetBySheetId(sheetId: string): FWorksheet | null {+ const worksheet = this._workbook.getSheetBySheetId(sheetId);+ if (!worksheet) {+ return null;+ }++ return this._injector.createInstance(FWorksheet, this._workbook, worksheet);+ }+// #region editingundo(): Promise<boolean> {diff --git a/packages/facade/src/apis/sheets/f-worksheet.ts b/packages/facade/src/apis/sheets/f-worksheet.tsindex 8f8b0401d0..bfecfebf5b 100644--- a/packages/facade/src/apis/sheets/f-worksheet.ts+++ b/packages/facade/src/apis/sheets/f-worksheet.ts@@ -31,6 +31,10 @@ export class FWorksheet {@ICommandService private readonly _commandService: ICommandService) {}+ getId(): string {+ return this._worksheet.getSheetId();+ }+getSelection(): FSelection | null {const selections = this._selectionManagerService.getSelections();if (!selections) {