Progress for ImportCSV

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
kooths
Posts: 4
Joined: Mon Mar 05, 2007 10:13 am
Location: infratelligence, Berlin

Progress for ImportCSV

Post by kooths »

The OnProgress event seems to be triggered only for reading/writing xls-files. Is there a way to use it while importing csv-files aswell?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Post by larsa »

Hello

Yes. But you have to modify the source of the file ImportCSV2.pas

Code: Select all

// 1. Reset the progress.
    ProgressCount := 0;
    if Assigned(XLS.OnProgress) then
      FXLS.OnProgress(Self,0);

// 2. Insert this code after the for loop in the ImportCSVInt function.
// You shall also add two int variables, V and ProgressCount
        if Assigned(XLS.OnProgress) then begin
          V := Round((i / Lines.Count) * 100);
          // Don't update the progress for each line, as this can slow things down...
          if V > ProgressCount then begin
            ProgressCount := V;
            XLS.OnProgress(Self,ProgressCount);
          end;
        end;

// 3. At the end of the function, make sure that progress is at 100.
    if Assigned(XLS.OnProgress) then
      XLS.OnProgress(Self,100);
I have not tested this code, so there may be some error...


Lars Arvidsson
Post Reply