TableView.ExportToCsv(Stream) Method
Exports a grid to the specified stream in CSV format.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v19.2.dll
Declaration
public override void ExportToCsv(
Stream stream
)
Public Overrides Sub ExportToCsv(
stream As Stream
)
Parameters
Name |
Type |
Description |
stream |
Stream |
A Stream object to which the created CSV file should be sent.
|
To display the Print Preview of the grid, use the DataViewBase.ShowPrintPreview and DataViewBase.ShowPrintPreviewDialog methods. To print the grid, use the DataViewBase.Print or DataViewBase.PrintDirect method.
To learn more, see Printing.
Note
The grid can be previewed, printed and exported only if the DXPrinting Library is available. You should manually add the reference to the DevExpress.Xpf.Printing.v19.2 assembly.
Example
This example shows how to preview and print/export the grid content. The grid is printed and exported using the built-in capabilities.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DXGrid_PrintGrid {
public class IssueList {
public List<IssueDataObject> List { get; private set; }
public IssueList() {
List = GetIssueList();
}
List<IssueDataObject> GetIssueList() {
List<IssueDataObject> data = new List<IssueDataObject>();
data.Add(new IssueDataObject() { IssueName = "Transaction History", IssueType = "Bug", IsPrivate = true });
data.Add(new IssueDataObject() { IssueName = "Ledger: Inconsistency", IssueType = "Bug", IsPrivate = false });
data.Add(new IssueDataObject() { IssueName = "Data Import", IssueType = "Request", IsPrivate = false });
data.Add(new IssueDataObject() { IssueName = "Data Archiving", IssueType = "Request", IsPrivate = true });
return data;
}
}
public class IssueDataObject {
public string IssueName { get; set; }
public string IssueType { get; set; }
public bool IsPrivate { get; set; }
}
}
<Window x:Class="DXGrid_PrintGrid.Window1" Title="Window1" Height="300" Width="450"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew" ItemsSource="{Binding List}">
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" />
</dxg:GridControl.View>
</dxg:GridControl>
<WrapPanel Grid.Row="1" Orientation="Horizontal">
<Button Click="PreviewGrid">
Show Print Preview
</Button>
<Button Click="ExportToXls">
Export to MS Excel
</Button>
<Button Click="ExportToCsv">
Export to CSV
</Button>
<Button Click="ExportToPng">
Export to an image
</Button>
</WrapPanel>
</Grid>
</Window>
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using DevExpress.Xpf.Grid;
using DevExpress.Xpf.Printing;
namespace DXGrid_PrintGrid {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
DataContext = new IssueList();
}
private void PreviewGrid(object sender, RoutedEventArgs e) {
view.ShowPrintPreviewDialog(this);
}
private void ExportToXls(object sender, RoutedEventArgs e) {
view.ExportToXlsx(@"d:\grid_export.xlsx");
}
private void ExportToCsv(object sender, RoutedEventArgs e) {
view.ExportToCsv(@"d:\grid_export.csv");
}
private void ExportToPng(object sender, RoutedEventArgs e) {
view.ExportToImage(@"d:\grid_export.png");
}
}
}
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Documents
Imports DevExpress.Xpf.Grid
Imports DevExpress.Xpf.Printing
Namespace DXGrid_PrintGrid
Partial Public Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
DataContext = New IssueList()
End Sub
Private Sub PreviewGrid(ByVal sender As Object, ByVal e As RoutedEventArgs)
view.ShowPrintPreviewDialog(Me)
End Sub
Private Sub ExportToXls(ByVal sender As Object, ByVal e As RoutedEventArgs)
view.ExportToXlsx("d:\grid_export.xlsx")
End Sub
Private Sub ExportToCsv(ByVal sender As Object, ByVal e As RoutedEventArgs)
view.ExportToCsv("d:\grid_export.csv")
End Sub
Private Sub ExportToPng(ByVal sender As Object, ByVal e As RoutedEventArgs)
view.ExportToImage("d:\grid_export.png")
End Sub
End Class
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Namespace DXGrid_PrintGrid
Public Class IssueList
Private privateList As List(Of IssueDataObject)
Public Property List() As List(Of IssueDataObject)
Get
Return privateList
End Get
Private Set(ByVal value As List(Of IssueDataObject))
privateList = value
End Set
End Property
Public Sub New()
List = GetIssueList()
End Sub
Private Function GetIssueList() As List(Of IssueDataObject)
Dim data As New List(Of IssueDataObject)()
data.Add(New IssueDataObject() With {.IssueName = "Transaction History", .IssueType = "Bug", .IsPrivate = True})
data.Add(New IssueDataObject() With {.IssueName = "Ledger: Inconsistency", .IssueType = "Bug", .IsPrivate = False})
data.Add(New IssueDataObject() With {.IssueName = "Data Import", .IssueType = "Request", .IsPrivate = False})
data.Add(New IssueDataObject() With {.IssueName = "Data Archiving", .IssueType = "Request", .IsPrivate = True})
Return data
End Function
End Class
Public Class IssueDataObject
Public Property IssueName() As String
Public Property IssueType() As String
Public Property IsPrivate() As Boolean
End Class
End Namespace
See Also