Daniel's XL Toolbox NG
XLToolbox.Excel.ViewModels.Instance Class Reference

Provide access to an instance of Excel that the components are to work with. More...

Inheritance diagram for XLToolbox.Excel.ViewModels.Instance:
Collaboration diagram for XLToolbox.Excel.ViewModels.Instance:

Public Member Functions

Workbook CreateWorkbook ()
 Creates and returns a new workbook containing exactly one worksheet. More...
 
Workbook CreateWorkbook (int numberOfSheets)
 Creates a workbook containing the specified number of sheets (not less than 1). More...
 
Workbook LocateWorkbook (string name)
 Locates a workbook and returns it. If the workbook is loaded already, it will not be re-opened. If the workbook cannot be located, this method returns null. More...
 
Worksheet LocateWorksheet (Workbook workbook, string name)
 Locates a worksheet in a given workbook. More...
 
void DisableScreenUpdating ()
 Disables screen updating. Increases an internal counter to be able to handle cascading calls to this method. More...
 
void EnableScreenUpdating ()
 Decreases the internal screen updating counter by one; if the counter reaches 0, the application's screen updating will resume. More...
 
void DisableDisplayAlerts ()
 Disables displaying of user alerts. Increases an internal counter to be able to handle cascading calls to this method. More...
 
void EnableDisplayAlerts ()
 Decreases the internal screen updating counter by one; if the counter reaches 0, the application's display of user alerts will be turned on again (in fact, it will be reset to its original state). More...
 
void Reset ()
 Debug method to reset the Excel application. The result is an application without open workbooks. More...
 
Workbook FindWorkbook (string workbookName)
 Fetches a workbook if it is opened. If no workbook is found by the given name, this function returns null. Unlike the LocateWorkbook method, this method will not open a workbook that is currently not loaded. More...
 
AddIn FindAddIn (string addInName)
 Fetches an add-in if it is opened. If no add-in is found by the given name, this function returns null. More...
 
bool IsWorkbookLoaded (string workbookName)
 Returns true if a workbook is opened. More...
 
bool IsAddInLoaded (string addInName)
 Returns true if an add-in is loaded. More...
 
void Quit ()
 Quits the current instance of Excel; no warning message will be shown. More...
 
void ClearPivotCache ()
 
 Instance ()
 Instantiates this class without an Excel instance More...
 
 Instance (Application application)
 Creates a new instance using application as Excel instance. More...
 
void Dispose ()
 
override object RevealModelObject ()
 Returns the model object that this view model wraps or null if there is no wrapped model object. More...
 
- Public Member Functions inherited from Bovender.Mvvm.ViewModels.ViewModelBase
bool IsViewModelOf (object model)
 Determines whether the current object is a view model of a particular model object. Returns false if either the model or the viewmodel's wrapped model object is null. More...
 
Window InjectInto< T > ()
 Injects the ViewModel into a newly created View and wires the RequestCloseView event. More...
 
Window InjectInto (Window view)
 Injects the view model into an existing view by setting the view's DataContext. More...
 
void InjectAndShowInThread< T > (IntPtr ownerForm)
 Creates a new thread that creates a new instance of the view T , sets its Forms owner and shows it modelessly. Use this to show views during asynchronous operations. More...
 
void InjectAndShowInThread< T > ()
 Creates a new thread that creates a new instance of the view T and shows it modelessly. Use this to show views during asynchronous operations. More...
 
void InjectAndShowDialogInThread< T > (IntPtr ownerForm)
 Creates a new thread that creates a new instance of the view T and shows it as a dialog. Use this to show dialogs during asynchronous operations. More...
 
bool IsViewModelOf (object model)
 Determines whether the current object is a view model of a particular model object. Returns false if either the model or the viewmodel's wrapped model object is null. More...
 
Window InjectInto< T > ()
 Injects the ViewModel into a newly created View and wires the RequestCloseView event. More...
 
Window InjectInto (Window view)
 Injects the view model into an existing view by setting the view's DataContext. More...
 
void InjectAndShowInThread< T > (IntPtr ownerForm)
 Creates a new thread that creates a new instance of the view T , sets its Forms owner and shows it modelessly. Use this to show views during asynchronous operations. More...
 
void InjectAndShowInThread< T > ()
 Creates a new thread that creates a new instance of the view T and shows it modelessly. Use this to show views during asynchronous operations. More...
 
void InjectAndShowDialogInThread< T > (IntPtr ownerForm)
 Creates a new thread that creates a new instance of the view T and shows it as a dialog. Use this to show dialogs during asynchronous operations. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 
- Protected Member Functions inherited from Bovender.Mvvm.ViewModels.ViewModelBase
virtual void OnPropertyChanged (string propertyName)
 
virtual bool CanCloseView ()
 
virtual void DoCloseView ()
 
 ViewModelBase ()
 Does not allow public instantiation of this class. More...
 
virtual void OnPropertyChanged (string propertyName)
 
virtual bool CanCloseView ()
 
virtual void DoCloseView ()
 
 ViewModelBase ()
 Does not allow public instantiation of this class. More...
 

Properties

static Instance Default [get, set]
 
DelegatingCommand QuitInteractivelyCommand [get]
 
DelegatingCommand QuitSavingChangesCommand [get]
 
DelegatingCommand QuitDiscardingChangesCommand [get]
 
Message< MessageContentConfirmQuitSavingChangesMessage [get]
 
Message< MessageContentConfirmQuitDiscardingChangesMessage [get]
 
Application Application [get]
 
Workbooks Workbooks [get]
 Gets the Application's Workbooks collection. The underlying COM object is automatically released when the Instance object is disposed. More...
 
Workbook ActiveWorkbook [get]
 
string ActivePath [get]
 Returns the active path. This is either the path of the active workbook, or the current working directory. More...
 
int MajorVersion [get]
 Gets the major version number of the Excel instance as an integer. More...
 
string HumanFriendlyVersion [get]
 Gets the Excel version and build number in a human-friendly form. More...
 
int CountOpenWorkbooks [get]
 
int CountUnsavedWorkbooks [get]
 
int CountSavedWorkbooks [get]
 
bool IsSingleDocumentInterface [get]
 Gets whether the current Excel instance has an SDI (Excel 2013+) or not (Excel 2007/2010). More...
 
- Properties inherited from Bovender.Mvvm.ViewModels.ViewModelBase
ICommand CloseViewCommand [get]
 
virtual string DisplayString [get, set]
 
bool IsSelected [get, set]
 
Dispatcher ViewDispatcher [get, set]
 
Dispatcher Dispatcher [get]
 Captures the dispatcher of the thread that the object was created in. More...
 

Events

EventHandler< InstanceShutdownEventArgsShuttingDown
 
- Events inherited from Bovender.Mvvm.ViewModels.ViewModelBase
EventHandler RequestCloseView
 Raised by the CloseView Command, signals that associated views are to be closed. More...
 
PropertyChangedEventHandler PropertyChanged
 

Detailed Description

Provide access to an instance of Excel that the components are to work with.

This class uses static fields to make sure only one instance of Excel is invoked. An internal counter records the number of class instances that are currently in use; when the last instance of this class is disposed of, the Excel instance will be closed.

Note that this class will only reference one single Excel instance, regardless whether this was started using a static method or by instantiating the class. Thus, there is no instance property to access the Exce instance, just the static property. Instantiating this class mainly serves the purpose of being able to automatically close Excel when the work is done by using Using() structures.

Constructor & Destructor Documentation

◆ Instance() [1/2]

XLToolbox.Excel.ViewModels.Instance.Instance ( )
inline

Instantiates this class without an Excel instance

◆ Instance() [2/2]

XLToolbox.Excel.ViewModels.Instance.Instance ( Application  application)
inline

Creates a new instance using application as Excel instance.

Parameters
applicationExcel instance.

Member Function Documentation

◆ ClearPivotCache()

void XLToolbox.Excel.ViewModels.Instance.ClearPivotCache ( )
inline

◆ CreateWorkbook() [1/2]

Workbook XLToolbox.Excel.ViewModels.Instance.CreateWorkbook ( )
inline

Creates and returns a new workbook containing exactly one worksheet.

Returns
Workbook with only one worksheet.

◆ CreateWorkbook() [2/2]

Workbook XLToolbox.Excel.ViewModels.Instance.CreateWorkbook ( int  numberOfSheets)
inline

Creates a workbook containing the specified number of sheets (not less than 1).

If numberOfSheets is less than 1, the workbook will still contain one worksheet.

Parameters
numberOfSheetsNumber of sheets in the new workbook.
Returns
Workbook containing the specified number of sheets (not less than 1).

◆ DisableDisplayAlerts()

void XLToolbox.Excel.ViewModels.Instance.DisableDisplayAlerts ( )
inline

Disables displaying of user alerts. Increases an internal counter to be able to handle cascading calls to this method.

◆ DisableScreenUpdating()

void XLToolbox.Excel.ViewModels.Instance.DisableScreenUpdating ( )
inline

Disables screen updating. Increases an internal counter to be able to handle cascading calls to this method.

◆ Dispose() [1/2]

void XLToolbox.Excel.ViewModels.Instance.Dispose ( )
inline

◆ Dispose() [2/2]

virtual void XLToolbox.Excel.ViewModels.Instance.Dispose ( bool  disposing)
inlineprotectedvirtual

◆ EnableDisplayAlerts()

void XLToolbox.Excel.ViewModels.Instance.EnableDisplayAlerts ( )
inline

Decreases the internal screen updating counter by one; if the counter reaches 0, the application's display of user alerts will be turned on again (in fact, it will be reset to its original state).

◆ EnableScreenUpdating()

void XLToolbox.Excel.ViewModels.Instance.EnableScreenUpdating ( )
inline

Decreases the internal screen updating counter by one; if the counter reaches 0, the application's screen updating will resume.

◆ FindAddIn()

AddIn XLToolbox.Excel.ViewModels.Instance.FindAddIn ( string  addInName)
inline

Fetches an add-in if it is opened. If no add-in is found by the given name, this function returns null.

Parameters
addInNameAdd-in to fetch.
Returns
Workbook or null.

◆ FindWorkbook()

Workbook XLToolbox.Excel.ViewModels.Instance.FindWorkbook ( string  workbookName)
inline

Fetches a workbook if it is opened. If no workbook is found by the given name, this function returns null. Unlike the LocateWorkbook method, this method will not open a workbook that is currently not loaded.

Parameters
workbookNameWorkbook to fetch.
Returns
Workbook or null.

◆ IsAddInLoaded()

bool XLToolbox.Excel.ViewModels.Instance.IsAddInLoaded ( string  addInName)
inline

Returns true if an add-in is loaded.

Parameters
workbookNameAdd-in name to query.
Returns
True if the add-in is loaded.

◆ IsWorkbookLoaded()

bool XLToolbox.Excel.ViewModels.Instance.IsWorkbookLoaded ( string  workbookName)
inline

Returns true if a workbook is opened.

Parameters
addInNameWorkbook name to query.
Returns
True if the workbook is opened.

◆ LocateWorkbook()

Workbook XLToolbox.Excel.ViewModels.Instance.LocateWorkbook ( string  name)
inline

Locates a workbook and returns it. If the workbook is loaded already, it will not be re-opened. If the workbook cannot be located, this method returns null.

Parameters
nameName (either bare name or full name with path) of the workbook being sought. If this is null or whitespace, the active workbook is returned.
Returns
Workbook or null

◆ LocateWorksheet()

Worksheet XLToolbox.Excel.ViewModels.Instance.LocateWorksheet ( Workbook  workbook,
string  name 
)
inline

Locates a worksheet in a given workbook.

Parameters
workbookWorkbook in which to look for the worksheet. If this is null, the active workbook is used.
nameName of the worksheet.
Returns
Worksheet or null if no worksheet by this name exists.

◆ Quit()

void XLToolbox.Excel.ViewModels.Instance.Quit ( )
inline

Quits the current instance of Excel; no warning message will be shown.

◆ Reset()

void XLToolbox.Excel.ViewModels.Instance.Reset ( )
inline

Debug method to reset the Excel application. The result is an application without open workbooks.

◆ RevealModelObject()

override object XLToolbox.Excel.ViewModels.Instance.RevealModelObject ( )
inlinevirtual

Returns the model object that this view model wraps or null if there is no wrapped model object.

This is a method rather than a property to make data binding more difficult (if not impossible), because binding directly to the model object is discouraged. However, certain users such as a ViewModelCollection might need access to the wrapped model object.

Returns
Model object.

Implements Bovender.Mvvm.ViewModels.ViewModelBase.

Property Documentation

◆ ActivePath

string XLToolbox.Excel.ViewModels.Instance.ActivePath
get

Returns the active path. This is either the path of the active workbook, or the current working directory.

If a workbook is opened as in Protected View and is the only open workbook, Application.ActiveWorkbook will be null. Therefore this helper property was invented.

◆ ActiveWorkbook

Workbook XLToolbox.Excel.ViewModels.Instance.ActiveWorkbook
get

◆ Application

Application XLToolbox.Excel.ViewModels.Instance.Application
get

◆ ConfirmQuitDiscardingChangesMessage

Message<MessageContent> XLToolbox.Excel.ViewModels.Instance.ConfirmQuitDiscardingChangesMessage
get

◆ ConfirmQuitSavingChangesMessage

Message<MessageContent> XLToolbox.Excel.ViewModels.Instance.ConfirmQuitSavingChangesMessage
get

◆ CountOpenWorkbooks

int XLToolbox.Excel.ViewModels.Instance.CountOpenWorkbooks
get

◆ CountSavedWorkbooks

int XLToolbox.Excel.ViewModels.Instance.CountSavedWorkbooks
get

◆ CountUnsavedWorkbooks

int XLToolbox.Excel.ViewModels.Instance.CountUnsavedWorkbooks
get

◆ Default

Instance XLToolbox.Excel.ViewModels.Instance.Default
staticgetset

◆ HumanFriendlyVersion

string XLToolbox.Excel.ViewModels.Instance.HumanFriendlyVersion
get

Gets the Excel version and build number in a human-friendly form.

See http://spreadsheetpage.com/index.php/resource/excel_version_history and http://blog.pathtosharepoint.com/2014/05/06/how-to-get-your-office-365-version-number/

Parameters
excelExcel application whose version information to to retrieve.
Returns
String in the form of "2003", "2010 SP1" and so on.

◆ IsSingleDocumentInterface

bool XLToolbox.Excel.ViewModels.Instance.IsSingleDocumentInterface
get

Gets whether the current Excel instance has an SDI (Excel 2013+) or not (Excel 2007/2010).

◆ MajorVersion

int XLToolbox.Excel.ViewModels.Instance.MajorVersion
get

Gets the major version number of the Excel instance as an integer.

◆ QuitDiscardingChangesCommand

DelegatingCommand XLToolbox.Excel.ViewModels.Instance.QuitDiscardingChangesCommand
get

◆ QuitInteractivelyCommand

DelegatingCommand XLToolbox.Excel.ViewModels.Instance.QuitInteractivelyCommand
get

◆ QuitSavingChangesCommand

DelegatingCommand XLToolbox.Excel.ViewModels.Instance.QuitSavingChangesCommand
get

◆ Workbooks

Workbooks XLToolbox.Excel.ViewModels.Instance.Workbooks
get

Gets the Application's Workbooks collection. The underlying COM object is automatically released when the Instance object is disposed.

Event Documentation

◆ ShuttingDown

EventHandler<InstanceShutdownEventArgs> XLToolbox.Excel.ViewModels.Instance.ShuttingDown

The documentation for this class was generated from the following file: