Class Worksheet

Class Worksheet

Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)

Encapsulates the object that represents a single worksheet.

public class Worksheet : IDisposable

Inheritance

objectWorksheet

Implements

IDisposable

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

The following example shows how to freeze panes and insert hyperlink to worksheet with .Net or VB.

Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

//Freeze panes at "AS40" with 10 rows and 10 columns
sheet.FreezePanes("AS40", 10, 10);

//Add a hyperlink in Cell A1
sheet.Hyperlinks.Add("A1", 1, 1, "http://www.aspose.com");
Dim workbook as Workbook = new Workbook()

Dim sheet as Worksheet = workbook.Worksheets(0)

'Freeze panes at "AS40" with 10 rows and 10 columns
sheet.FreezePanes("AS40", 10, 10)

'Add a hyperlink in Cell A1
sheet.Hyperlinks.Add("A1", 1, 1, "http://www.aspose.com")

Properties

ActiveCell

Gets or sets the active cell in the worksheet.

public string ActiveCell { get; set; }

Property Value

string

AllowEditRanges

Gets the allow edit range collection in the worksheet.

public ProtectedRangeCollection AllowEditRanges { get; }

Property Value

ProtectedRangeCollection

AutoFilter

Represents auto filter for the specified worksheet.

public AutoFilter AutoFilter { get; }

Property Value

AutoFilter

BackgroundImage

Gets and sets worksheet background image.

public byte[] BackgroundImage { get; set; }

Property Value

byte[]

CellWatches

Gets collection of cells on this worksheet being watched in the ‘watch window’.

public CellWatchCollection CellWatches { get; }

Property Value

CellWatchCollection

Cells

Gets the Aspose.Cells.Worksheet.Cells collection.

public Cells Cells { get; }

Property Value

Cells

Charts

Gets a Aspose.Cells.Charts.Chart collection

public ChartCollection Charts { get; }

Property Value

ChartCollection

CheckBoxes

Gets a Aspose.Cells.Drawing.CheckBox collection.

public CheckBoxCollection CheckBoxes { get; }

Property Value

CheckBoxCollection

CodeName

Gets worksheet code name.

public string CodeName { get; set; }

Property Value

string

Comments

Gets the Aspose.Cells.Comment collection.

public CommentCollection Comments { get; }

Property Value

CommentCollection

ConditionalFormattings

Gets the ConditionalFormattings in the worksheet.

public ConditionalFormattingCollection ConditionalFormattings { get; }

Property Value

ConditionalFormattingCollection

CustomProperties

Gets an object representing the identifier information associated with a worksheet.

public CustomPropertyCollection CustomProperties { get; }

Property Value

CustomPropertyCollection

Remarks

Worksheet.CustomProperties provide a preferred mechanism for storing arbitrary data. It supports legacy third-party document components, as well as those situations that have a stringent need for binary parts.

DisplayRightToLeft

Indicates if the specified worksheet is displayed from right to left instead of from left to right. Default is false.

public bool DisplayRightToLeft { get; set; }

Property Value

bool

DisplayZeros

True if zero values are displayed.

public bool DisplayZeros { get; set; }

Property Value

bool

ErrorCheckOptions

Gets error check setting applied on certain ranges.

public ErrorCheckOptionCollection ErrorCheckOptions { get; }

Property Value

ErrorCheckOptionCollection

FirstVisibleColumn

Represents first visible column index.

public int FirstVisibleColumn { get; set; }

Property Value

int

FirstVisibleRow

Represents first visible row index.

public int FirstVisibleRow { get; set; }

Property Value

int

HasAutofilter

Indicates whether this worksheet has auto filter.

public bool HasAutofilter { get; }

Property Value

bool

HorizontalPageBreaks

Gets the Aspose.Cells.HorizontalPageBreakCollection collection.

public HorizontalPageBreakCollection HorizontalPageBreaks { get; }

Property Value

HorizontalPageBreakCollection

Hyperlinks

Gets the Aspose.Cells.HyperlinkCollection collection.

public HyperlinkCollection Hyperlinks { get; }

Property Value

HyperlinkCollection

Index

Gets the index of sheet in the worksheet collection.

public int Index { get; }

Property Value

int

IsGridlinesVisible

Gets or sets a value indicating whether the gridlines are visible.Default is true.

public bool IsGridlinesVisible { get; set; }

Property Value

bool

IsOutlineShown

Indicates whether to show outline.

public bool IsOutlineShown { get; set; }

Property Value

bool

IsPageBreakPreview

Indicates whether the specified worksheet is shown in normal view or page break preview.

public bool IsPageBreakPreview { get; set; }

Property Value

bool

IsProtected

Indicates if the worksheet is protected.

public bool IsProtected { get; }

Property Value

bool

IsRowColumnHeadersVisible

Gets or sets a value indicating whether the worksheet will display row and column headers. Default is true.

public bool IsRowColumnHeadersVisible { get; set; }

Property Value

bool

IsRulerVisible

Indicates whether the ruler is visible. This property is only applied for page break preview.

public bool IsRulerVisible { get; set; }

Property Value

bool

IsSelected

Indicates whether this worksheet is selected when the workbook is opened.

public bool IsSelected { get; set; }

Property Value

bool

IsVisible

Represents if the worksheet is visible.

public bool IsVisible { get; set; }

Property Value

bool

ListObjects

Gets all ListObjects in this worksheet.

public ListObjectCollection ListObjects { get; }

Property Value

ListObjectCollection

Name

Gets or sets the name of the worksheet.

public string Name { get; set; }

Property Value

string

Remarks

The max length of sheet name is 31. And you cannot assign same name(case insensitive) to two worksheets. For example, you cannot set “SheetName1” to the first worksheet and set “SHEETNAME1” to the second worksheet.

OleObjects

Represents a collection of Aspose.Cells.Drawing.OleObject in a worksheet.

public OleObjectCollection OleObjects { get; }

Property Value

OleObjectCollection

Outline

Gets the outline on this worksheet.

public Outline Outline { get; }

Property Value

Outline

PageSetup

Represents the page setup description in this sheet.

public PageSetup PageSetup { get; }

Property Value

PageSetup

PaneState

Indicates whether the pane has horizontal or vertical splits, and whether those splits are frozen.

public PaneStateType PaneState { get; }

Property Value

PaneStateType

Pictures

Gets a Aspose.Cells.Drawing.Picture collection.

public PictureCollection Pictures { get; }

Property Value

PictureCollection

PivotTables

Gets all pivot tables in this worksheet.

public PivotTableCollection PivotTables { get; }

Property Value

PivotTableCollection

Protection

Represents the various types of protection options available for a worksheet. Supports advanced protection options in ExcelXP and above version.

public Protection Protection { get; }

Property Value

Protection

Remarks

This property can protect worksheet in all versions of Excel file and support advanced protection options in ExcelXP and above version.

QueryTables

Gets Aspose.Cells.QueryTableCollection in the worksheet.

public QueryTableCollection QueryTables { get; }

Property Value

QueryTableCollection

Scenarios

Gets the collection of Aspose.Cells.Scenario.

public ScenarioCollection Scenarios { get; }

Property Value

ScenarioCollection

Shapes

Returns all drawing shapes in this worksheet.

public ShapeCollection Shapes { get; }

Property Value

ShapeCollection

ShowFormulas

Indicates whether to show formulas or their results.

public bool ShowFormulas { get; set; }

Property Value

bool

Slicers

Get the Slicer collection in the worksheet

public SlicerCollection Slicers { get; }

Property Value

SlicerCollection

SmartTagSetting

Gets all Aspose.Cells.Markup.SmartTagCollection objects of the worksheet.

public SmartTagSetting SmartTagSetting { get; }

Property Value

SmartTagSetting

SparklineGroups

Gets the sparkline groups in the worksheet.

public SparklineGroupCollection SparklineGroups { get; }

Property Value

SparklineGroupCollection

TabColor

Represents worksheet tab color.

public Color TabColor { get; set; }

Property Value

Color

Remarks

This feature is only supported in ExcelXP(Excel2002) and later versions. If you save file as Excel97 or Excel2000 format, it will be omitted.

TabId

Specifies the internal identifier for the sheet.

public int TabId { get; set; }

Property Value

int

TextBoxes

Gets a Aspose.Cells.Drawing.TextBox collection.

public TextBoxCollection TextBoxes { get; }

Property Value

TextBoxCollection

Timelines

Get the Timeline collection in the worksheet

public TimelineCollection Timelines { get; }

Property Value

TimelineCollection

TransitionEntry

Indicates whether the Transition Formula Entry (Lotus compatibility) option is enabled.

public bool TransitionEntry { get; set; }

Property Value

bool

TransitionEvaluation

Indicates whether the Transition Formula Evaluation (Lotus compatibility) option is enabled.

public bool TransitionEvaluation { get; set; }

Property Value

bool

Type

Represents worksheet type.

public SheetType Type { get; set; }

Property Value

SheetType

UniqueId

Gets and sets the unique id, it is same as {15DB5C3C-A5A1-48AF-8F25-3D86AC232D4F}.

public string UniqueId { get; set; }

Property Value

string

Validations

Gets the data validation setting collection in the worksheet.

public ValidationCollection Validations { get; }

Property Value

ValidationCollection

VerticalPageBreaks

Gets the Aspose.Cells.VerticalPageBreakCollection collection.

public VerticalPageBreakCollection VerticalPageBreaks { get; }

Property Value

VerticalPageBreakCollection

ViewType

Gets and sets the view type.

public ViewType ViewType { get; set; }

Property Value

ViewType

VisibilityType

Indicates the visible state for this sheet.

public VisibilityType VisibilityType { get; set; }

Property Value

VisibilityType

Workbook

Gets the workbook object which contains this sheet.

public Workbook Workbook { get; }

Property Value

Workbook

Zoom

Represents the scaling factor in percentage. It should be between 10 and 400.

public int Zoom { get; set; }

Property Value

int

Remarks

Please set the view type first.

Methods

AddPageBreaks(string)

Adds page break.

public void AddPageBreaks(string cellName)

Parameters

cellName string

AdvancedFilter(bool, string, string, string, bool)

Filters data using complex criteria.

public void AdvancedFilter(bool isFilter, string listRange, string criteriaRange, string copyTo, bool uniqueRecordOnly)

Parameters

isFilter bool

Indicates whether filtering the list in place.

listRange string

The list range.

criteriaRange string

The criteria range.

copyTo string

The range where copying data to.

uniqueRecordOnly bool

Only displaying or copying unique rows.

AutoFitColumn(int, int, int)

Autofits the column width.

public void AutoFitColumn(int columnIndex, int firstRow, int lastRow)

Parameters

columnIndex int

Column index.

firstRow int

First row index.

lastRow int

Last row index.

Remarks

This method autofits a row based on content in a range of cells within the row.

AutoFitColumn(int)

Autofits the column width.

public void AutoFitColumn(int columnIndex)

Parameters

columnIndex int

Column index.

Remarks

AutoFitColumn is an imprecise function.

AutoFitColumns()

Autofits all columns in this worksheet.

public void AutoFitColumns()

AutoFitColumns(AutoFitterOptions)

Autofits all columns in this worksheet.

public void AutoFitColumns(AutoFitterOptions options)

Parameters

options AutoFitterOptions

The auto fitting options

AutoFitColumns(int, int)

Autofits the columns width.

public void AutoFitColumns(int firstColumn, int lastColumn)

Parameters

firstColumn int

First column index.

lastColumn int

Last column index.

Remarks

AutoFitColumn is an imprecise function.

AutoFitColumns(int, int, AutoFitterOptions)

Autofits the columns width.

public void AutoFitColumns(int firstColumn, int lastColumn, AutoFitterOptions options)

Parameters

firstColumn int

First column index.

lastColumn int

Last column index.

options AutoFitterOptions

The auto fitting options

Remarks

AutoFitColumn is an imprecise function.

AutoFitColumns(int, int, int, int)

Autofits the columns width.

public void AutoFitColumns(int firstRow, int firstColumn, int lastRow, int lastColumn)

Parameters

firstRow int

First row index.

firstColumn int

First column index.

lastRow int

Last row index.

lastColumn int

Last column index.

Remarks

AutoFitColumn is an imprecise function.

AutoFitColumns(int, int, int, int, AutoFitterOptions)

Autofits the columns width.

public void AutoFitColumns(int firstRow, int firstColumn, int lastRow, int lastColumn, AutoFitterOptions options)

Parameters

firstRow int

First row index.

firstColumn int

First column index.

lastRow int

Last row index.

lastColumn int

Last column index.

options AutoFitterOptions

The auto fitting options

Remarks

AutoFitColumn is an imprecise function.

AutoFitRow(int, int, int)

Autofits the row height.

public void AutoFitRow(int rowIndex, int firstColumn, int lastColumn)

Parameters

rowIndex int

Row index.

firstColumn int

First column index.

lastColumn int

Last column index.

Remarks

This method autofits a row based on content in a range of cells within the row.

AutoFitRow(int, int, int, AutoFitterOptions)

Autofits the row height.

public void AutoFitRow(int rowIndex, int firstColumn, int lastColumn, AutoFitterOptions options)

Parameters

rowIndex int

Row index.

firstColumn int

First column index.

lastColumn int

Last column index.

options AutoFitterOptions

The auto fitter options

Remarks

This method autofits a row based on content in a range of cells within the row.

AutoFitRow(int, int, int, int)

Autofits row height in a rectangle range.

public void AutoFitRow(int startRow, int endRow, int startColumn, int endColumn)

Parameters

startRow int

Start row index.

endRow int

End row index.

startColumn int

Start column index.

endColumn int

End column index.

AutoFitRow(int)

Autofits the row height.

public void AutoFitRow(int rowIndex)

Parameters

rowIndex int

Row index.

Remarks

AutoFitRow is an imprecise function.

AutoFitRows()

Autofits all rows in this worksheet.

public void AutoFitRows()

AutoFitRows(bool)

Autofits all rows in this worksheet.

public void AutoFitRows(bool onlyAuto)

Parameters

onlyAuto bool

True,only autofits the row height when row height is not customed.

AutoFitRows(AutoFitterOptions)

Autofits all rows in this worksheet.

public void AutoFitRows(AutoFitterOptions options)

Parameters

options AutoFitterOptions

The auto fitter options

AutoFitRows(int, int)

Autofits row height in a range.

public void AutoFitRows(int startRow, int endRow)

Parameters

startRow int

Start row index.

endRow int

End row index.

AutoFitRows(int, int, AutoFitterOptions)

Autofits row height in a range.

public void AutoFitRows(int startRow, int endRow, AutoFitterOptions options)

Parameters

startRow int

Start row index.

endRow int

End row index.

options AutoFitterOptions

The options of auto fitter.

CalculateArrayFormula(string, CalculationOptions)

Calculates a formula as array formula.

public object[][] CalculateArrayFormula(string formula, CalculationOptions opts)

Parameters

formula string

Formula to be calculated.

opts CalculationOptions

Options for calculating formula

Returns

object[][]

CalculateArrayFormula(string, CalculationOptions, int, int)

Calculates a formula as array formula.

public object[][] CalculateArrayFormula(string formula, CalculationOptions opts, int maxRowCount, int maxColumnCount)

Parameters

formula string

Formula to be calculated.

opts CalculationOptions

Options for calculating formula

maxRowCount int

the maximum row count of resultant data. If it is non-positive or greater than the actual row count, then actual row count will be used.

maxColumnCount int

the maximum column count of resultant data. If it is non-positive or greater than the actual row count, then actual column count will be used.

Returns

object[][]

Calculated formula result.

Remarks

The formula will be taken as dynamic array formula to calculate the dimension and result. User specified maximum dimension is used for cases that the calculated result is large data set (for example, the calculated result may correspond to a whole row or column data) but user does not need so large an array according to business requirement or for performance consideration.

CalculateArrayFormula(string, FormulaParseOptions, CalculationOptions, int, int, int, int, CalculationData)

Calculates a formula as array formula.

public object[][] CalculateArrayFormula(string formula, FormulaParseOptions pOpts, CalculationOptions cOpts, int baseCellRow, int baseCellColumn, int maxRowCount, int maxColumnCount, CalculationData calculationData)

Parameters

formula string

Formula to be calculated.

pOpts FormulaParseOptions

Options for parsing formula

cOpts CalculationOptions

Options for calculating formula

baseCellRow int

The row index of the base cell.

baseCellColumn int

The column index of the base cell.

maxRowCount int

The maximum row count of resultant data. If it is non-positive or greater than the actual row count, then actual row count will be used.

maxColumnCount int

The maximum column count of resultant data. If it is non-positive or greater than the actual row count, then actual column count will be used.

calculationData CalculationData

The calculation data. It is used for the situation that user needs to calculate some static formulas when implementing custom calculation engine. For such kind of situation, user needs to specify it with the calculation data provided for Aspose.Cells.AbstractCalculationEngine.Calculate(Aspose.Cells.CalculationData).

Returns

object[][]

Calculated formula result.

Remarks

The formula will be taken as dynamic array formula to calculate the dimension and result. User specified maximum dimension is used for cases that the calculated result is large data set (for example, the calculated result may correspond to a whole row or column data) but user does not need so large an array according to business requirement or for performance consideration.

CalculateFormula(string)

Calculates a formula.

public object CalculateFormula(string formula)

Parameters

formula string

Formula to be calculated.

Returns

object

Calculated formula result.

CalculateFormula(string, CalculationOptions)

Calculates a formula expression directly.

public object CalculateFormula(string formula, CalculationOptions opts)

Parameters

formula string

Formula to be calculated.

opts CalculationOptions

Options for calculating formula

Returns

object

Calculated result of given formula. The returned object may be of possible types of Aspose.Cells.Cell.Value, or ReferredArea.

Remarks

The formula will be calculated just like it has been set to cell A1. And the formula will be taken as normal formula. If you need the formula be calculated as an array formula and to get an array for the calculated result, please use Aspose.Cells.Worksheet.CalculateArrayFormula(System.String,Aspose.Cells.CalculationOptions) instead.

CalculateFormula(string, FormulaParseOptions, CalculationOptions, int, int, CalculationData)

Calculates a formula expression directly.

public object CalculateFormula(string formula, FormulaParseOptions pOpts, CalculationOptions cOpts, int baseCellRow, int baseCellColumn, CalculationData calculationData)

Parameters

formula string

Formula to be calculated.

pOpts FormulaParseOptions

Options for parsing formula.

cOpts CalculationOptions

Options for calculating formula.

baseCellRow int

The row index of the base cell.

baseCellColumn int

The column index of the base cell.

calculationData CalculationData

The calculation data. It is used for the situation that user needs to calculate some static formulas when implementing custom calculation engine. For such kind of situation, user needs to specify it with the calculation data provided for Aspose.Cells.AbstractCalculationEngine.Calculate(Aspose.Cells.CalculationData).

Returns

object

Calculated result of given formula. The returned object may be of possible types of Aspose.Cells.Cell.Value, or ReferredArea.

Remarks

The formula will be calculated just like it has been set to the specified base cell. And the formula will be taken as normal formula. If you need the formula be calculated as an array formula and to get an array for the calculated result, please use Aspose.Cells.Worksheet.CalculateArrayFormula(System.String,Aspose.Cells.FormulaParseOptions,Aspose.Cells.CalculationOptions,System.Int32,System.Int32,System.Int32,System.Int32,Aspose.Cells.CalculationData) instead.

CalculateFormula(CalculationOptions, bool)

Calculates all formulas in this worksheet.

public void CalculateFormula(CalculationOptions options, bool recursive)

Parameters

options CalculationOptions

Options for calculation

recursive bool

True means if the worksheet’ cells depend on the cells of other worksheets, the dependent cells in other worksheets will be calculated too. False means all the formulas in the worksheet have been calculated and the values are right.

ClearComments()

Clears all comments in designer spreadsheet.

public void ClearComments()

CloseAccessCache(AccessCacheOptions)

Closes the session that uses caches to access the data in this worksheet.

public void CloseAccessCache(AccessCacheOptions opts)

Parameters

opts AccessCacheOptions

options of data access

ConvertFormulaReferenceStyle(string, bool, int, int)

Converts the formula reference style.

public string ConvertFormulaReferenceStyle(string formula, bool toR1C1, int baseCellRow, int baseCellColumn)

Parameters

formula string

The formula to be converted.

toR1C1 bool

Which reference style to convert the formula to. If the original formula is of A1 reference style, then this value should be true so the formula will be converted from A1 to R1C1 reference style; If the original formula is of R1C1 reference style, then this value should be false so the formula will be converted from R1C1 to A1 reference style;

baseCellRow int

The row index of the base cell.

baseCellColumn int

The column index of the base cell.

Returns

string

The converted formula.

Copy(Worksheet)

Copies contents and formats from another worksheet.

public void Copy(Worksheet sourceSheet)

Parameters

sourceSheet Worksheet

Source worksheet.

Copy(Worksheet, CopyOptions)

Copies contents and formats from another worksheet.

public void Copy(Worksheet sourceSheet, CopyOptions copyOptions)

Parameters

sourceSheet Worksheet

Source worksheet.

copyOptions CopyOptions

Remarks

You can copy data from another worksheet in the same file or another file. However, this method does not support to copy drawing objects, such as comments, images and charts.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

FreezePanes(int, int, int, int)

Freezes panes at the specified cell in the worksheet.

public void FreezePanes(int row, int column, int freezedRows, int freezedColumns)

Parameters

row int

Row index.

column int

Column index.

freezedRows int

Number of visible rows in top pane, no more than row index.

freezedColumns int

Number of visible columns in left pane, no more than column index.

Remarks

Row index and column index cannot all be zero. Number of rows and number of columns also cannot all be zero.

The first two parameters specify the froze position and the last two parameters specify the area frozen on the left top pane.

FreezePanes(string, int, int)

Freezes panes at the specified cell in the worksheet.

public void FreezePanes(string cellName, int freezedRows, int freezedColumns)

Parameters

cellName string

Cell name.

freezedRows int

Number of visible rows in top pane, no more than row index.

freezedColumns int

Number of visible columns in left pane, no more than column index.

Remarks

Row index and column index cannot all be zero. Number of rows and number of columns also cannot all be zero.

GetAdvancedFilter()

Gets the settings of advanced filter.

public AdvancedFilter GetAdvancedFilter()

Returns

AdvancedFilter

GetFreezedPanes(out int, out int, out int, out int)

Gets the freeze panes.

public bool GetFreezedPanes(out int row, out int column, out int freezedRows, out int freezedColumns)

Parameters

row int

Row index.

column int

Column index.

freezedRows int

Number of visible rows in top pane, no more than row index.

freezedColumns int

Number of visible columns in left pane, no more than column index.

Returns

bool

Return whether the worksheet is frozen

GetPanes()

Gets the window panes.

public PaneCollection GetPanes()

Returns

PaneCollection

Remarks

If the window is not split or frozen.

GetPrintingPageBreaks(ImageOrPrintOptions)

Gets automatic page breaks.

public CellArea[] GetPrintingPageBreaks(ImageOrPrintOptions options)

Parameters

options ImageOrPrintOptions

The print options

Returns

CellArea[]

The automatic page breaks areas.

Remarks

Each cell area represents a paper.

GetSelectedRanges()

Gets selected ranges of cells in the designer spreadsheet.

public ArrayList GetSelectedRanges()

Returns

ArrayList

An System.Collections.ArrayList which contains selected ranges.

MoveTo(int)

Moves the sheet to another location in the spreadsheet.

public void MoveTo(int index)

Parameters

index int

Destination sheet index.

Protect(ProtectionType)

Protects worksheet.

public void Protect(ProtectionType type)

Parameters

type ProtectionType

Protection type.

Remarks

This method protects worksheet without password. It can protect worksheet in all versions of Excel file.

Protect(ProtectionType, string, string)

Protects worksheet.

public void Protect(ProtectionType type, string password, string oldPassword)

Parameters

type ProtectionType

Protection type.

password string

Password.

oldPassword string

If the worksheet is already protected by a password, please supply the old password. Otherwise, you can set a null value or blank string to this parameter.

Examples

//Instantiating a Workbook object
Workbook excel = new Workbook("template.xlsx");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = excel.Worksheets[0];
//Protecting the worksheet with a password
worksheet.Protect(ProtectionType.All, "aspose", null);
//Saving the modified Excel file in default (that is Excel 20003) format
excel.Save("output.xls");
//Closing the file stream to free all resources
'Creating a file stream containing the Excel file to be opened
Dim fstream As FileStream = New FileStream("book1.xls", FileMode.Open)
'Instantiating a Workbook object and Opening the Excel file through the file stream
Dim excel As Workbook = New Workbook(fstream)
'Accessing the first worksheet in the Excel file
Dim worksheet As Worksheet = excel.Worksheets(0)
'Protecting the worksheet with a password
worksheet.Protect(ProtectionType.All, "aspose", DBNull.Value.ToString())
'Saving the modified Excel file in default (that is Excel 20003) format
excel.Save("output.xls")
'Closing the file stream to free all resources
fstream.Close()

Remarks

This method can protect worksheet in all versions of Excel file.

RefreshPivotTables()

Refreshes all the PivotTables in this Worksheet.

public void RefreshPivotTables()

RefreshPivotTables(PivotTableRefreshOption)

Refreshes all the PivotTables in this Worksheet.

public bool RefreshPivotTables(PivotTableRefreshOption option)

Parameters

option PivotTableRefreshOption

The option for refreshing data source of pivot table.

Returns

bool

RemoveAllDrawingObjects()

Removes all drawing objects in this worksheet.

public void RemoveAllDrawingObjects()

RemoveAutoFilter()

Removes the auto filter of the worksheet.

public void RemoveAutoFilter()

RemoveSplit()

Removes split window.

public void RemoveSplit()

Replace(string, string)

Replaces all cells’ text with a new string.

public int Replace(string oldString, string newString)

Parameters

oldString string

Old string value.

newString string

New string value.

Returns

int

SelectRange(int, int, int, int, bool)

Selects a range.

public void SelectRange(int startRow, int startColumn, int totalRows, int totalColumns, bool removeOthers)

Parameters

startRow int

The start row.

startColumn int

The start column

totalRows int

The number of rows.

totalColumns int

The number of columns

removeOthers bool

True means removing other selected range and only select this range.

SetVisible(bool, bool)

Sets the visible options.

public void SetVisible(bool isVisible, bool ignoreError)

Parameters

isVisible bool

Whether the worksheet is visible

ignoreError bool

Whether to ignore error if this option is not valid.

Split()

Splits window.

public void Split()

StartAccessCache(AccessCacheOptions)

Starts the session that uses caches to access the data in this worksheet.

public void StartAccessCache(AccessCacheOptions opts)

Parameters

opts AccessCacheOptions

options of data access

Remarks

After finishing the access to the data, Aspose.Cells.Worksheet.CloseAccessCache(Aspose.Cells.AccessCacheOptions) should be invoked with same options to clear all caches and recover normal access mode.

ToString()

Returns a string represents the current Worksheet object.

public override string ToString()

Returns

string

UnFreezePanes()

Unfreezes panes in the worksheet.

public void UnFreezePanes()

Unprotect()

Unprotects worksheet.

public void Unprotect()

Remarks

This method unprotects worksheet which is protected without password.

Unprotect(string)

Unprotects worksheet.

public void Unprotect(string password)

Parameters

password string

Password

Remarks

If the worksheet is protected without a password, you can set a null value or blank string to password parameter.

XmlMapQuery(string, XmlMap)

Query cell areas that mapped/linked to the specific path of xml map.

public ArrayList XmlMapQuery(string path, XmlMap xmlMap)

Parameters

path string

xml element path

xmlMap XmlMap

Specify an xml map if you want to query for the specific path within a specific map

Returns

ArrayList

Aspose.Cells.CellArea list that mapped/linked to the specific path of xml map, an empty list is returned if nothing is mapped/linked.