Skip to main content

GridExportOptions.DocumentCulture Property

Specifies the exported document’s culture that defines numeric and date-time data formatting settings.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public CultureInfo DocumentCulture { get; set; }

Property Value

Type Description
CultureInfo

The document culture.

Property Paths

You can access this nested property as listed below:

Object Type Path to DocumentCulture
GridExportEventArgs
.Options .DocumentCulture

Remarks

The grid uses the current culture to format numeric and date-time cell values in exported document. Use the DocumentCulture property to specify another culture for the exported document.

@using System.Xml;
<DxGrid @ref="Grid" Data="@Data" >
    <Columns>
        <DxGridDataColumn FieldName="OrderDate" />
        <DxGridDataColumn FieldName="CompanyName"  />
        <DxGridDataColumn FieldName="Country" />
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" />
        <DxGridDataColumn FieldName="Quantity" />
        <DxGridDataColumn FieldName="Total" UnboundType="GridUnboundColumnType.Decimal" 
                          DisplayFormat="c" UnboundExpression="[UnitPrice]*[Quantity]" />
    </Columns>
</DxGrid>
<DxButton Text="Export in Euro" Click="ExportXlsx_Click" />

@code {
    object Data { get; set; }
    IGrid Grid { get; set; }
    protected override async Task OnInitializedAsync() {
        var invoices = await NwindDataService.GetInvoicesAsync();
        var customers = await NwindDataService.GetCustomersAsync();
        Data = invoices.OrderBy(i => i.OrderDate).Join(customers, i => i.CustomerId, c => c.CustomerId, (i, c) => {
            return new {
                OrderDate = i.OrderDate,
                CompanyName = c.CompanyName,
                City = i.City,
                Region = i.Region,
                Country = i.Country,
                UnitPrice = i.UnitPrice,
                Quantity = i.Quantity
            };
        });
    }
    decimal GetRate() {
        string daylyRate = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
        decimal rate = 0;
        XmlTextReader reader = new XmlTextReader(daylyRate);
        while (reader.Read()) {
            if (reader.NodeType == XmlNodeType.Element && reader.MoveToAttribute("currency")) {
                if (reader.Value == "USD") {
                    reader.MoveToAttribute("rate");
                    rate = Convert.ToDecimal(reader.Value);
                    break;
                }

            }
        }
        return rate;
    }

    async Task ExportXlsx_Click() {
        decimal currentRate = GetRate();
        var options = new GridXlExportOptions();
        options.DocumentCulture = new CultureInfo("fr-FR");
        options.SheetName = "(Rate = " + currentRate + ")";
        options.CustomizeCell = e => {
            if (e.AreaType == DevExpress.Export.SheetAreaType.DataArea && (e.ColumnFieldName == "Total" || e.ColumnFieldName == "UnitPrice")) {
                e.Value = (decimal)e.Value / currentRate;
                // Highlight data cells where Total > 1000€
                if (e.ColumnFieldName == "Total" && (decimal)e.Value > 1000) {
                    e.Formatting.BackColor = System.Drawing.Color.LightGreen;
                }
                e.Handled = true;
            }
        };
        await Grid.ExportToXlsxAsync("ExportResult", options);
    }
}

Grid - French Culture

For more information about data export in the Grid component, refer to the following topic: Export Data in Blazor Grid.

See Also