CsvDataAwareExporterOptions Class
Specifies options for exporting the document to CSV format.
Namespace: DevExpress.XtraExport.Csv
Assembly: DevExpress.Printing.v18.1.Core.dll
Declaration
Example
The following code snippet illustrates how to specify options to export the document to CSV format.
A new instance of the CsvDataAwareExporterOptions class is initialized.The IXlDocument.Options property of a document is casted to the CsvDataAwareExporterOptions. It provides access to all the options associated to the CsvDataAwareExporterOptions object.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/xl-export-api-examples-t253492
// Create an exporter instance.
IXlExporter exporter = XlExport.CreateExporter(documentFormat);
// Create a new document.
using(IXlDocument document = exporter.CreateDocument(stream)) {
document.Options.Culture = CultureInfo.CurrentCulture;
// Specify options for exporting the document to CSV format.
CsvDataAwareExporterOptions csvOptions = document.Options as CsvDataAwareExporterOptions;
if(csvOptions != null) {
// Set the encoding of the text-based file to which the workbook is exported.
csvOptions.Encoding = Encoding.UTF8;
// Write a preamble that specifies the encoding used.
csvOptions.WritePreamble = true;
// Convert a cell value to a string by using the current culture's format string.
csvOptions.UseCellNumberFormat = false;
// Insert the newline character after the last row of the resulting text.
csvOptions.NewlineAfterLastRow = true;
}
// Generate data for the document.
using(IXlSheet sheet = document.CreateSheet()) {
using(IXlRow row = sheet.CreateRow()) {
using(IXlCell cell = row.CreateCell()) {
cell.Value = "Product";
}
for(int i = 0; i < 4; i++) {
using(IXlCell cell = row.CreateCell()) {
cell.Value = string.Format("Q{0}", i + 1);
}
}
}
string[] products = new string[] {
"Camembert Pierrot", "Gorgonzola Telino", "Mascarpone Fabioli", "Mozzarella di Giovanni",
"Gnocchi di nonna Alice", "Gudbrandsdalsost", "Gustaf's Knäckebröd", "Queso Cabrales",
"Queso Manchego La Pastora", "Raclette Courdavault", "Singaporean Hokkien Fried Mee", "Wimmers gute Semmelknödel"
};
Random random = new Random();
for(int i = 0; i < 12; i++) {
using(IXlRow row = sheet.CreateRow()) {
using(IXlCell cell = row.CreateCell()) {
cell.Value = products[i];
}
for(int j = 0; j < 4; j++) {
using(IXlCell cell = row.CreateCell()) {
cell.Value = Math.Round(random.NextDouble() * 2000 + 3000);
}
}
}
}
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the CsvDataAwareExporterOptions class.
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.