1 year ago

#354180

test-img

husham1414

DevExpress WPF GridContol Export Very Large Data to Excel File

I'm trying to export a DevExpress GridControl with more than 2 millions rows, then error 'OutOfMemory exception' appears .

What is the best way to export and handle this?

this my code

retrieve from DataTable:

public async void Get_Report()
        {
            try
            {
                myGridControl.ItemsSource = await Get_Report_from_DataTable();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

then export to excel:

private void btn_Excel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                XlsxExportOptionsEx options = new XlsxExportOptionsEx() { UnboundExpressionExportMode = DevExpress.Export.UnboundExpressionExportMode.AsFormula, LayoutMode = LayoutMode.Table };
                options.BeforeExportTable += options_BeforeExportTable;
                
                myGridControl_view.ExportToXlsx("Large Report.xlsx", options);
        //This the view of GridControl
                Process.Start("Large Report.xlsx");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        void options_BeforeExportTable(BeforeExportTableEventArgs e)
        {
            e.Table.Style.Name = XlBuiltInTableStyleId.Medium9;
        }

c#

wpf

devexpress

export-to-excel

large-data

0 Answers

Your Answer

Accepted video resources