Completed
Last Updated: 20 Oct 2016 15:46 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 03 Mar 2016 09:24
Category: GridView
Type: Bug Report
3
FIX. RadGridView - OutOfMemoryException when using GridViewSpreadExport to export a grid with 300 000 rows
To reproduce:
public Form1()
{
    InitializeComponent();
    
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text1"));
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text2"));
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text3"));
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text4"));
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text5"));
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text6"));
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text7"));
    radGridView1.Columns.Add(new GridViewTextBoxColumn("Text8"));
    radGridView1.Columns.Add(new GridViewDateTimeColumn("Date1"));
    radGridView1.Columns.Add(new GridViewDecimalColumn("Amount1"));
    radGridView1.Columns.Add(new GridViewDecimalColumn("Amount2"));
    radGridView1.Columns.Add(new GridViewDecimalColumn("Amount3"));
    radGridView1.Columns.Add(new GridViewDecimalColumn("Amount4"));
    radGridView1.Columns.Add(new GridViewDecimalColumn("Amount5"));
    radGridView1.Columns.Add(new GridViewDecimalColumn("Amount6"));
    radGridView1.DataSource = GetDataSet();
}

private DataTable GetDataSet()
{
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("Text1", typeof(string)));
    dt.Columns.Add(new DataColumn("Text2", typeof(string)));
    dt.Columns.Add(new DataColumn("Text3", typeof(string)));
    dt.Columns.Add(new DataColumn("Text4", typeof(string)));
    dt.Columns.Add(new DataColumn("Text5", typeof(string)));
    dt.Columns.Add(new DataColumn("Text6", typeof(string)));
    dt.Columns.Add(new DataColumn("Text7", typeof(string)));
    dt.Columns.Add(new DataColumn("Text8", typeof(string)));
    dt.Columns.Add(new DataColumn("Date1", typeof(DateTime)));
    dt.Columns.Add(new DataColumn("Amount1", typeof(decimal)));
    dt.Columns.Add(new DataColumn("Amount2", typeof(decimal)));
    dt.Columns.Add(new DataColumn("Amount3", typeof(decimal)));
    dt.Columns.Add(new DataColumn("Amount4", typeof(decimal)));
    dt.Columns.Add(new DataColumn("Amount5", typeof(decimal)));
    dt.Columns.Add(new DataColumn("Amount6", typeof(decimal)));

    for (int i = 1; i <= 150000; i++)
    {
        dt.Rows.Add(new object[]
        {
            "Example Text For Row " + i.ToString(),
            "Example Text For Row " + i.ToString(),
            "More Example Text For Row " + i.ToString(),
            "Even More Example Text For Row " + i.ToString(),
            "Lots More Example Text For Row " + i.ToString(),
            "Excessive Example Text For Row " + i.ToString(),
            "Extra Example Text For Row " + i.ToString(),
            "Random Example Text For Row " + i.ToString(),
            new DateTime(2015, i % 12 + 1, i % 28 + 1),
            i % 2 * 10000, i % 3 * 10000, i % 5 * 10000, i % 7 * 10000, i % 11 * 10000, i % 13 * 10000
        });
    }

    return dt;
}

string fileName = @"..\..\" + DateTime.Now.ToLongTimeString().Replace(":", "_");

private void button1_Click(object sender, EventArgs e)
{
    SaveFileDialog sfdExportToExcel = new SaveFileDialog();
    DialogResult exportBrowse = sfdExportToExcel.ShowDialog();

    if (exportBrowse == DialogResult.OK)
    {
        GridViewSpreadExport exporter = new GridViewSpreadExport(this.radGridView1);
        exporter.SheetMaxRows = Telerik.WinControls.UI.Export.ExcelMaxRows._1048576;
        exporter.FileExportMode = FileExportMode.CreateOrOverrideFile;
        exporter.ExportVisualSettings = false;
        exporter.AsyncExportCompleted += exporter_AsyncExportCompleted;
        SpreadExportRenderer renderer = new SpreadExportRenderer();
        
        exporter.RunExportAsync(fileName, renderer);
    }
}

1 comment
ADMIN
Ralitsa
Posted on: 20 Oct 2016 15:46
In order to export greater amounts of data, you can use our new export provider - GridViewSpreadStreamExport, which does not create spread document model in memory, but instead writes the grid contents directly to a file, hence it has very low memory footprint, and better performance. The provider will be available in our next version of suite: Telerik UI for Winforms R3 2016 SP1. More information how to use it can be found in our documentation and examples.