[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IWorkbook.Save

Save Method

Save(string)

Saves the workbook to disk.

Declaration
void Save(string fileName)
Sub Save(fileName As String)
Parameters
Type Name Description
string fileName

The path of the destination file.

Examples
worksheet.Range["A1:B2"].Value = new object[,] {
    {"Name", "Value"},
    {"Test", 100}
};
workbook.Save(Path.Combine(Environment.CurrentDirectory, "SalesReport.xlsx"));

Save(string, string, SaveOptions)

Saves the workbook to the specified Excel file.

Declaration
[Obsolete("Use Save(string, SaveOptionsBase) instead.")]
void Save(string fileName, string password = null, SaveOptions saveOptions = null)
<Obsolete("Use Save(string, SaveOptionsBase) instead.")>
Sub Save(fileName As String, Optional password As String = Nothing, Optional saveOptions As SaveOptions = Nothing)
Parameters
Type Name Description
string fileName

The Excel file to save.

string password

The password of the file.

SaveOptions saveOptions

Options for saving.

Save(Stream)

Saves the workbook to the specified stream.

Declaration
void Save(Stream fileStream)
Sub Save(fileStream As Stream)
Parameters
Type Name Description
Stream fileStream

The output stream to which the workbook is saved. Must not be null.

Examples
worksheet.Range["A1:B2"].Value = new object[,] {
    { "Name", "Value" },
    { "Test", 100 }
};
using (MemoryStream outputStream = new MemoryStream())
{
    workbook.Save(outputStream);
    byte[] bytes = outputStream.ToArray();
}

Save(Stream, string, SaveOptions)

Saves the workbook to the specified stream.

Declaration
[Obsolete("Use Save(Stream, SaveOptionsBase) instead.")]
void Save(Stream fileStream, string password = null, SaveOptions saveOptions = null)
<Obsolete("Use Save(Stream, SaveOptionsBase) instead.")>
Sub Save(fileStream As Stream, Optional password As String = Nothing, Optional saveOptions As SaveOptions = Nothing)
Parameters
Type Name Description
Stream fileStream

The stream to which the workbook is saved.

string password

The password of the file.

SaveOptions saveOptions

Options for saving.

Save(string, SaveFileFormat)

Saves the workbook to a file in the specified file format.

Declaration
void Save(string fileName, SaveFileFormat fileFormat)
Sub Save(fileName As String, fileFormat As SaveFileFormat)
Parameters
Type Name Description
string fileName

The path of the destination file.

SaveFileFormat fileFormat

The format of the file.

Examples
worksheet.Range["A1:B2"].Value = new object[,] {
    {"Name", "Value"},
    {"Test", 100}
};
workbook.Save(Path.Combine(Environment.CurrentDirectory, "SalesReport.xlsx"), SaveFileFormat.Xlsx);

Save(Stream, SaveFileFormat)

Saves the workbook to a stream in the specified file format.

Declaration
void Save(Stream fileStream, SaveFileFormat fileFormat)
Sub Save(fileStream As Stream, fileFormat As SaveFileFormat)
Parameters
Type Name Description
Stream fileStream

The stream to which the workbook is saved.

SaveFileFormat fileFormat

The file format used to save the workbook to the stream.

Examples
worksheet.Range["A1:B2"].Value = new object[,] {
    {"Name", "Value"},
    {"Test", 100}
};
using (MemoryStream outputStream = new MemoryStream())
{
    workbook.Save(outputStream, SaveFileFormat.Xlsx);
    byte[] bytes = outputStream.ToArray();
}

Save(string, SaveOptionsBase)

Saves the workbook to a file with the specified save options.

Declaration
void Save(string fileName, SaveOptionsBase options)
Sub Save(fileName As String, options As SaveOptionsBase)
Parameters
Type Name Description
string fileName

The path of the destination file.

SaveOptionsBase options

The options of saving the file. Possible types:

Examples
worksheet.Range["A1:B2"].Value = new object[,] {
    {"Name", "Value"},
    {"Test", 100}
};
PdfSaveOptions options = new PdfSaveOptions();
workbook.Save(Path.Combine(Environment.CurrentDirectory, "report.pdf"), options);

Save(Stream, SaveOptionsBase)

Saves workbook to stream with specified options.

Declaration
void Save(Stream fileStream, SaveOptionsBase options)
Sub Save(fileStream As Stream, options As SaveOptionsBase)
Parameters
Type Name Description
Stream fileStream

The stream to which the workbook is saved.

SaveOptionsBase options

The options of saving the file stream. Possible types:

Examples
worksheet.Range["A1:B2"].Value = new object[,] {
    {"Name", "Value"},
    {"Test", 100}
};
XlsxSaveOptions options = new XlsxSaveOptions();
options.IncludeAutoMergedCells = true;
using (MemoryStream stream = new MemoryStream())
{
    workbook.Save(stream, options);
    byte[] bytes = stream.ToArray();
}