Search code examples
c#-4.0filehelpers

How to get notified in the progress of the operations in ExcelStorage of FileHelpers


Documentation http://www.filehelpers.com/example_progress.html saying that i need to use method SetProgressHandler but ExcelStorage does not have it.

ExcelStorage has method public event EventHandler<ProgressEventArgs> Progress; so looks like i need to use it in some way?

ExcelStorage provider = new ExcelStorage(typeof(MyModel));

provider.StartRow = 2;    
provider.StartColumn = 1;                
provider.FileName = @"C:\Customers.xlsx";    
provider.HeaderRows = 13;

provider.InsertRecords(data.ToArray()); // need to get progress here

May be some one could help?


Solution

  • Try this:

    provider.Progress += provider_Progress;
    

    and then define the provider_Progress event handler to update

    static void provider_Progress(object sender, ProgressEventArgs e)
    {
         var percent = e.Percent; 
         var positionMax = e.TotalRecords; 
         var position = e.CurrentRecord; 
    
         // update the progress control
    
         Application.DoEvents(); 
    }