没什么好说的,就是一个导出Excel的功能,代码如下:
function TExportToExcel.Export(SGrid_List: TStringGrid;filename:string;out Errstr:string): Boolean; varexcelapp:Variant;page:Variant;i,j:Integer;savedialog:TSaveDialog;strsavefile:string; begintryresult := false;savedialog := TSaveDialog.Create(self);trysavedialog.FileName := filename;savedialog.Filter := '*.xls';if not savedialog.Execute() thenexit;strsavefile := savedialog.FileName;Screen.Cursor:=crhourglass; //屏幕指针形状excelapp := CreateOleObject('excel.application');excelapp.workbooks.add;excelapp.workbooks[1].worksheets[1].name:=filename;page:=excelapp.workbooks[1].worksheets[filename];for i:= 0 to SGrid_List.RowCount-2 dobegin//第一列没有数据,不用for j:=1 to SGrid_List.ColCount-1 dobeginpage.cells[i+1,j]:= SGrid_List.Cells[j,i];end;end;excelapp.activeworkbook.saveas(strsavefile);Application.ProcessMessages;excelapp.application.quit;result := true;finallysavedialog.Free;Screen.Cursor:=crDefault;end;excepton E:Exception dobeginErrstr := e.Message;result := false;end;end; end;