[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.Workbook.Save

Save Method

Save(string, string, SaveOptions)

Saves the workbook to disk.

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

The excel file.

string password

The password of the file.

SaveOptions saveOptions

Options for saving.

Implements

Save(string)

Saves the workbook to disk.

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

The path of the destination file.

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

Save(Stream, string, SaveOptions)

Saves the workbook to the specified stream.

Declaration
[Obsolete("Use Save(Stream, SaveOptionsBase) instead.")]
public void Save(Stream fileStream, string password = null, SaveOptions saveOptions = null)
<Obsolete("Use Save(Stream, SaveOptionsBase) instead.")>
Public 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

Implements

Save(Stream)

Saves the workbook to the specified stream.

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

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

Implements
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(string, SaveFileFormat)

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

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

The path of the destination file.

SaveFileFormat fileFormat

The file format used to save the workbook.

Implements
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
public void Save(Stream fileStream, SaveFileFormat fileFormat)
Public 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.

Implements
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
public void Save(string fileName, SaveOptionsBase options)
Public 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:

Implements
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
public void Save(Stream fileStream, SaveOptionsBase options)
Public 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:

Implements
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();
}