Version

Save(String,WorkbookSaveOptions) Method

Writes the workbook to a file.
Syntax
'Declaration
 
Public Overloads Sub Save( _
   ByVal fileName As String, _
   Optional ByVal saveOptions As WorkbookSaveOptions _
) 
public void Save( 
   string fileName,
   WorkbookSaveOptions saveOptions
)

Parameters

fileName
The file to write the workbook to.
saveOptions
The options to use to save the file or null to use the default options.
Exceptions
ExceptionDescription
System.InvalidOperationExceptionThe workbook has no worksheets in its Worksheets collection.
System.InvalidOperationExceptionNo worksheet in this workbook's Worksheets collection has its DisplayOptionsBase.Visibility set to Visible. At least one worksheet in the workbook must be visible.
System.InvalidOperationExceptionA CustomView in the workbook's CustomViews collection has all worksheets hidden. At least one worksheet must be visible in all custom views.
Remarks

The workbook will be written in the format specified by the CurrentFormat.

The fileName specified should have an extension corresponding to the current format so it can be opened in Microsoft Excel by default (if it is installed).

Note: This method creates a System.IO.FileStream using the FileStream(string, FileMode, FileAccess) overload of the constructor. See the remarks section of this overload to for the exceptions that could be thrown.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also