Get Started
Usage API
More information

ApiWorksheet

new ApiWorksheet()

Class representing a sheet.

Properties

Name Type Description
Visible bool

Returns or sets the state of sheet visibility.

Active number

Makes the current sheet the active sheet.

ActiveCell ApiRange

Returns an object that represents the active cell.

Selection ApiRange

Returns an object that represents the selection 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 bool

Returns or sets the page PrintHeadings property.

PrintGridlines bool

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.

Methods

Name Description
AddChart

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

AddDefName

Define a new name for a range of cells.

AddImage

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

AddShape

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

Delete

Delete an ApiWorksheet object.

FormatAsTable

Format 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

Return an object that represents the active cell.

GetBottomMargin

Get the bottom margin of the sheet.

GetCells

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

GetCols

Return an ApiRange that represents all the cells on the columns range.

GetComments

Return an ApiComment.

GetDefName

Return an ApiName.

GetDefNames

Return an array of ApiName objects.

GetIndex

Get a sheet index.

GetLeftMargin

Get the left margin of the sheet.

GetName

Get a sheet name.

GetPageOrientation

Get the page orientation

GetPrintGridlines

Get the page PrintGridlines property.

GetPrintHeadings

Get the page PrintHeadings property.

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

Get the right margin of the sheet.

GetRows

Return an ApiRange that represents all the cells on the rows range.

GetSelection

Return an object that represents the selected range.

GetTopMargin

Get the top margin of the sheet.

GetUsedRange

Return an ApiRange that represents the used range on the specified worksheet.

GetVisible

Return the state of sheet visibility.

ReplaceCurrentImage

Replace current image.

SetActive

Make the current sheet the active sheet.

SetBottomMargin

Set the bottom margin of the sheet.

SetColumnWidth

Set the width of the specified columns. 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

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

SetDisplayHeadings

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

SetHyperlink

Add a hyperlink to the specified range.

SetLeftMargin

Set the left margin of the sheet.

SetName

Set a name to the current active sheet.

SetPageOrientation

Set the page orientation.

SetPrintGridlines

Set the page PrintGridlines property.

SetPrintHeadings

Set the page PrintHeadings property.

SetRightMargin

Set the right margin of the sheet.

SetRowHeight

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

SetTopMargin

Set the top margin of the sheet.

SetVisible

Set the state of sheet visibility.

Example

Copy code
builder.CreateFile("xlsx");
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");
oChart = oWorksheet.AddChart("'sheet 1'!$A$1:$D$5", true, "bar", 2, 5, 0, 12, 12);
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);
builder.SaveFile("xlsx", "AddChart.xlsx");
builder.CloseFile();

Resulting document