There are many ways to export data to Excel, and there are three speeds. I have used three methods. The speed is faster. One of the following is to use temporary files. Compared with the former method, open temporary When the file can specify the character set encoding, so it can guarantee that Chinese content is exported correctly.
Function ExportBytmpfile: Boolean; Var List: TstringList; FileName, TmpFile: String; Buffer: Array [0..max_path] of char; asheet: variant; begin // Call the function of the above example ShowProgress (0, AdoQuery1). RecordCount 3, 0); Result: = true; filename: = 'c: /abc.xls'; // The file name is modified according to the actual situation, and the parameter is incoming // generates a temporary file name GetTemppath (Max_Path, Buffer) ; TMPFILE: = Buffer; if Rightstr (TmpFile, 1) <> '/' THENTMPFILE: = TmpFile '/'; tmpfile: = TmpFile '~ TMP' INTOSTR (GettickCount) '.txt'; list: = TSTRINGLIST.CREATE; TRY TRY / / Call the above example to read the data into the list, saved to TMPFile if getDataList (list) the beginning (tmpfile); progressbar1.stepit; end; finally list.free; EXCEPT RESULT: = false; pnlprogress.visible: = false; exit; end; Excel.connect; // Open Excel (Excel: Texcelapplication control) Try Excel.displayAlerts [0]: = false; Excel.visible [0] : = false; Excel.caption: = 'XXXX Title (Excel)'; // Excel opens a temporary file, specifying the internal code for Simplified Chinese Excel.Workbooks.opentext (Tmpfile, 936, 1, Xldelimited, Xldouble Quote, False, True, False, False, False, False, False, Null, Null, Null, Null , 0); //excel.workbooks.add(XLwbatworksheet, 0); asheet: = Excel.Worksheets.Item [1]; //Excel.Workbooks.Item[1].activate(0); // Set display Format asheet.cells.font.name: = 'Song body'; asheet.cells.font.size: = 10; asheet.cells.VerticalAlignment: = 2; asheet.range ['a1', 'z1']. HorizontaLAlignment: = 7;