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..b0cf6694c9 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"]; @@ -82,6 +83,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 freeze Panes for a current worsheet. */ function ApiWorksheet(worksheet) { this.worksheet = worksheet; @@ -355,6 +357,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 +907,83 @@ } }); + /** + * Specifies freeze panes type. + * @typedef {("row" | "column" | "cell" | null )} FreezePaneType + */ + + /** + * Sets freeze panes type. + * @memberof Api + * @typeofeditors ["CSE"] + * @param {FreezePaneType} FreezePaneType - The type of freezing ('null' to unfreeze). + * @since 7.6.0 + */ + Api.prototype.SetFreezePanesType = function(FreezePaneType) { + if (typeof FreezePaneType === 'string' || FreezePaneType === null) { + //detect current freeze type + let curType = this.GetFreezePanesType(); + + let type = null; + if (FreezePaneType === 'cell' && ( ( curType && curType !== 'cell' ) || ( !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 !== 'row') { + type = 1; + } else if (FreezePaneType === 'column' && curType !== 'column') { + type = 2; + } + + if (type !== null) + this.asc_freezePane(type); + + } else { + throw(new Error('Invalid parametr "FreezePaneType".')); + } + }; + + /** + * Rerutns freeze panes type. + * @memberof Api + * @typeofeditors ["CSE"] + * @returns {FreezePaneType} FreezePaneType - The type of freezing ('null' - if there is no frozen pane). + * @since 7.6.0 + */ + 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 @@ -1888,6 +1975,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 +3191,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 +6466,116 @@ } }); + + //------------------------------------------------------------------------------------------------------------------ + // + // 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.6.0 + */ + ApiFreezePanes.prototype.FreezeAt = function(frozenRange) { + let api = this.ws.workbook.oApi; + let tempRange = (typeof frozenRange === 'string') ? api.GetRange(frozenRange) : frozenRange; + + 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; + api.asc_freezePane(null, c, r); + } 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.6.0 + */ + 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 && count === 0) { + api.asc_freezePane(undefined); + } else { + throw(new Error('Invalid parameter "count".')) + } + }; + + /** + * 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.6.0 + */ + 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 && count === 0) { + api.asc_freezePane(undefined); + } else { + throw(new Error('Invalid parameter "count".')) + } + }; + + /** + * 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. + * @since 7.6.0 + */ + 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.6.0 + */ + 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 +6601,8 @@ Api.prototype["AddComment"] = Api.prototype.AddComment; Api.prototype["GetComments"] = Api.prototype.GetComments; Api.prototype["GetCommentById"] = Api.prototype.GetCommentById; + Api.prototype["SetFreezePanesType"] = Api.prototype.SetFreezePanesType; + Api.prototype["GetFreezePanesType"] = Api.prototype.GetFreezePanesType; ApiWorksheet.prototype["GetVisible"] = ApiWorksheet.prototype.GetVisible; ApiWorksheet.prototype["SetVisible"] = ApiWorksheet.prototype.SetVisible; @@ -6432,6 +6655,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 +6870,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;