Declare some Procedure DataToExcelcsv (SaveFileName: String; DataSet: TDataSet; showcompletebox: boolean = true; groupcount: integer = 1);
... {------------------------------------------- -----------} {Detection Findstr in MAINSTR, if there is, return true, otherwise false} {--------------------- ---------------------------------} Function isstrinotherstr (Mainstr, Findstr: String): Bool; Begin Result: = Strpos (MAINSTR), Pansichar (Findstr)) = Nilend; ----------------------------------- -------------------------------------------------- // Lijinhao 2004-4-4 // Adopt CSV format .. Convert data to Excel.// Speed very fast, and have a subhang function // to avoid bringing COMOBJ to drawback // GroupCount: for setting The number of columns. .
The default is 1 // showcompletebox: boolean; to set the completion of the display completion prompt // ------------------------------ ------------------------------------------------ Procedure DataToExcelcsv (SaveFileName: string; DataSet: TDataSet; ShowCompleteBoX: Boolean; groupCount: integer); Function CheckStr (str: string): string; begin if IsStrInOtherStr (str, ',') then str: = ' "' str '"' Result: = Str; end; // =============================================================================================================================================================================================================================================================================== j, k: integer; tempStr: string; begin try if Not DataSet.Active then DataSet.Open; iRecordCount: = DataSet.RecordCount; iFieldCount: = DataSet.FieldCount; assignFile (ExcelFile, SaveFileName 'csv.'); rewrite (ExcelFile ); Dataset.first; (* -------- write field ------ *) Tempstr: = '; fork: = 0 to ifieldcount-1 do // Number of fields Begin if Tempstr <> '' Ten Tempstr: = Tempstr ',' Checkstr (Dataset.fields [k] .fieldname) Else Tempstr: = Checkstr (dataset.fiel DS [k] .fieldname) end; (* fork: = 1 to FieldCount Do *) for i: = 1 to groupcount-1 do tempstr: = Tempstr ',' Tempstr; Writeln (Excelfile, Tempstr); // --------------------------------- (* Write records, write according to the number of points *) i: = 1 While I <= ROUND (IRecordCount Div GroupCount) Do Begin Tempstr: = '; //, such as: F0 F1 F2 F3 | F0 F1 F2 F3 for J: = 1 TO GroupCount DO // His BEGIN IF Dataset.eof Then Break; INC (I);