Como primera parte, supongo que estas utilizando un DataSet, asi que primero debe colocar en uses ComObj y Excel97 o Excel2000 o ExcelXp, depende del delphi en mi caso es delphi 7, dentro del procedure debes declarar una variable una variable para la aplicacion de Excel, una para el Libro y otra para la Hoja asi:
Código Delphi
[-]procedure TqrListAcuN.Excel(Titulo: String);
var
ApXls : Variant;
Libro : Variant;
Hoja : Variant;
Fi : Integer;
De ahi en adelante debes utilizar las funciones del excel, te envio el codigo completo para que te sirva de ejemplo, cualquier cosa me avisas
Código Delphi
[-]procedure TqrListAcuN.Excel(Titulo: String);
var
ApXls : Variant;
Libro : Variant;
Hoja : Variant;
Fi : Integer;
begin
try
ApXls := CreateOleObject('Excel.Application');
try
Screen.Cursor := crHourGlass;
ApXls.Visible := False;
ApXls.SheetsInNewWorkbook := 1;
Libro := ApXls.WorkBooks.Add;
Hoja := Libro.WorkSheets[1];
Fi := 1;
qDatos.Open;
Hoja.Cells[Fi,1].Font.Bold := True;
Hoja.Cells[Fi,1] := CambiaEn(qDatosNOMBRE.Value,'@',' ');
qDatos.Close;
Hoja.Range['A'+IntToStr(Fi),'F'+IntToStr(Fi)].Select;
ApXls.Selection.Merge;
ApXls.Selection.HorizontalAlignment := xlCenter;
Inc(Fi,2);
Hoja.Cells[Fi,1] := Titulo;
Hoja.Cells[Fi,1].Font.Bold := True;
Hoja.Range['A'+IntToStr(Fi),'F'+IntToStr(Fi)].Select;
ApXls.Selection.Merge;
ApXls.Selection.HorizontalAlignment := xlCenter;
Inc(Fi,3);
qAcuNc.Open;
while not qAcuNc.Eof do
begin
Inc(Fi);
Hoja.Cells[Fi,1] := 'CODIGO';
Hoja.Cells[Fi,1].Select;
ApXls.Selection.Font.Bold := True;
ApXls.Selection.HorizontalAlignment := xlRight;
Hoja.Cells[Fi,2].Select;
ApXls.Selection.NumberFormat := '@';
ApXls.Selection.HorizontalAlignment := xlLeft;
Hoja.Cells[Fi,2] := qAcuNcCODIGO.Value;
Hoja.Cells[Fi,3] := 'NOMBRE';
Hoja.Cells[Fi,3].Select;
ApXls.Selection.Font.Bold := True;
ApXls.Selection.HorizontalAlignment := xlRight;
Hoja.Range['D'+IntToStr(Fi),'F'+IntToStr(Fi)].Select;
ApXls.Selection.NumberFormat := '@';
ApXls.Selection.HorizontalAlignment := xlLeft;
ApXls.Selection.Merge;
ApXls.Selection.Font.Size := 9;
Hoja.Cells[Fi,4] := qAcuNcNOMBRE.Value;
Inc(Fi,2);
Hoja.Range['A'+IntToStr(Fi),'F'+IntToStr(Fi)].Select;
ApXls.Selection.Font.Bold := True;
Hoja.Cells[Fi,1] := 'FACTURA';
Hoja.Cells[Fi,1].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,2] := 'VALOR';
Hoja.Cells[Fi,2].HorizontalAlignment := xlRight;
Hoja.Cells[Fi,3] := 'FECHA';
Hoja.Cells[Fi,3].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,4] := 'NOTA CR';
Hoja.Cells[Fi,4].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,5] := 'VALOR';
Hoja.Cells[Fi,5].HorizontalAlignment := xlRight;
Hoja.Cells[Fi,6] := 'FECHA';
Hoja.Cells[Fi,6].HorizontalAlignment := xlCenter;
Inc(Fi);
Hoja.Cells[Fi,1].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,2].HorizontalAlignment := xlRight;
Hoja.Cells[Fi,2].NumberFormat := '#.##0';
Hoja.Cells[Fi,3].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,3].NumberFormat := 'dd.mmm.yyy';
Hoja.Cells[Fi,4].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,5].HorizontalAlignment := xlRight;
Hoja.Cells[Fi,5].NumberFormat := '#.##0';
Hoja.Cells[Fi,6].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,6].NumberFormat := 'dd.mmm.yyy';
Hoja.Cells[Fi,1] := qAcuNcFACTU.Value;
Hoja.Cells[Fi,2] := qAcuNcVR_FAC.Value;
Hoja.Cells[Fi,3] := qAcuNcFECHAF.Value;
Hoja.Cells[Fi,4] := qAcuNcNUME.Value;
Hoja.Cells[Fi,5] := qAcuNcVALOR.Value;
Hoja.Cells[Fi,6] := qAcuNcFECHAN.Value;
qRcMes.Open;
If not qRcMes.IsEmpty then
begin
Inc(Fi);
Hoja.Range['C'+IntToStr(Fi),'F'+IntToStr(Fi)].Select;
ApXls.Selection.Font.Bold := True;
Hoja.Cells[Fi,3] := 'RECIBO';
Hoja.Cells[Fi,3].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,4] := 'CONSIG';
Hoja.Cells[Fi,4].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,5] := 'VALOR';
Hoja.Cells[Fi,5].HorizontalAlignment := xlRight;
Hoja.Cells[Fi,6] := 'FECHA';
Hoja.Cells[Fi,6].HorizontalAlignment := xlCenter;
Inc(Fi);
end;
while not qRcMes.Eof do
begin
Hoja.Cells[Fi,3] := qRcMesID_REC.Value;
Hoja.Cells[Fi,3].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,4] := qRcMesCONSIG.Value;
Hoja.Cells[Fi,4].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,5] := qRcMesVR_REC.Value;
Hoja.Cells[Fi,5].HorizontalAlignment := xlRight;
Hoja.Cells[Fi,5].NumberFormat := '#.##0';
Hoja.Cells[Fi,6] := qRcMesFECHA.Value;
Hoja.Cells[Fi,6].HorizontalAlignment := xlCenter;
Hoja.Cells[Fi,6].NumberFormat := 'dd.mmm.yyy';
Inc(Fi);
qRcMes.Next;
end;
qRcMes.Close;
Inc(Fi,2);
qAcuNc.Next;
end;
qAcuNc.Close;
finally
Screen.Cursor := crDefault;
try Hoja.Cells.Columns.AutoFit; except end;
Hoja.Columns['B'].ColumnWidth := Hoja.Columns['B'].ColumnWidth + 2;
Hoja.Columns['E'].ColumnWidth := Hoja.Columns['E'].ColumnWidth + 2;
Hoja.Columns['C'].ColumnWidth := Hoja.Columns['C'].ColumnWidth + 2;
Hoja.Columns['F'].ColumnWidth := Hoja.Columns['F'].ColumnWidth + 2;
ApXls.Visible := True;
end;
except
SM.MessageDlg('Excel no se encuentra instalado en este equipo, no se puede exportar',mtError,[mbOk],0);
end;