Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

Workbook.SaveDocument(Stream, DocumentFormat) Method

Saves the document to a stream in the specified format.

You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use this method in production code.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Docs.v19.1.dll

Declaration

public void SaveDocument(
    Stream stream,
    DocumentFormat format
)

Parameters

Name Type Description
stream Stream

Specifies the output stream.

format DocumentFormat

A DocumentFormat enumeration value that specifies the document’s format.

Remarks

Take into account the following when you save a document to a stream:

  • Do not save a workbook to a stream that does not support seek operations. An exception is thrown in this case. Use the System.IO.Stream.CanSeek property to determine if the steam supports seeking.

  • Do not save a workbook to the same stream from which it was loaded. In this case, document bytes are written to the end of the existing stream and an invalid document is produced.

Use the Workbook.Options.Export property or Workbook.BeforeExport event to specify export options.

// Add a reference to the DevExpress.Docs.dll assembly.
using DevExpress.Spreadsheet;
using System.IO;
// ...

Workbook workbook = new Workbook();
// ...

// Save the document to a stream.
using (FileStream stream = new FileStream("Document.xlsx",
    FileMode.Create, FileAccess.ReadWrite))
{
    workbook.SaveDocument(stream, DocumentFormat.Xlsx);
}
See Also