Commit 735714ed authored by Alexander.Trofimov's avatar Alexander.Trofimov

add method GetActiveCell to api builder ApiWorksheet

parent b8859a32
...@@ -32,317 +32,326 @@ ...@@ -32,317 +32,326 @@
"use strict"; "use strict";
(function(window, builder) { (function (window, builder) {
/** /**
* @global * @global
* @class * @class
* @name Api * @name Api
*/ */
var Api = window["Asc"]["spreadsheet_api"]; var Api = window["Asc"]["spreadsheet_api"];
/** /**
* Class representing a sheet. * Class representing a sheet.
* @constructor * @constructor
*/ */
function ApiWorksheet(worksheet) { function ApiWorksheet(worksheet, worksheetView) {
this.worksheet = worksheet; this.worksheet = worksheet;
} this.worksheetView = worksheetView;
}
/** /**
* Class representing a range. * Class representing a range.
* @constructor * @constructor
*/ */
function ApiRange(range) { function ApiRange(range) {
this.range = range; this.range = range;
} }
/** /**
* Class representing a graphical object. * Class representing a graphical object.
* @constructor * @constructor
*/ */
function ApiDrawing(Drawing) function ApiDrawing(Drawing) {
{ this.Drawing = Drawing;
this.Drawing = Drawing; }
}
/** /**
* This type specifies the types, create charts * This type specifies the types, create charts
* @typedef {("bar" | "barStacked" | "barStackedPercent" | "bar3D" | "barStacked3D" | "barStackedPercent3D" | "barStackedPercent3DPerspective" | "horizontalBar" | "horizontalBarStacked" | "horizontalBarStackedPercent" | "horizontalBar3D" | "horizontalBarStacked3D" | "horizontalBarStackedPercent3D" | "lineNormal" | "lineStacked" | "lineStackedPercent" | "line3D" | "pie" | "pie3D" | "doughnut" | "scatter" | "stock")} ChartType * @typedef {("bar" | "barStacked" | "barStackedPercent" | "bar3D" | "barStacked3D" | "barStackedPercent3D" | "barStackedPercent3DPerspective" | "horizontalBar" | "horizontalBarStacked" | "horizontalBarStackedPercent" | "horizontalBar3D" | "horizontalBarStacked3D" | "horizontalBarStackedPercent3D" | "lineNormal" | "lineStacked" | "lineStackedPercent" | "line3D" | "pie" | "pie3D" | "doughnut" | "scatter" | "stock")} ChartType
*/ */
/** /**
* Class representing a Chart. * Class representing a Chart.
* @constructor * @constructor
* *
*/ */
function ApiChart(Chart) function ApiChart(Chart) {
{ ApiChart.superclass.constructor.call(this, Chart.parent);
ApiChart.superclass.constructor.call(this, Chart.parent); this.Chart = Chart;
this.Chart = Chart; }
}
AscCommon.extendClass(ApiChart, ApiDrawing);
/** AscCommon.extendClass(ApiChart, ApiDrawing);
* Returns an object that represents the active sheet
* @memberof Api
* @returns {ApiWorksheet}
*/
Api.prototype.GetActiveSheet = function() {
return new ApiWorksheet(this.wbModel.getWorksheet(this.wbModel.getActive()));
};
/** /**
* Set sheet name * Returns an object that represents the active sheet
* @memberof ApiWorksheet * @memberof Api
* @param {string} name * @returns {ApiWorksheet}
*/ */
ApiWorksheet.prototype.SetName = function(name) { Api.prototype.GetActiveSheet = function () {
this.worksheet.setName(name); var index = this.wbModel.getActive();
}; return new ApiWorksheet(this.wbModel.getWorksheet(index), this.wb.getWorksheet(index));
};
/** /**
* Returns an object that represents the range * Returns an object that represents the active cell
* @memberof ApiWorksheet * @memberof ApiWorksheet
* @param {string} sRange * @returns {ApiRange}
* @returns {ApiRange} */
*/ ApiWorksheet.prototype.GetActiveCell = function () {
ApiWorksheet.prototype.GetRange = function(sRange) { var ar = this.worksheetView.activeRange;
return new ApiRange(this.worksheet.getRange2(sRange)); return new ApiRange(this.worksheet.getCell3(ar.startRow, ar.startCol));
}; };
/** /**
* Format as table * Set sheet name
* @memberof ApiWorksheet * @memberof ApiWorksheet
* @param {string} sRange * @param {string} name
*/ */
ApiWorksheet.prototype.FormatAsTable = function(sRange) { ApiWorksheet.prototype.SetName = function (name) {
this.worksheet.autoFilters.addAutoFilter('TableStyleLight9', AscCommonExcel.g_oRangeCache.getAscRange(sRange)); this.worksheet.setName(name);
}; };
/** /**
* Set column width * Returns an object that represents the range
* @memberof ApiWorksheet * @memberof ApiWorksheet
* @param {number} column * @param {string} sRange
* @param {number} width * @returns {ApiRange}
*/ */
ApiWorksheet.prototype.SetColumnWidth = function(column, width) { ApiWorksheet.prototype.GetRange = function (sRange) {
this.worksheet.setColWidth(width, column, column); return new ApiRange(this.worksheet.getRange2(sRange));
}; };
/** /**
* Set column width * Format as table
* @memberof ApiWorksheet * @memberof ApiWorksheet
* @param {string} sDataRange * @param {string} sRange
* @param {bool} bInRows */
* @param {ChartType} sType ApiWorksheet.prototype.FormatAsTable = function (sRange) {
* @param {number} nStyleIndex this.worksheet.autoFilters.addAutoFilter('TableStyleLight9', AscCommonExcel.g_oRangeCache.getAscRange(sRange));
* @param {number} nFromCol };
* @param {number} nFromRow
* @param {number} nToCol
* @param {number} nToRow
*/
ApiWorksheet.prototype.AddChart = function(sDataRange, bInRows, sType, nStyleIndex, nFromCol, nFromRow, nToCol, nToRow) {
History.Create_NewPoint(); /**
var settings = new AscCommon.asc_ChartSettings(); * Set column width
switch (sType) * @memberof ApiWorksheet
{ * @param {number} column
case "bar" : * @param {number} width
{ */
settings.type = Asc.c_oAscChartTypeSettings.barNormal; ApiWorksheet.prototype.SetColumnWidth = function (column, width) {
break; this.worksheet.setColWidth(width, column, column);
} };
case "barStacked":
{
settings.type = Asc.c_oAscChartTypeSettings.barStacked;
break;
}
case "barStackedPercent":
{
settings.type = Asc.c_oAscChartTypeSettings.barStackedPer;
break;
}
case "bar3D":
{
settings.type = Asc.c_oAscChartTypeSettings.barNormal3d;
break;
}
case "barStacked3D":
{
settings.type = Asc.c_oAscChartTypeSettings.barStacked3d;
break;
}
case "barStackedPercent3D":
{
settings.type = Asc.c_oAscChartTypeSettings.barStackedPer3d;
break;
}
case "barStackedPercent3DPerspective":
{
settings.type = Asc.c_oAscChartTypeSettings.barNormal3dPerspective;
break;
}
case "horizontalBar":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarNormal;
break;
}
case "horizontalBarStacked":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStacked;
break;
}
case "horizontalBarStackedPercent":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStackedPer;
break;
}
case "horizontalBar3D":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarNormal3d;
break;
}
case "horizontalBarStacked3D":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStacked3d;
break;
}
case "horizontalBarStackedPercent3D":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStackedPer3d;
break;
}
case "lineNormal":
{
settings.type = Asc.c_oAscChartTypeSettings.lineNormal;
break;
}
case "lineStacked":
{
settings.type = Asc.c_oAscChartTypeSettings.lineStacked;
break;
}
case "lineStackedPercent":
{
settings.type = Asc.c_oAscChartTypeSettings.lineStackedPer;
break;
}
case "line3D":
{
settings.type = Asc.c_oAscChartTypeSettings.line3d;
break;
}
case "pie":
{
settings.type = Asc.c_oAscChartTypeSettings.pie;
break;
}
case "pie3D":
{
settings.type = Asc.c_oAscChartTypeSettings.pie3d;
break;
}
case "doughnut":
{
settings.type = Asc.c_oAscChartTypeSettings.doughnut;
break;
}
case "scatter":
{
settings.type = Asc.c_oAscChartTypeSettings.scatter;
break;
}
case "stock":
{
settings.type = Asc.c_oAscChartTypeSettings.stock;
break;
}
}
settings.style = nStyleIndex;
settings.inColumns = !bInRows;
settings.range = sDataRange;
var oChart = AscFormat.DrawingObjectsController.prototype.getChartSpace(this.worksheet, settings);
oChart.setWorksheet(this.worksheet);
oChart.setBFromSerialize(true);
oChart.addToDrawingObjects();
oChart.setDrawingBaseCoords(nFromCol, 0, nFromRow, 0, nToCol, 0, nToRow, 0, 0, 0, 0, 0);
if(AscFormat.isRealNumber(nStyleIndex))
{
oChart.setStyle(nStyleIndex);
}
};
/** /**
* Set cell value * Set column width
* @memberof ApiRange * @memberof ApiWorksheet
* @param {string} val * @param {string} sDataRange
*/ * @param {bool} bInRows
ApiRange.prototype.SetValue = function(val) { * @param {ChartType} sType
this.range.setValue(val); * @param {number} nStyleIndex
}; * @param {number} nFromCol
* @param {number} nFromRow
* @param {number} nToCol
* @param {number} nToRow
*/
ApiWorksheet.prototype.AddChart =
function (sDataRange, bInRows, sType, nStyleIndex, nFromCol, nFromRow, nToCol, nToRow) {
/** History.Create_NewPoint();
* Set text color in the rgb format. var settings = new AscCommon.asc_ChartSettings();
* @param {byte} r switch (sType) {
* @param {byte} g case "bar" :
* @param {byte} b {
*/ settings.type = Asc.c_oAscChartTypeSettings.barNormal;
ApiRange.prototype.SetFontColor = function(r, g, b) { break;
this.range.setFontcolor(new AscCommonExcel.RgbColor((r << 16) + (g << 8) + b)); }
}; case "barStacked":
{
settings.type = Asc.c_oAscChartTypeSettings.barStacked;
break;
}
case "barStackedPercent":
{
settings.type = Asc.c_oAscChartTypeSettings.barStackedPer;
break;
}
case "bar3D":
{
settings.type = Asc.c_oAscChartTypeSettings.barNormal3d;
break;
}
case "barStacked3D":
{
settings.type = Asc.c_oAscChartTypeSettings.barStacked3d;
break;
}
case "barStackedPercent3D":
{
settings.type = Asc.c_oAscChartTypeSettings.barStackedPer3d;
break;
}
case "barStackedPercent3DPerspective":
{
settings.type = Asc.c_oAscChartTypeSettings.barNormal3dPerspective;
break;
}
case "horizontalBar":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarNormal;
break;
}
case "horizontalBarStacked":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStacked;
break;
}
case "horizontalBarStackedPercent":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStackedPer;
break;
}
case "horizontalBar3D":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarNormal3d;
break;
}
case "horizontalBarStacked3D":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStacked3d;
break;
}
case "horizontalBarStackedPercent3D":
{
settings.type = Asc.c_oAscChartTypeSettings.hBarStackedPer3d;
break;
}
case "lineNormal":
{
settings.type = Asc.c_oAscChartTypeSettings.lineNormal;
break;
}
case "lineStacked":
{
settings.type = Asc.c_oAscChartTypeSettings.lineStacked;
break;
}
case "lineStackedPercent":
{
settings.type = Asc.c_oAscChartTypeSettings.lineStackedPer;
break;
}
case "line3D":
{
settings.type = Asc.c_oAscChartTypeSettings.line3d;
break;
}
case "pie":
{
settings.type = Asc.c_oAscChartTypeSettings.pie;
break;
}
case "pie3D":
{
settings.type = Asc.c_oAscChartTypeSettings.pie3d;
break;
}
case "doughnut":
{
settings.type = Asc.c_oAscChartTypeSettings.doughnut;
break;
}
case "scatter":
{
settings.type = Asc.c_oAscChartTypeSettings.scatter;
break;
}
case "stock":
{
settings.type = Asc.c_oAscChartTypeSettings.stock;
break;
}
}
settings.style = nStyleIndex;
settings.inColumns = !bInRows;
settings.range = sDataRange;
var oChart = AscFormat.DrawingObjectsController.prototype.getChartSpace(this.worksheet, settings);
oChart.setWorksheet(this.worksheet);
oChart.setBFromSerialize(true);
oChart.addToDrawingObjects();
oChart.setDrawingBaseCoords(nFromCol, 0, nFromRow, 0, nToCol, 0, nToRow, 0, 0, 0, 0, 0);
if (AscFormat.isRealNumber(nStyleIndex)) {
oChart.setStyle(nStyleIndex);
}
};
/** /**
* Set font size * Set cell value
* @param {number} size * @memberof ApiRange
*/ * @param {string} val
ApiRange.prototype.SetFontSize = function(size) { */
this.range.setFontsize(size); ApiRange.prototype.SetValue = function (val) {
}; this.range.setValue(val);
};
/** /**
* Set font name * Set text color in the rgb format.
* @param {string} name * @param {byte} r
*/ * @param {byte} g
ApiRange.prototype.SetFontName = function(name) { * @param {byte} b
this.range.setFontname(name); */
}; ApiRange.prototype.SetFontColor = function (r, g, b) {
this.range.setFontcolor(new AscCommonExcel.RgbColor((r << 16) + (g << 8) + b));
};
/** /**
* Set align vertical * Set font size
* @param {'center' | 'bottom' | 'top'} value * @param {number} size
*/ */
ApiRange.prototype.SetAlignVertical = function(value) { ApiRange.prototype.SetFontSize = function (size) {
this.range.setAlignVertical(value); this.range.setFontsize(size);
}; };
/** /**
* Set align horizontal * Set font name
* @param {'left' | 'right' | 'center' | 'justify'} value * @param {string} name
*/ */
ApiRange.prototype.SetAlignHorizontal = function(value) { ApiRange.prototype.SetFontName = function (name) {
this.range.setAlignHorizontal(value); this.range.setFontname(name);
}; };
/**
* Set align vertical
* @param {'center' | 'bottom' | 'top'} value
*/
ApiRange.prototype.SetAlignVertical = function (value) {
this.range.setAlignVertical(value);
};
/**
* Set align horizontal
* @param {'left' | 'right' | 'center' | 'justify'} value
*/
ApiRange.prototype.SetAlignHorizontal = function (value) {
this.range.setAlignHorizontal(value);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Export // Export
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Api.prototype["GetActiveSheet"] = Api.prototype.GetActiveSheet; Api.prototype["GetActiveSheet"] = Api.prototype.GetActiveSheet;
ApiWorksheet.prototype["SetName"] = ApiWorksheet.prototype.SetName; ApiWorksheet.prototype["GetActiveCell"] = ApiWorksheet.prototype.GetActiveCell;
ApiWorksheet.prototype["GetRange"] = ApiWorksheet.prototype.GetRange; ApiWorksheet.prototype["SetName"] = ApiWorksheet.prototype.SetName;
ApiWorksheet.prototype["FormatAsTable"] = ApiWorksheet.prototype.FormatAsTable; ApiWorksheet.prototype["GetRange"] = ApiWorksheet.prototype.GetRange;
ApiWorksheet.prototype["SetColumnWidth"] = ApiWorksheet.prototype.SetColumnWidth; ApiWorksheet.prototype["FormatAsTable"] = ApiWorksheet.prototype.FormatAsTable;
ApiWorksheet.prototype["AddChart"] = ApiWorksheet.prototype.AddChart; ApiWorksheet.prototype["SetColumnWidth"] = ApiWorksheet.prototype.SetColumnWidth;
ApiWorksheet.prototype["AddChart"] = ApiWorksheet.prototype.AddChart;
ApiRange.prototype["SetValue"] = ApiRange.prototype.SetValue; ApiRange.prototype["SetValue"] = ApiRange.prototype.SetValue;
ApiRange.prototype["SetFontColor"] = ApiRange.prototype.SetFontColor; ApiRange.prototype["SetFontColor"] = ApiRange.prototype.SetFontColor;
ApiRange.prototype["SetFontSize"] = ApiRange.prototype.SetFontSize; ApiRange.prototype["SetFontSize"] = ApiRange.prototype.SetFontSize;
ApiRange.prototype["SetFontName"] = ApiRange.prototype.SetFontName; ApiRange.prototype["SetFontName"] = ApiRange.prototype.SetFontName;
ApiRange.prototype["SetAlignVertical"] = ApiRange.prototype.SetAlignVertical; ApiRange.prototype["SetAlignVertical"] = ApiRange.prototype.SetAlignVertical;
ApiRange.prototype["SetAlignHorizontal"] = ApiRange.prototype.SetAlignHorizontal; ApiRange.prototype["SetAlignHorizontal"] = ApiRange.prototype.SetAlignHorizontal;
}(window, null)); }(window, null));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment