C# Class Smrf.AppLib.ExcelActiveWorksheetRestorer

Saves and restores the active worksheet of an Excel workbook.
Writing to a worksheet that isn't active causes problems with the selection in Excel. To avoid such problems, use this class to activate the worksheet that needs to be written to and then restore the original active worksheet when you're done writing. The activations are done with Excel's screen updating turned off, so they are not visible to the user.

Call ActivateWorksheet to activate the worksheet that needs to be written to. Call Restore when you're done writing.

If you activate a worksheet by other means but still want to use this class to save and restore the original active worksheet, call to save the active worksheet state and call Restore when you're done writing.

Inheritance: Object
Show file Open project: 2014-sed-team3/term-project Class Usage Examples

Protected Properties

Property Type Description
m_oWorkbook Workbook

Public Methods

Method Description
ActivateWorksheet ( Worksheet worksheet ) : ExcelActiveWorksheetState
ExcelActiveWorksheetRestorer ( Microsoft workbook ) : System

Initializes a new instance of the class.

GetActiveWorksheetState ( ) : ExcelActiveWorksheetState
Restore ( ExcelActiveWorksheetState excelActiveWorksheetState ) : void

Private Methods

Method Description
AssertValid ( ) : void

Method Details

ActivateWorksheet() public method

public ActivateWorksheet ( Worksheet worksheet ) : ExcelActiveWorksheetState
worksheet Worksheet
return ExcelActiveWorksheetState

ExcelActiveWorksheetRestorer() public method

Initializes a new instance of the class.
public ExcelActiveWorksheetRestorer ( Microsoft workbook ) : System
workbook Microsoft /// Workbook containing the worksheet that will be activated. ///
return System

GetActiveWorksheetState() public method

public GetActiveWorksheetState ( ) : ExcelActiveWorksheetState
return ExcelActiveWorksheetState

Restore() public method

public Restore ( ExcelActiveWorksheetState excelActiveWorksheetState ) : void
excelActiveWorksheetState ExcelActiveWorksheetState
return void

Property Details

m_oWorkbook protected property

protected Workbook m_oWorkbook
return Workbook