From 67833dcc4e3db1968bd285ec5280ec567e3e387c Mon Sep 17 00:00:00 2001 From: AlexeyMatveev686 Date: Wed, 4 Oct 2023 14:48:33 +0300 Subject: [PATCH 1/5] [se][builder] Add new class "ApiFreezePanes", and new methods: "Api.FreezePanes", "ApiWorksheet.GetFreezePanes" and property "ApiWorksheet.tFreezePanes". Also change "ApiRange.Select" (now we can make select for multirange). --- cell/api.js | 4 +- cell/apiBuilder.js | 207 ++++++++++++++++++++++++++++++++++++- cell/view/WorksheetView.js | 5 +- 3 files changed, 212 insertions(+), 4 deletions(-) diff --git a/cell/api.js b/cell/api.js index f492cf38e1..8d373a988f 100644 --- a/cell/api.js +++ b/cell/api.js @@ -5689,9 +5689,9 @@ var editor; }; // Frozen pane - spreadsheet_api.prototype.asc_freezePane = function (type) { + spreadsheet_api.prototype.asc_freezePane = function (type, col, row) { if (this.canEdit()) { - this.wb.getWorksheet().freezePane(type); + this.wb.getWorksheet().freezePane(type, col, row); } }; diff --git a/cell/apiBuilder.js b/cell/apiBuilder.js index 58b5bb9b8e..6ef0242941 100644 --- a/cell/apiBuilder.js +++ b/cell/apiBuilder.js @@ -82,6 +82,7 @@ * @property {boolean} PrintGridlines - Returns or sets the page PrintGridlines property. * @property {Array} Defnames - Returns an array of the ApiName objects. * @property {Array} Comments - Returns an array of the ApiComment objects. + * @property {ApiFreezePanes} FreezePanes - Returns a freezePanes for a current worsheet. */ function ApiWorksheet(worksheet) { this.worksheet = worksheet; @@ -355,6 +356,14 @@ this._object = object; } + /** + * Class representing a freeze Panes. + * @constructor + */ + function ApiFreezePanes(ws) { + this.ws = ws; + } + /** * Returns a class formatted according to the instructions contained in the format expression. * @memberof Api @@ -897,6 +906,61 @@ } }); + /** + * Specifies the cell border position. + * @typedef {("row" | "column" | "cell" | null )} FreezePaneType + */ + + /** + * Freeze and unfeeze Panes. + * @memberof Api + * @typeofeditors ["CSE"] + * @param {FreezePaneType} FreezePaneType - The type of freezing ('null' to unfreeze). + * @since 7.5.1 + */ + Api.prototype.FreezePanes = function(FreezePaneType) { + if (typeof FreezePaneType === 'string' || FreezePaneType === null) { + let cell = this.wb.getWorksheet().topLeftFrozenCell; + //detect current freeze type + let curType = 0; + if (cell) { + let c = cell.getCol0(); + let r = cell.getRow0(); + if (c == 0) { + // hole row + curType = 1; + } else if (r == 0) { + // whole column + curType = 2; + } else { + // cell + curType = 3; + } + } + + let type = null; + if (FreezePaneType === 'cell' && ( ( curType && curType !== 3 ) || ( !curType ) ) ) { + // make unfreeze and freeze then + if (curType) + this.asc_freezePane(undefined); + + type = undefined; + } else if (FreezePaneType === null && curType) { + type = undefined; + } else if (FreezePaneType === 'row' && curType !== 1) { + type = 1; + } else if (FreezePaneType === 'column' && curType !== 2) { + type = 2; + } + + if (type !== null) + this.asc_freezePane(type); + + } else { + throw(new Error('Invalid parametr "FreezePaneType".')); + } + }; + /** * Returns the state of sheet visibility. * @memberof ApiWorksheet @@ -1888,6 +1952,23 @@ } }; + /** + * Returns a freezePanes for a current worsheet. + * @memberof ApiWorksheet + * @typeofeditors ["CSE"] + * @returns {ApiFreezePanes} + */ + ApiWorksheet.prototype.GetFreezePanes = function() { + return new ApiFreezePanes(this.worksheet); + }; + + Object.defineProperty(ApiWorksheet.prototype, "FreezePanes", { + get: function () { + return this.GetFreezePanes(); + } + }); + + /** * Specifies the cell border position. * @typedef {("DiagonalDown" | "DiagonalUp" | "Bottom" | "Left" | "Right" | "Top" | "InsideHorizontal" | "InsideVertical")} BordersIndex @@ -3087,7 +3168,14 @@ ApiRange.prototype.Select = function () { if (this.range.worksheet.getId() === this.range.worksheet.workbook.getActiveWs().getId()) { var newSelection = new AscCommonExcel.SelectionRange(this.range.worksheet); - newSelection.assign2(this.range.bbox); + let bbox = this.range.bbox; + newSelection.assign2(bbox); + if (this.areas) { + this.areas.forEach(function(el){ + if (!bbox.isEqual(el.bbox)) + newSelection.ranges.push(el.bbox); + }) + } newSelection.Select(); } }; @@ -6355,6 +6443,114 @@ } }); + + //------------------------------------------------------------------------------------------------------------------ + // + // ApiFreezePanes + // + //------------------------------------------------------------------------------------------------------------------ + + /** + * Sets the frozen cells in the active worksheet view. The range provided corresponds to cells that will be frozen in the top- and left-most pane. + * @memberof ApiFreezePanes + * @typeofeditors ["CSE"] + * @param {ApiRange | String} frozenRange - A range that represents the cells to be frozen panes. + * @since 7.5.1 + */ + ApiFreezePanes.prototype.FreezeAt = function(frozenRange) { + let api = this.ws.workbook.oApi; + let tempRange = (typeof frozenRange === 'string') ? api.GetRange(frozenRange) : frozenRange; + + if (tempRange.range && tempRange.range !== null) { + let bbox = tempRange.range.bbox; + let r = bbox.r2 < AscCommon.gc_nMaxRow0 ? bbox.r2 + 1 : bbox.r2; + let c = bbox.c2 < AscCommon.gc_nMaxCol0 ? bbox.c2 + 1 : bbox.c2; + let cell = new ApiRange(this.ws.getRange3(r, c, r, c)); + let selection = this.ws.selectionRange.clone(); + cell.Select(); + api.FreezePanes('cell'); + selection.Select(); + } else { + throw(new Error('Invalid parametr "frozenRange".')); + } + }; + + /** + * Freeze the first column or columns of the worksheet in place. + * @memberof ApiFreezePanes + * @typeofeditors ["CSE"] + * @param {Number?} [count=0] - Optional number of columns to freeze, or zero to unfreeze all columns. + * @since 7.5.1 + */ + ApiFreezePanes.prototype.FreezeColumns = function(count) { + let api = this.ws.workbook.oApi; + if (typeof count === 'number' && count > 0 && count <= AscCommon.gc_nMaxCol0) { + api.asc_freezePane(null, count, 0); + } else if (!!api.wb.getWorksheet().topLeftFrozenCell) { + api.asc_freezePane(undefined); + } + }; + + /** + * Freeze the top row or rows of the worksheet in place. + * @memberof ApiFreezePanes + * @typeofeditors ["CSE"] + * @param {Number?} [count=0] - Optional number of rows to freeze, or zero to unfreeze all rows. + * @since 7.5.1 + */ + ApiFreezePanes.prototype.FreezeRows = function(count) { + let api = this.ws.workbook.oApi; + if (typeof count === 'number' && count > 0 && count <= AscCommon.gc_nMaxRow0) { + api.asc_freezePane(null, 0, count); + } else if (!!api.wb.getWorksheet().topLeftFrozenCell) { + api.asc_freezePane(undefined); + } + }; + + /** + * Freeze the top row or rows of the worksheet in place. + * @memberof ApiFreezePanes + * @typeofeditors ["CSE"] + * @returns {ApiRange | null} - Returns null if there is no frozen pane. + * @since 7.5.1 + */ + ApiFreezePanes.prototype.GetLocation = function() { + let result = null; + let api = this.ws.workbook.oApi; + let cell = api.wb.getWorksheet().topLeftFrozenCell; + if (cell) { + let c = cell.getCol0(); + let r = cell.getRow0(); + if (c == 0) { + // hole row + r--; + c = AscCommon.gc_nMaxCol0; + } else if (r == 0) { + // whole column + c--; + r = AscCommon.gc_nMaxRow0; + } else { + // cell + r--; + c--; + } + result = new ApiRange(this.ws.getRange3(0, 0, r, c)); + } + return result; + }; + + /** + * Removes all frozen panes in the worksheet. + * @memberof ApiFreezePanes + * @typeofeditors ["CSE"] + * @since 7.5.1 + */ + ApiFreezePanes.prototype.Unfreeze = function() { + if (!!this.ws.workbook.oApi.wb.getWorksheet().topLeftFrozenCell) + this.ws.workbook.oApi.asc_freezePane(undefined); + }; + + Api.prototype["Format"] = Api.prototype.Format; Api.prototype["AddSheet"] = Api.prototype.AddSheet; Api.prototype["GetSheets"] = Api.prototype.GetSheets; @@ -6380,6 +6576,7 @@ Api.prototype["AddComment"] = Api.prototype.AddComment; Api.prototype["GetComments"] = Api.prototype.GetComments; Api.prototype["GetCommentById"] = Api.prototype.GetCommentById; + Api.prototype["FreezePanes"] = Api.prototype.FreezePanes; ApiWorksheet.prototype["GetVisible"] = ApiWorksheet.prototype.GetVisible; ApiWorksheet.prototype["SetVisible"] = ApiWorksheet.prototype.SetVisible; @@ -6432,6 +6629,7 @@ ApiWorksheet.prototype["GetAllCharts"] = ApiWorksheet.prototype.GetAllCharts; ApiWorksheet.prototype["GetAllOleObjects"] = ApiWorksheet.prototype.GetAllOleObjects; ApiWorksheet.prototype["Move"] = ApiWorksheet.prototype.Move; + ApiWorksheet.prototype["GetFreezePanes"] = ApiWorksheet.prototype.GetFreezePanes; ApiRange.prototype["GetClassType"] = ApiRange.prototype.GetClassType ApiRange.prototype["GetRow"] = ApiRange.prototype.GetRow; @@ -6646,6 +6844,13 @@ ApiFont.prototype["GetColor"] = ApiFont.prototype.GetColor; ApiFont.prototype["SetColor"] = ApiFont.prototype.SetColor; + ApiFreezePanes.prototype["FreezeAt"] = ApiFreezePanes.prototype.FreezeAt; + ApiFreezePanes.prototype["FreezeColumns"] = ApiFreezePanes.prototype.FreezeColumns; + ApiFreezePanes.prototype["FreezeRows"] = ApiFreezePanes.prototype.FreezeRows; + ApiFreezePanes.prototype["GetLocation"] = ApiFreezePanes.prototype.GetLocation; + ApiFreezePanes.prototype["Unfreeze"] = ApiFreezePanes.prototype.Unfreeze; + + function private_SetCoords(oDrawing, oWorksheet, nExtX, nExtY, nFromCol, nColOffset, nFromRow, nRowOffset, pos){ oDrawing.x = 0; oDrawing.y = 0; diff --git a/cell/view/WorksheetView.js b/cell/view/WorksheetView.js index d0add60ea6..bd85da3d5d 100644 --- a/cell/view/WorksheetView.js +++ b/cell/view/WorksheetView.js @@ -6278,7 +6278,7 @@ }; /** Для api закрепленных областей */ - WorksheetView.prototype.freezePane = function (type) { + WorksheetView.prototype.freezePane = function (type, c, r) { var t = this; var activeCell = this.model.selectionRange.activeCell.clone(); var onChangeFreezePane = function (isSuccess) { @@ -6292,6 +6292,9 @@ } else if (type === Asc.c_oAscFrozenPaneAddType.firstCol) { col = 1; row = 0; + } else if(type === null && c !== undefined && r !== undefined) { + col = c; + row = r; } else { if (null !== t.topLeftFrozenCell) { col = row = 0; From 92da835021d3af6fa27a5e2137730512bb64a07b Mon Sep 17 00:00:00 2001 From: AlexeyMatveev686 Date: Wed, 4 Oct 2023 16:06:38 +0300 Subject: [PATCH 2/5] [se][builde] Change method "ApiFreezePanes.FreezeAt". --- cell/apiBuilder.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cell/apiBuilder.js b/cell/apiBuilder.js index 6ef0242941..0c2bcc7941 100644 --- a/cell/apiBuilder.js +++ b/cell/apiBuilder.js @@ -6465,11 +6465,7 @@ let bbox = tempRange.range.bbox; let r = bbox.r2 < AscCommon.gc_nMaxRow0 ? bbox.r2 + 1 : bbox.r2; let c = bbox.c2 < AscCommon.gc_nMaxCol0 ? bbox.c2 + 1 : bbox.c2; - let cell = new ApiRange(this.ws.getRange3(r, c, r, c)); - let selection = this.ws.selectionRange.clone(); - cell.Select(); - api.FreezePanes('cell'); - selection.Select(); + api.asc_freezePane(null, c, r); } else { throw(new Error('Invalid parametr "frozenRange".')); } From e8246b7991e92811d7b5373c4ff30f5087b5bc44 Mon Sep 17 00:00:00 2001 From: AlexeyMatveev686 Date: Thu, 5 Oct 2023 11:25:59 +0300 Subject: [PATCH 3/5] [se][builder] Change description for some methods and change methods freeze columns and rows. --- cell/apiBuilder.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cell/apiBuilder.js b/cell/apiBuilder.js index 0c2bcc7941..71525f9bf0 100644 --- a/cell/apiBuilder.js +++ b/cell/apiBuilder.js @@ -82,7 +82,7 @@ * @property {boolean} PrintGridlines - Returns or sets the page PrintGridlines property. * @property {Array} Defnames - Returns an array of the ApiName objects. * @property {Array} Comments - Returns an array of the ApiComment objects. - * @property {ApiFreezePanes} FreezePanes - Returns a freezePanes for a current worsheet. + * @property {ApiFreezePanes} FreezePanes - Returns a freeze Panes for a current worsheet. */ function ApiWorksheet(worksheet) { this.worksheet = worksheet; @@ -907,7 +907,7 @@ }); /** - * Specifies the cell border position. + * Specifies freeze panes type. * @typedef {("row" | "column" | "cell" | null )} FreezePaneType */ @@ -6480,10 +6480,13 @@ */ ApiFreezePanes.prototype.FreezeColumns = function(count) { let api = this.ws.workbook.oApi; + if (count == undefined) count = 0; if (typeof count === 'number' && count > 0 && count <= AscCommon.gc_nMaxCol0) { api.asc_freezePane(null, count, 0); - } else if (!!api.wb.getWorksheet().topLeftFrozenCell) { + } else if (!!api.wb.getWorksheet().topLeftFrozenCell && count === 0) { api.asc_freezePane(undefined); + } else { + throw(new Error('Invalid parameter "count".')) } }; @@ -6496,15 +6499,18 @@ */ ApiFreezePanes.prototype.FreezeRows = function(count) { let api = this.ws.workbook.oApi; + if (count == undefined) count = 0; if (typeof count === 'number' && count > 0 && count <= AscCommon.gc_nMaxRow0) { api.asc_freezePane(null, 0, count); - } else if (!!api.wb.getWorksheet().topLeftFrozenCell) { + } else if (!!api.wb.getWorksheet().topLeftFrozenCell && count === 0) { api.asc_freezePane(undefined); + } else { + throw(new Error('Invalid parameter "count".')) } }; /** - * Freeze the top row or rows of the worksheet in place. + * Gets a range that describes the frozen cells in the active worksheet view. * @memberof ApiFreezePanes * @typeofeditors ["CSE"] * @returns {ApiRange | null} - Returns null if there is no frozen pane. From 5196157084e3d4e63bdf935c14c1c016cb5258f1 Mon Sep 17 00:00:00 2001 From: AlexeyMatveev686 Date: Fri, 6 Oct 2023 17:02:39 +0300 Subject: [PATCH 4/5] [se][builder] Add new method "Api.GetFreezePanesType", new property "Api.FreezePanes". Also rename method "Api.FreezePanes" to "Api.SetFreezePanesType". --- cell/apiBuilder.js | 70 +++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/cell/apiBuilder.js b/cell/apiBuilder.js index 71525f9bf0..0c3bf8a206 100644 --- a/cell/apiBuilder.js +++ b/cell/apiBuilder.js @@ -50,6 +50,7 @@ * @property {ApiWorksheet} ActiveSheet - Returns an object that represents the active sheet. * @property {ApiRange} Selection - Returns an object that represents the selected range. * @property {ApiComment[]} Comments - Returns an array of ApiComment objects. + * @property {FreezePaneType} FreezePanes - Returns or sets a freeze panes type. */ var Api = window["Asc"]["spreadsheet_api"]; @@ -912,34 +913,19 @@ */ /** - * Freeze and unfeeze Panes. + * Sets freeze panes type. * @memberof Api * @typeofeditors ["CSE"] * @param {FreezePaneType} FreezePaneType - The type of freezing ('null' to unfreeze). * @since 7.5.1 */ - Api.prototype.FreezePanes = function(FreezePaneType) { + Api.prototype.SetFreezePanesType = function(FreezePaneType) { if (typeof FreezePaneType === 'string' || FreezePaneType === null) { - let cell = this.wb.getWorksheet().topLeftFrozenCell; //detect current freeze type - let curType = 0; - if (cell) { - let c = cell.getCol0(); - let r = cell.getRow0(); - if (c == 0) { - // hole row - curType = 1; - } else if (r == 0) { - // whole column - curType = 2; - } else { - // cell - curType = 3; - } - } + let curType = this.GetFreezePanesType(); let type = null; - if (FreezePaneType === 'cell' && ( ( curType && curType !== 3 ) || ( !curType ) ) ) { + if (FreezePaneType === 'cell' && ( ( curType && curType !== 'cell' ) || ( !curType ) ) ) { // make unfreeze and freeze then if (curType) this.asc_freezePane(undefined); @@ -947,9 +933,9 @@ type = undefined; } else if (FreezePaneType === null && curType) { type = undefined; - } else if (FreezePaneType === 'row' && curType !== 1) { + } else if (FreezePaneType === 'row' && curType !== 'row') { type = 1; - } else if (FreezePaneType === 'column' && curType !== 2) { + } else if (FreezePaneType === 'column' && curType !== 'column') { type = 2; } @@ -961,6 +947,43 @@ } }; + /** + * Rerutns freeze panes type. + * @memberof Api + * @typeofeditors ["CSE"] + * @returns {FreezePaneType} FreezePaneType - The type of freezing ('null' - if there is no frozen pane). + * @since 7.5.1 + */ + Api.prototype.GetFreezePanesType = function() { + let cell = this.wb.getWorksheet().topLeftFrozenCell; + //detect current freeze type + let curType = null; + if (cell) { + let c = cell.getCol0(); + let r = cell.getRow0(); + if (c == 0) { + // hole row + curType = 'row'; + } else if (r == 0) { + // whole column + curType = 'column'; + } else { + // cell + curType = 'cell'; + } + } + return curType; + }; + + Object.defineProperty(Api.prototype, "FreezePanes", { + get: function () { + return this.GetFreezePanesType(); + }, + set: function(FreezePaneType) { + this.SetFreezePanesType(FreezePaneType); + } + }); + /** * Returns the state of sheet visibility. * @memberof ApiWorksheet @@ -6461,7 +6484,7 @@ let api = this.ws.workbook.oApi; let tempRange = (typeof frozenRange === 'string') ? api.GetRange(frozenRange) : frozenRange; - if (tempRange.range && tempRange.range !== null) { + if (tempRange.range) { let bbox = tempRange.range.bbox; let r = bbox.r2 < AscCommon.gc_nMaxRow0 ? bbox.r2 + 1 : bbox.r2; let c = bbox.c2 < AscCommon.gc_nMaxCol0 ? bbox.c2 + 1 : bbox.c2; @@ -6578,7 +6601,8 @@ Api.prototype["AddComment"] = Api.prototype.AddComment; Api.prototype["GetComments"] = Api.prototype.GetComments; Api.prototype["GetCommentById"] = Api.prototype.GetCommentById; - Api.prototype["FreezePanes"] = Api.prototype.FreezePanes; + Api.prototype["SetFreezePanesType"] = Api.prototype.SetFreezePanesType; + Api.prototype["GetFreezePanesType"] = Api.prototype.GetFreezePanesType; ApiWorksheet.prototype["GetVisible"] = ApiWorksheet.prototype.GetVisible; ApiWorksheet.prototype["SetVisible"] = ApiWorksheet.prototype.SetVisible; From f3e2a6b1aeb6f51bf2ccdcfe9072f59b3d343ea6 Mon Sep 17 00:00:00 2001 From: AlexeyMatveev686 Date: Fri, 6 Oct 2023 17:13:34 +0300 Subject: [PATCH 5/5] [se][builder] Change version for some methods from "7.5.1" to "7.6.0". --- cell/apiBuilder.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cell/apiBuilder.js b/cell/apiBuilder.js index 0c3bf8a206..b0cf6694c9 100644 --- a/cell/apiBuilder.js +++ b/cell/apiBuilder.js @@ -917,7 +917,7 @@ * @memberof Api * @typeofeditors ["CSE"] * @param {FreezePaneType} FreezePaneType - The type of freezing ('null' to unfreeze). - * @since 7.5.1 + * @since 7.6.0 */ Api.prototype.SetFreezePanesType = function(FreezePaneType) { if (typeof FreezePaneType === 'string' || FreezePaneType === null) { @@ -952,7 +952,7 @@ * @memberof Api * @typeofeditors ["CSE"] * @returns {FreezePaneType} FreezePaneType - The type of freezing ('null' - if there is no frozen pane). - * @since 7.5.1 + * @since 7.6.0 */ Api.prototype.GetFreezePanesType = function() { let cell = this.wb.getWorksheet().topLeftFrozenCell; @@ -6478,7 +6478,7 @@ * @memberof ApiFreezePanes * @typeofeditors ["CSE"] * @param {ApiRange | String} frozenRange - A range that represents the cells to be frozen panes. - * @since 7.5.1 + * @since 7.6.0 */ ApiFreezePanes.prototype.FreezeAt = function(frozenRange) { let api = this.ws.workbook.oApi; @@ -6499,7 +6499,7 @@ * @memberof ApiFreezePanes * @typeofeditors ["CSE"] * @param {Number?} [count=0] - Optional number of columns to freeze, or zero to unfreeze all columns. - * @since 7.5.1 + * @since 7.6.0 */ ApiFreezePanes.prototype.FreezeColumns = function(count) { let api = this.ws.workbook.oApi; @@ -6518,7 +6518,7 @@ * @memberof ApiFreezePanes * @typeofeditors ["CSE"] * @param {Number?} [count=0] - Optional number of rows to freeze, or zero to unfreeze all rows. - * @since 7.5.1 + * @since 7.6.0 */ ApiFreezePanes.prototype.FreezeRows = function(count) { let api = this.ws.workbook.oApi; @@ -6537,7 +6537,7 @@ * @memberof ApiFreezePanes * @typeofeditors ["CSE"] * @returns {ApiRange | null} - Returns null if there is no frozen pane. - * @since 7.5.1 + * @since 7.6.0 */ ApiFreezePanes.prototype.GetLocation = function() { let result = null; @@ -6568,7 +6568,7 @@ * Removes all frozen panes in the worksheet. * @memberof ApiFreezePanes * @typeofeditors ["CSE"] - * @since 7.5.1 + * @since 7.6.0 */ ApiFreezePanes.prototype.Unfreeze = function() { if (!!this.ws.workbook.oApi.wb.getWorksheet().topLeftFrozenCell)