Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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

public void SetPreferredNumberFormatLocal(
    IWorkbook workbook,
    string excelNumberFormat
)

#Parameters

Name Type Description
workbook IWorkbook

The current workbook.

excelNumberFormat String

A Microsoft Excel compatible number format.

#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