Completed
Last Updated: 11 Jul 2017 14:00 by ADMIN
ADMIN
Dimitar
Created on: 29 Jun 2017 07:16
Category: PivotGrid
Type: Bug Report
0
FIX. RadPivotGrid - PivotGridSpreadExport one cannot set the format or the value in the CellFormаtting event.
To reproduce:
Try setting the value in the CellForamting event. 

Workaround:
class MySpreadExportRenderer : SpreadExportRenderer
{
    public override void SetCellSelectionValue(DataType dataType, object value)
    {
        base.SetCellSelectionValue(dataType, value);
        if (dataType == DataType.Number)
        {
            CellRange range = ((CellSelection)this.GetCellSelection()).CellRanges.ElementAtOrDefault(0);
            double d;
            if (double.TryParse(Convert.ToString(value), out d))
            {
                var cell = ((Worksheet)this.GetWorksheet()).Cells[range.FromIndex.RowIndex, range.FromIndex.ColumnIndex];
                cell.SetFormat(new CellValueFormat("#,##0.00"));
                cell.SetValue(d);
            }
        }
    }
}

1 comment
ADMIN
Ralitsa
Posted on: 10 Jul 2017 06:32
In order to customize the number formatting of exported RadPivotGrid, you can subscribe to PivotGridSpredExport.CellFormatting event. The code below demonstrates how can you achieve it: 

void spreadExport_CellFormatting(object sender, PivotGridSpreadExportCellFormattingEventArgs e)
{
    if (e.ColumnIndex >= 3 && e.ColumnIndex >= 12)
    {
        e.Cell.FormatString = "#.000";
        e.Cell.BackColor = Color.LightCyan;
    }
}

Keep in mind, that MS Excel supports its own formatting strings. In the following article, you can find more details on formatting in MS Excel ( //http://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/features/format-codes )