ApiWorksheet

new ApiWorksheet()

Class representing a sheet.

Properties

Name Type Description
Visible boolean

Returns or sets the state of sheet visibility.

Active number

Makes the current sheet active.

ActiveCell ApiRange

Returns an object that represents an active cell.

Selection ApiRange

Returns an object that represents the selected range.

Cells ApiRange

Returns ApiRange that represents all the cells on the worksheet (not just the cells that are currently in use).

Rows ApiRange

Returns ApiRange that represents all the cells of the rows range.

Cols ApiRange

Returns ApiRange that represents all the cells of the columns range.

UsedRange ApiRange

Returns ApiRange that represents the used range on the specified worksheet.

Name string

Returns or sets a name of the active sheet.

Index number

Returns a sheet index.

LeftMargin number

Returns or sets the size of the sheet left margin measured in points.

RightMargin number

Returns or sets the size of the sheet right margin measured in points.

TopMargin number

Returns or sets the size of the sheet top margin measured in points.

BottomMargin number

Returns or sets the size of the sheet bottom margin measured in points.

PageOrientation PageOrientation

Returns or sets the page orientation.

PrintHeadings boolean

Returns or sets the page PrintHeadings property.

PrintGridlines boolean

Returns or sets the page PrintGridlines property.

Defnames Array

Returns an array of the ApiName objects.

Comments Array

Returns an array of the ApiComment objects.

FreezePanes ApiFreezePanes

Returns the freeze panes for the current worksheet.

Methods

Name Description
AddChart

Creates a chart of the specified type from the selected data range of the current sheet. Please note that the horizontal and vertical offsets are calculated within the limits of the specified column and row cells only. If this value exceeds the cell width or height, another vertical/horizontal position will be set.

AddDefName

Adds a new name to the current worksheet.

AddImage

Adds an image to the current sheet with the parameters specified.

AddOleObject

Adds an OLE object to the current sheet with the parameters specified.

AddShape

Adds a shape to the current sheet with the parameters specified. Please note that the horizontal and vertical offsets are calculated within the limits of the specified column and row cells only. If this value exceeds the cell width or height, another vertical/horizontal position will be set.

AddWordArt

Adds a Text Art object to the current sheet with the parameters specified.

Delete

Deletes the current worksheet.

FormatAsTable

Formats the selected range of cells from the current sheet as a table (with the first row formatted as a header). As the first row is always formatted as a table header, you need to select at least two rows for the table to be formed correctly.

GetActiveCell

Returns an object that represents an active cell.

GetAllCharts

Returns all charts from the current sheet.

GetAllDrawings

Returns all drawings from the current sheet.

GetAllImages

Returns all images from the current sheet.

GetAllOleObjects

Returns all OLE objects from the current sheet.

GetAllShapes

Returns all shapes from the current sheet.

GetBottomMargin

Returns the bottom margin of the sheet.

GetCells

Returns the ApiRange that represents all the cells on the worksheet (not just the cells that are currently in use).

GetCols

Returns the ApiRange object that represents all the cells on the columns range.

GetComments

Returns an array of ApiComment objects.

GetDefName

Returns the ApiName object by the worksheet name.

GetDefNames

Returns an array of ApiName objects.

GetFreezePanes

Returns the freeze panes from the current worksheet.

GetIndex

Returns a sheet index.

GetLeftMargin

Returns the left margin of the sheet.

GetName

Returns a sheet name.

GetPageOrientation

Returns the page orientation.

GetPrintGridlines

Returns the page PrintGridlines property which specifies whether the current sheet gridlines must be printed or not.

GetPrintHeadings

Returns the page PrintHeadings property which specifies whether the current sheet row/column headings must be printed or not.

GetRange

Returns an object that represents the selected range of the current sheet. Can be a single cell - A1, or cells from a single row - A1:E1, or cells from a single column - A1:A10, or cells from several rows and columns - A1:E10.

GetRangeByNumber

Returns an object that represents the selected range of the current sheet using the row/column coordinates for the cell selection.

GetRightMargin

Returns the right margin of the sheet.

GetRows

Returns the ApiRange object that represents all the cells on the rows range.

GetSelection

Returns an object that represents the selected range.

GetTopMargin

Returns the top margin of the sheet.

GetUsedRange

Returns the ApiRange object that represents the used range on the specified worksheet.

GetVisible

Returns the state of sheet visibility.

Move

Moves the current sheet to another location in the workbook.

ReplaceCurrentImage

Replaces the current image with a new one.

SetActive

Makes the current sheet active.

SetBottomMargin

Sets the bottom margin of the sheet.

SetColumnWidth

Sets the width of the specified column. One unit of column width is equal to the width of one character in the Normal style. For proportional fonts, the width of the character 0 (zero) is used.

SetDisplayGridlines

Specifies whether the current sheet gridlines must be displayed or not.

SetDisplayHeadings

Specifies whether the current sheet row/column headers must be displayed or not.

SetHyperlink

Adds a hyperlink to the specified range.

SetLeftMargin

Sets the left margin of the sheet.

SetName

Sets a name to the current active sheet.

SetPageOrientation

Sets the page orientation.

SetPrintGridlines

Specifies whether the current sheet gridlines must be printed or not.

SetPrintHeadings

Specifies whether the current sheet row/column headers must be printed or not.

SetRightMargin

Sets the right margin of the sheet.

SetRowHeight

Sets the height of the specified row measured in points. A point is 1/72 inch.

SetTopMargin

Sets the top margin of the sheet.

SetVisible

Sets the state of sheet visibility.

Example

Copy code
builder.CreateFile("xlsx");
var oWorksheet = Api.GetActiveSheet();
oWorksheet.SetName("sheet 1");
oWorksheet.GetRange("B1").SetValue("Row 1");
oWorksheet.GetRange("C1").SetValue("Row 2");
oWorksheet.GetRange("D1").SetValue("Row 3");
oWorksheet.GetRange("A2").SetValue("Category 1");
oWorksheet.GetRange("A3").SetValue("Category 2");
oWorksheet.GetRange("A4").SetValue("Category 3");
oWorksheet.GetRange("A5").SetValue("Category 4");
oWorksheet.GetRange("B2").SetValue("4.3");
oWorksheet.GetRange("B3").SetValue("2.5");
oWorksheet.GetRange("B4").SetValue("3.5");
oWorksheet.GetRange("B5").SetValue("4.5");
oWorksheet.GetRange("C2").SetValue("2.4");
oWorksheet.GetRange("C3").SetValue("4.4");
oWorksheet.GetRange("C4").SetValue("1.8");
oWorksheet.GetRange("C5").SetValue("2.8");
oWorksheet.GetRange("D2").SetValue("2");
oWorksheet.GetRange("D3").SetValue("2");
oWorksheet.GetRange("D4").SetValue("3");
oWorksheet.GetRange("D5").SetValue("5");
var oChart = oWorksheet.AddChart("'sheet 1'!$A$1:$D$5", true, "bar", 2, 100 * 36000, 70 * 36000, 0, 2 * 36000, 9, 3 * 36000);
oChart.SetVerAxisTitle("Vertical Title", 10);
oChart.SetHorAxisTitle("Horizontal Title", 11);
oChart.SetLegendPos("right");
oChart.SetShowDataLabels(false, false, true, false);
oChart.SetTitle("Main Chart Title", 13);
var oFill = Api.CreateSolidFill(Api.CreateRGBColor(51, 51, 51));
oChart.SetSeriesFill(oFill, 0, false);
oFill = Api.CreateSolidFill(Api.CreateRGBColor(255, 111, 61));
oChart.SetSeriesFill(oFill, 1, false);
oFill = Api.CreateSolidFill(Api.CreateRGBColor(128, 128, 128));
oChart.SetSeriesFill(oFill, 2, false);
oFill = Api.CreateSolidFill(Api.CreateRGBColor(255, 213, 191));
oChart.SetSeriesFill(oFill, 3, false);
oWorksheet.AddDefName("chart data", "Sheet1!$A$1:$D$5");
oWorksheet.GetRange("A8").SetValue("We defined a name 'chart data' for a range of cells A1:D5.");
oWorksheet.AddImage("https://api.onlyoffice.com/content/img/docbuilder/examples/coordinate_aspects.png", 60 * 36000, 35 * 36000, 5, 2 * 36000, 0, 3 * 36000);
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 213, 191), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 111, 61), 100000);
oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
oWorksheet.AddShape("flowChartOnlineStorage", 60 * 36000, 35 * 36000, oFill, oStroke, 0, 2 * 36000, 25, 3 * 36000);
oWorksheet.FormatAsTable("A1:D5");
builder.SaveFile("xlsx", "ApiWorksheet.xlsx");
builder.CloseFile();

Resulting document