Quickly export data to Excel (1): Use clipboard

xiaoxiao2021-03-06  14

There are many ways to export data to Excel. There are three speeds. I have used three methods, the speed is faster, the following is through the clipboard, but the system over one W2K, due to the character set Different coding, the Chinese content may become garbled after exporting to Excel.

// function defined BlockInput function BlockInput (fBlockInput: boolean): DWord; stdcall; external 'user32.DLL'; // display a progress bar panel procedure ShowProgress (Min, Max, Position: integer); begin // pnlProgress: TPanel, ProgressBar1 : TProgressBar pnlProgress.Left: = (ClientWidth - pnlProgress.Width) div 2; ProgressBar1.Min: = Min; ProgressBar1.Max: = Max; ProgressBar1.Position: = Position; pnlProgress.Visible: = true; pnlProgress.Update; end // Add database data to DataListFunction GetDataList (Datalist: tstringlist): boolean; var s: string; i: integer; begin result: = true; datalist.clear; try try datalist.add ('This is title'); Progressbar1.stepit; adoQuery1.disablecontrols; with adoquery1 do beg, first; s: = '; for i: = 0 to fieldcount-1 do iffields [i] .visible the: = s fields [i] .displaylabel # 9; // Prompt the field name, separate DATALIST.ADD (S) with a tactic: ProgressBar1.Stepit; While NOT EOF Do Begi n s: = ''; for i: = 0 to FieldCount-1 Do if Fields [i] .visible the: = s Fields [i] .displaytext # 9; // Export Data Show content DataList.Add ( S); ProgressBar1.StepIt; Application.ProcessMessages; Next; end; end; except Result: = false; end; finally ADOQuery1.EnableControls; end; end; function ExportByClipboard: Boolean; var List: TStringList; FileName: string; ASheet: Variant; Begin ShowProgress (0, AdoQuery1.Recordcount 3, 0); Result: = true; filename: =

'C: /abc.xls'; Excel.Connect; // Excel: Texcelapplication control TRY Excel.displayAlerts [0]: = false; Excel.visible [0]: = false; Excel.caption: =' xxxxx export ( Excel) '; Excel.workBooks.add (xlwbatworksheet, 0); asheet: = Excel.Worksheets.Item [1]; // Set the default format Excel.cells.Font.Name: =' Song body '; Excel.cells. Font.size: = 10; Excel.cells.VerticalAlignment: = 2; // Setting the title format Excel.Range ['A1', 'Z1']. Horizontalalignment: = 7; Excel.Range ['A1', 'Z1 '] .Font.size: = 16; Excel.Range [' A1 ',' Z1 ']. RowHeight: = 22; Excel.Range [' A2 ',' Z2 ']. Horizontalalignment: = 3; Excel.Range 'A2', 'Z2']. Font.bold: = true; list: = tstringlist.create; try = tstringlist (List) THEN BEGIN / / Lock computer and spherped the data into Excel BlockInput (TRUE); Clipboard. Astext: = list.text; asheet.paste; clipboard.clear; blockinput (false); Progressbar1.stepit; end; finally list: = false; pnlprogress.visible: = false; exit; end; progressbar1.stepit; Excel.Workbooks.Item [1] .savecopyas (filename, 0); Excel.Workbooks.Item [1] .close (False, FileName, 0, 0); Finally Excel.quit; Excel.disconnect; End; Except Result: = false; pnlprogress.visible: = false; exit; end; progressbar1. Position: = progravelbar1.max;

转载请注明原文地址:https://www.9cbs.com/read-50829.html

New Post(0)