wpf-devexpress-dot-xpf-dot-spreadsheet-dot-spreadsheetcontrol-534b5916.md
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.
Gets or sets a document supplier for a SpreadsheetControl. This is a dependency property.
Namespace : DevExpress.Xpf.Spreadsheet
Assembly : DevExpress.Xpf.Spreadsheet.v25.2.dll
NuGet Package : DevExpress.Wpf.Spreadsheet
public object DocumentSource { get; set; }
Public Property DocumentSource As Object
| Type | Description |
|---|---|
| Object |
An object specifying the document to bind to the SpreadsheetControl.
|
When you set the DocumentSource property, the SpreadsheetControl attempts to load a document specified by the property value.
You can use the following data sources:
The built-in IFormatDetectorService implementation automatically detects the format of documents loaded from a Stream, Uri or Byte[] instance.
The following formats can be detected on the fly:
The following code snippet binds an XLSX file as the document source:
<Grid>
<dxsps:SpreadsheetControl CommandBarStyle="Ribbon"
ShowFormulaBar="True"
DocumentSource="pack://application:,,,/WpfSpreadsheet;component/Document.xlsx"/>
</Grid>
If you use the SpreadsheetDocumentSource object, a document is loaded from the stream specified by the SpreadsheetDocumentSource.Stream property. The SpreadsheetDocumentSource.Format property determines the document format.
Tip
Set the DocumentSource property to null to create a new document.
The following code sample loads a CSV document from a stream to the SpreadsheetDocumentSource object:
<Grid>
<dxs:SpreadsheetControl CommandBarStyle="Ribbon" ShowFormulaBar="True" DocumentSource="{Binding Source}"/>
</Grid>
private SpreadsheetDocumentSource Source { get; set; }
//...
byte[] bytes = File.ReadAllBytes(@"\Docs\TopTradingPartners.csv");
Stream stream = new MemoryStream(bytes);
stream.Seek(0, SeekOrigin.Begin);
Source = new SpreadsheetDocumentSource(stream, DocumentFormat.Csv);
Private Property Source() As SpreadsheetDocumentSource
'...
Private bytes() As Byte = File.ReadAllBytes("\Docs\TopTradingPartners.csv")
Private stream As Stream = New MemoryStream(bytes)
stream.Seek(0, SeekOrigin.Begin)
Source = New SpreadsheetDocumentSource(stream, DocumentFormat.Csv)
The following code snippets (auto-collected from DevExpress Examples) contain references to the DocumentSource property.
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.
<dxsps:SpreadsheetControl x:Name="spreadsheet" CommandBarStyle="Ribbon" ShowFormulaBar="True" Loaded="spreadsheet_Loaded"
DocumentSource="pack://application:,,,/WpfSpreadsheet_MessageBoxService;component/Document.xlsx"/>
</Grid>
<dxsps:SpreadsheetControl x:Name="spreadsheetControl" CommandBarStyle="Ribbon" ShowFormulaBar="True" Loaded="spreadsheetControl_Loaded"
DocumentSource="pack://application:,,,/WpfSpreadsheet_CustomCommand;component/Document.xlsx"/>
</Grid>
See Also