CellValueToStringConverter.SetPreferredNumberFormatLocal(IWorkbook, String) Method
Specifies a local number format used for string representation of numeric values.
Namespace: DevExpress.Spreadsheet.Export
Assembly: DevExpress.Spreadsheet.v24.2.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
workbook | IWorkbook | The current workbook. |
excelNumberFormat | String |
Remarks
Use the SetPreferredNumberFormatLocal method to specify a number format based on the local culture defined by the DocumentOptions.Culture property.
The following code snippet exports a DateTime value in a format specific to the French culture. The result is “mai-22”.
using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Export;
using System;
using System.Data;
using System.Globalization;
// ...
spreadsheetControl1.Options.Culture = new CultureInfo("fr-FR");
var workbook = spreadsheetControl1.Document;
var worksheet = workbook.Worksheets.ActiveWorksheet;
var dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("Column1", typeof(string)));
worksheet["A1"].Value = new DateTime(2022, 05, 30);
var exporter = worksheet.CreateDataTableExporter(worksheet["A1"], dataTable, false);
exporter.Options.DefaultCellValueToStringConverter.PreferredCulture = new CultureInfo("fr-FR");
exporter.Options.DefaultCellValueToStringConverter.SetPreferredNumberFormatLocal(spreadsheetControl1.Document, "mmm-aa");
exporter.Export();
string result = dataTable.Rows[0].Field<string>("Column1");
The CellValueToStringConverter.SetPreferredNumberFormat method allows you to obtain or specify a number format in the invariant culture.
See Also