Back to Devexpress

Workbook.SaveDocument(String) Method

officefileapi-devexpress-dot-spreadsheet-dot-workbook-dot-savedocument-x28-system-dot-string-x29.md

latest8.9 KB
Original Source

Workbook.SaveDocument(String) Method

SECURITY-RELATED CONSIDERATIONS

Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.

Saves the document to a file in the Excel or text format. The file format is identified by the file extension.

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

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public void SaveDocument(
    string fileName
)
vb
Public Sub SaveDocument(
    fileName As String
)

Parameters

NameTypeDescription
fileNameString

Specifies the file path to save the document.

|

Remarks

The DocumentFormat enumeration lists the supported document formats. To export a file to PDF or HTML, use the Workbook.ExportToPdf and Workbook.ExportToHtml methods.

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

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

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

// Save the modified document to a file.
workbook.SaveDocument("Document.xlsx");
vb
' Add a reference to the DevExpress.Docs.dll assembly.
Imports DevExpress.Spreadsheet
' ...

Dim workbook As New Workbook()
' ...

' Save the modified document to the file.
workbook.SaveDocument("Document.xlsx")

Calculate Formulas Before Save Operation

The default calculation mode for a Workbook is Manual. This mode implies that the Spreadsheet does not calculate formulas before it saves a document. Call the Workbook.Calculate or Workbook.CalculateFull method to calculate all formulas in the workbook.

The following code snippets (auto-collected from DevExpress Examples) contain references to the SaveDocument(String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

spreadsheet-document-api-import-data-from-data-sources/CS/DataImportExample/Form1.cs#L33

csharp
workbook.EndUpdate();
workbook.SaveDocument("result.xlsx");
Process.Start(new ProcessStartInfo("result.xlsx") { UseShellExecute = true });

spreadsheet-document-api-external-workbook/CS/SpreadsheetApiExternalWorkbook/Program.cs#L23

csharp
externalWorkbook.Worksheets[0].Import(CreateDataTable(10), false, 0, 0);
externalWorkbook.SaveDocument("ExternalDocument.xlsx");
myWorkbook.ExternalWorkbooks.Add(externalWorkbook);

spreadsheet-document-api-chart-examples/CS/SpreadsheetDocServerChartAPISamples/Form1.cs#L443

csharp
tempWorkbook.Worksheets[0].CopyFrom(workbook.Worksheets.ActiveWorksheet);
tempWorkbook.SaveDocument(fileName);
Process.Start(fileName);

reporting-winforms-export-reports-to-diff-sheets-in-xlsx-file-with-spreadsheet-document-api/CS/WindowsFormsApplication1/Form1.cs#L45

csharp
workbook.Worksheets[1].CopyFrom(workbook2.Worksheets[0]);
workbook.SaveDocument("test3.xlsx");
Process.Start("test3.xlsx");

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/CustomXmlPartActions.cs#L43

csharp
workbook.CustomXmlParts.Add(xmlDoc);
workbook.SaveDocument("..\\..\\..\\Documents\\CustomXmlTest.xlsx");
System.IO.File.Copy("..\\..\\..\\Documents\\CustomXmlTest.xlsx", "..\\..\\..\\Documents\\CustomXmlTest.xlsx.zip", true);

spreadsheet-document-api-import-data-from-data-sources/VB/DataImportExample/Form1.vb#L25

vb
workbook.EndUpdate()
workbook.SaveDocument("result.xlsx")
Process.Start(New ProcessStartInfo("result.xlsx") With {.UseShellExecute = True})

spreadsheet-document-api-external-workbook/VB/SpreadsheetApiExternalWorkbook/Program.vb#L20

vb
externalWorkbook.Worksheets(0).Import(CreateDataTable(10), False, 0, 0)
externalWorkbook.SaveDocument("ExternalDocument.xlsx")
myWorkbook.ExternalWorkbooks.Add(externalWorkbook)

spreadsheet-document-api-chart-examples/VB/SpreadsheetDocServerChartAPISamples/Form1.vb#L424

vb
tempWorkbook.Worksheets(0).CopyFrom(workbook.Worksheets.ActiveWorksheet)
tempWorkbook.SaveDocument(fileName)
Process.Start(fileName)

reporting-winforms-export-reports-to-diff-sheets-in-xlsx-file-with-spreadsheet-document-api/VB/WindowsFormsApplication1/Form1.vb#L41

vb
workbook.Worksheets(1).CopyFrom(workbook2.Worksheets(0))
workbook.SaveDocument("test3.xlsx")
Call Process.Start("test3.xlsx")

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/CustomXmlPartActions.vb#L40

vb
workbook.CustomXmlParts.Add(xmlDoc)
workbook.SaveDocument("..\..\..\Documents\CustomXmlTest.xlsx")
System.IO.File.Copy("..\..\..\Documents\CustomXmlTest.xlsx", "..\..\..\Documents\CustomXmlTest.xlsx.zip", True)

Implements

SaveDocument(String)

See Also

WorkbookExportOptions

How to: Save a Document to a File

How to: Export a Workbook to PDF

Workbook Class

Workbook Members

DevExpress.Spreadsheet Namespace