C1DataGrid Save to xlsx - System.OutOfMemoryException - Please help me

Posted by: gborzyszkowski on 14 October 2022, 2:19 am EST

  • Posted 14 October 2022, 2:19 am EST

    Hello somehow, I can’t find anyone else who had the problem because of that my first message in the forum.

    When I try via

    GridToExport.Save(_excelFileName, FileFormat.Xlsx);
    to export a grid to Excel with 180000 rows and 30 columns then I get a System.OutOfMemoryException.

    Few rows go without problems, of course.

    C1.WPF.DataGrid.4 is used in the solution.

    Is there any way to get this datagrid into a Excel file without getting an exception?

  • Posted 16 October 2022, 4:31 pm EST

    Hi,

    We are unable to replicate this behavior at our end. DataGrid with 180000 rows and 30 columns is exported in Excel without any error. However, it takes some time due to large data but no exceptions while exporting.

    Could you please provide a small sample that replicates your issue? And Please provide the correct build version, So that we can test with that.

    Regards,

    Nitin

  • Posted 16 October 2022, 6:11 pm EST - Updated 16 October 2022, 8:00 pm EST

    Hi Nitin,

    the Version is C1.WPF.DataGrid.4 → Version : 4.0.20152.473

    And I have take a look again in the datatable and it have not 30 columns but 250 columns and 180000 rows.

    Here more of the source code :

     // WPF: 
     <c1:C1DataGrid Name="Grid" Grid.Row="0" Grid.RowSpan="2  ItemsSource="{Binding DataView, IsAsync=True}"
    	
    
    // Model:
    
      private IBindingListView _dataView;
          
      public IBindingListView DataView
            {
                get
                {
                    return _dataView;
                }
                set
                {
                    _dataView = value;
                    this.FirePropertyChanged(i => i.DataView);
                }
            }
    
    
        // ViewModel:
    
         DataTable tbl;
    	 
       // To the DataTable I load in a different place the data but that will make the example to long.
    	public void LoadData()
            {
                try
                {                               
                    DataView = tbl().DefaultView;                
                }
                catch (Exception e)
                {
                    Log.Debug(e.ToString());
                }
    		}
    		
    	//View.xaml.cs:
    private string _excelFileName = "";
    private string _excelFileExtension = ".xls";
    		
    private void SaveDataToExcel()
            {
                var dlg = new Microsoft.Win32.SaveFileDialog
                {
                    DefaultExt = "xlsx",
                    FileName = "FileName",
                    InitialDirectory = FileUtilities.GetDir(),
                    Filter = "Excel Workbook (*.xlsx)|*.xlsx|" + "Microsoft Excel (*.xls)|*.xls"
                };
                if (dlg.ShowDialog() == true)
                {
                    if (Dispatcher != null)
                        Dispatcher.Invoke(() =>
                        {
                           
                            _excelFileName = dlg.FileName;
                            _excelFileExtension = Path.GetExtension(dlg.SafeFileName).ToLower();
                         
    
                            //SaveExcel();
                            switch (_excelFileExtension)
                            {
                                case ".xls":
                                {
                                    try
                                    {
                                        if (Dispatcher != null)
                                            Dispatcher.Invoke(() => { Grid.Save(_excelFileName, FileFormat.Xls); });
    
                                    }
                                    catch (Exception exception)
                                    {
                                        Console.WriteLine(exception);
                                        throw;
                                    }
    
                                    break;
                                }
    
                                default:
                                {
                                    try
                                    {                                       
    									if (Dispatcher != null)
                                                    Dispatcher.Invoke(() => { Grid.Save(_excelFileName, FileFormat.Xlsx); });
                                    }
                                    catch (Exception exception)
                                    {
                                        Console.WriteLine(exception);
                                        throw;
                                    }
    
                                    break;
                                }
                            }
                        });
      
                }
            }
  • Posted 16 October 2022, 10:02 pm EST

    Hi,

    We have replicated this issue at our end with the 250 columns. We are discussing this with the development team. Will get back to you once we have any update from them.[Internal Tracking Id-C1XAML-30475]

    Best Regards,

    Nitin

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels