Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi Export table rows (https://www.delphipraxis.net/176708-export-table-rows.html)

danten 21. Sep 2013 23:12

Datenbank: Absolute Database • Version: 1 • Zugriff über: 1

Export table rows
 
Hi all.
Now I deal with the export of table rows entry in the filter, but it is ineffective.
I need to export table rows after 200 rows repeatedly until no Table1.RecordCount = 0.
The file name would be increased by 1.
export1.csv, export2.csv ......
CSVExport = JvDBGridCSVExport
Thank you all for your ideas.
Delphi-Quellcode:
tab1.Filtered := False;
  tab1.Filter := 'Cislo_ID > 0 AND Cislo_ID < 201';
  tab1.Filtered := True;
  CSVExport.FileName := ExtractFilePath(ParamStr(0))+ 'upload/export1.csv';
  CSVExport.Separator := ';';
  CSVExport.ExportGrid;
  tab1.Filtered := False;
  tab1.Filter := 'Cislo_ID > 199 AND Cislo_ID < 401';
  tab1.Filtered := True;
  CSVExport.FileName := ExtractFilePath(ParamStr(0))+ 'upload/export2.csv';
  CSVExport.Separator := ';';
  CSVExport.ExportGrid;
  tab1.Filtered := False;
  tab1.Filter := 'Cislo_ID > 399 AND Cislo_ID < 601';
  tab1.Filtered := True;
  CSVExport.FileName := ExtractFilePath(ParamStr(0))+ 'upload/export3.csv';
  CSVExport.Separator := ';'
  CSVExport.ExportGrid;

danten 22. Sep 2013 12:57

AW: Export table rows
 
Delphi-Quellcode:
  x := 0;
  repeat;
  y := Random(200);
for i := y tab1.RecordCount -1 do
begin
  tab1.Filtered := False;
  tab1.Filter := 'Cislo_ID > '+ QuotedStr(x) + ' AND Cislo_ID < '+ QuotedStr(y);
  tab1.Filtered := True;
  CSVExport.FileName := ExtractFilePath(ParamStr(0))+ 'upload/export'+IntToStr(x+1)+'.csv';
  CSVExport.Separator := ';';
  CSVExport.ExportGrid;
  until x = 0;
export1.csv = 200 lines (0 to 200)
export2.csv = 200 lines (201 to 400)
export3.csv = 200 lines (401 to 600)
export4.csv = x lines (601 to ??)

sx2008 22. Sep 2013 15:04

AW: Export table rows
 
Delphi-Quellcode:
const BSIZE = 200;

....
CSVExport.Separator := ';'; // moved outside of the loop because we need so set the separator only once
for i := 0 to (tab1.RecordCount div BSIZE) + 1 do
begin
  tab1.Filtered := False;
  // note: lower margin is included and upper margin is excluded
  // 0..199 (200 records)
  // 200..399 (200 records)
  tab1.Filter := 'Cislo_ID >='+ QuotedStr(i*BSIZE) + ' AND Cislo_ID < '+ QuotedStr((i+1)*BSIZE);
  tab1.Filtered := True;
  if tab1.IsEmpty then
    break; // stop export if there are no more records
  CSVExport.FileName := ExtractFilePath(ParamStr(0))+ 'upload/export'+IntToStr(i+1)+'.csv';
  CSVExport.ExportGrid;
end;

danten 23. Sep 2013 03:50

AW: Export table rows
 
OK sx2008,
export1.csv = 732 lines
export2.csv = 221 lines
export3.csv = 221 lines
export4.csv = 221 lines
......

Furtbichler 23. Sep 2013 08:52

AW: Export table rows
 
Why is that so? Take a look at the export files. Which Cislo-ID do they contain? I bet all is ok according to what you've told us (i.e. export1.CSV contains all recors with a Cislo-ID of 0..199).

Am I right?


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:36 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz