Completed
Last Updated: 12 Oct 2015 10:10 by Todor
Todor
Created on: 18 Sep 2015 16:05
Category: PivotGrid
Type: Bug Report
0
FIX. RadPivotGrid - exception is thrown if cell value is string and starts with "=" or "-", when exporting with PivotGridSpreadExport.
To reproduce:
In RadPivotGrid set some cell values to start with "=" or "-". Export it using PivotGridSpreadExport. The exporter tries to convert the value to formula and if this is not successful an exception is thrown.

Workaround:
private void radButtonNewPivotToExcel_Click(object sender, EventArgs e)
{
    SaveFileDialog saveFileDialog = new SaveFileDialog();
    saveFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx";
    if (saveFileDialog.ShowDialog() == DialogResult.OK)
    {
        SpreadExportRenderer renderer = new SpreadExportRenderer();
        MyPivotSpreadExport exporter = new MyPivotSpreadExport(this.radPivotGrid1, renderer);
        exporter.ExportFormat = SpreadExportFormat.Xlsx;
        exporter.RunExportAsync(saveFileDialog.FileName + ".xlsx", renderer);
    }
}

public class MyPivotSpreadExport : PivotGridSpreadExport
{
    private ISpreadExportRenderer spreadExportRenderer;

    public MyPivotSpreadExport(RadPivotGrid pivotGrid, ISpreadExportRenderer renderer)
        : base(pivotGrid)
    {
        this.spreadExportRenderer = renderer;
    }

    protected override void AddRowToWorksheet(PivotGridExportRowElement rowElement)
    {
        foreach (PivotGridSpreadExportCellElement exportCell in rowElement.Cells)
        {
            this.spreadExportRenderer.CreateCellSelection(rowElement.Index, exportCell.ColumnIndex);

            Color borderColor = this.ShowGridLines ? exportCell.BorderColor : Color.Transparent;
            this.spreadExportRenderer.CreateCellStyleInfo(exportCell.BackColor, exportCell.ForeColor, exportCell.Font.FontFamily, exportCell.Font.Size,
                exportCell.Font.Bold, exportCell.Font.Italic, exportCell.Font.Underline, exportCell.TextAlignment, exportCell.TextWrap, BorderBoxStyle.SingleBorder,
                borderColor, Color.Empty, Color.Empty, Color.Empty, Color.Empty);

            if (exportCell.DataType == DataType.String || exportCell.DataType == DataType.Other)
            {
                this.spreadExportRenderer.SetCellSelectionFormat("@");
            }
            this.spreadExportRenderer.SetCellSelectionValue(exportCell.DataType, exportCell.Value ?? exportCell.Text);
        }
    }
}

0 comments