提供你输出到EXCEL的方法:
procedure TFrmCheckRecord.BitBtn4Click(Sender: TObject);
var i :integer;
begin
try
if ESumYear.Text='' then
begin
showmessage('请输入年度! 如:2000');
abort;
end;
bXls:=True;
ExcelApp:=CreateOleObject('Excel.Application');
MyWorkBook:=CreateOleobject('Excel.Sheet');
except
on Exception do raise exception.Create('无法打开Xls文件,请确认已 经安装EXCEL')
end;
ExcelApp.Visible := true;
MyworkBook:=ExcelApp.workBooks.Add;
//在此处插入读数据库及写Excel文档的代码
//其中写Excel文档的关键语句如下:
Myworkbook.worksheets[1].range['A1:G1'].Merge(True);
Myworkbook.worksheets[1].range['A1:G2'].HorizontalAlignment := $FFFFEFF4;
MyWorkBook.WorkSheets[1].Cells[1,1].Value := '金东纸业(江苏)有限公司 年终考核汇总表';
i := 2;
MyWorkBook.WorkSheets[1].Cells[i,1].Value := '员工编号';
MyWorkBook.WorkSheets[1].Cells[i,2].Value := '受评人姓名';
MyWorkBook.WorkSheets[1].Cells[i,3].Value := '部门编号';
MyWorkBook.WorkSheets[1].Cells[i,4].Value := '部门名称';
MyWorkBook.WorkSheets[1].Cells[i,5].Value := '到职日期';
MyWorkBook.WorkSheets[1].Cells[i,6].Value := '分数';
MyWorkBook.WorkSheets[1].Cells[i,7].Value := '年度';
Myworkbook.worksheets[1].Range['A1:G2'].Font.Color := clBlue;
Myworkbook.worksheets[1].Range['A1:G1'].Font.Name := '隶书';
Myworkbook.worksheets[1].Range['A1:G1'].Font.Size := 18;
i := 3;
with DM do
begin
QExcelMark.close;
QExcelMark.ParamByName('pYear').AsInteger:=strtoint(ESumYear.Text);
QExcelMark.open;
QExcelMark.First;
while not QExcelMark.eof do begin
MyWorkBook.WorkSheets[1].Cells[i,1].Value := QExcelMark.FieldByName('empNo').AsString;
MyWorkBook.WorkSheets[1].Cells[i,2].Value := QExcelMark.FieldByName('name').AsString;
MyWorkBook.WorkSheets[1].Cells[i,3].Value := QExcelMark.FieldByName('dptNo').AsString;
MyWorkBook.WorkSheets[1].Cells[i,4].Value := QExcelMark.FieldByName('dptName').AsString;
MyWorkBook.WorkSheets[1].Cells[i,5].Value := QExcelMark.FieldByName('dateStarted').Value;
MyWorkBook.WorkSheets[1].Cells[i,6].Value := QExcelMark.FieldByName('sumPoint').AsFloat;
MyWorkBook.WorkSheets[1].Cells[i,7].Value := QExcelMark.FieldByName('chkYear').Value;
QExcelMark.Next; Inc(i);
end;
end; // with DM do
end;