在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
可能以后会用到,记录一下: 导出EXCEL var h,k:integer; Excelid: OleVariant; s: string; begin try Excelid := CreateOLEObject('Excel.Application'); except Application.MessageBox('Excel没有安装!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL); Exit; end; try Tblrs.Close; Tblrs.SQL.Clear; Tblrs.SQL.Add('select * from rszl'); Tblrs.Open; k:=Tblrs.RecordCount; Excelid.Visible := True; Excelid.WorkBooks.Add; Excelid.worksheets[1].range['A1:C1'].Merge(True); //A1到C1的单元格进行合并 Excelid.WorkSheets[1].Cells[1,1].Value :='人事表' ; //给A1到C1的单元格合并后取一个TITLE Excelid.WorkSheets[1].Cells[2,1].Value :='工号' ; Excelid.WorkSheets[1].Cells[2,2].Value :='姓名' ; Excelid.WorkSheets[1].Cells[2,3].Value :='性别' ; //给A1到C1的单元格 设置字体 字号 加粗 Excelid.worksheets[1].Range['A1:C1'].Font.Name := '宋体'; Excelid.worksheets[1].Range['A1:C1'].Font.Size := 14; Excelid.worksheets[1].Range['A1:C1'].Font.Bold:=true; //填充入值 h:=3; Tblrs.First; while not Tblrs.Eof do begin Excelid.WorkSheets[1].Cells[h,1].Value := Tblrs.FieldByName('ygbh').AsString; Excelid.WorkSheets[1].Cells[h,2].Value := Tblrs.FieldByName('mc').AsString; Excelid.WorkSheets[1].Cells[h,3].Value := Tblrs.FieldByName('sex').AsString; Inc(h); Tblrs.Next; end; except Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL); end; MessageBox(GetActiveWindow(), 'EXCEL数据导出成功!', '提示信息', MB_OK +MB_ICONWARNING);
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论