本人做的报表导入excel
procedure Tsals002r1Frm.ReportToExcel(wkBook:_Workbook;SheetNumber:integer);
var
Datas : Variant;
tempstr:string;
wkSheet:_Worksheet;
line,col,i,j,z:integer;
aray, total1,total2,total3:real;
begin
i:=0;j:=12;
salsorddet.Open;
tempstr:='select distinct cust_pono ';
tempstr:=tempstr+copy(salsorddet.CommandText,pos('from',salsorddet.CommandText),length(salsorddet.CommandText));
ADODataSet2.close;
ADODataSet2.CommandText:=tempstr;
ADODataSet2.open;
tempstr:='';
col := SalsOrdDet.RecordCount;
line := 33+col+1+ADODataSet2.recordcount+adodataset3.RecordCount;
Datas:= varArrayCreate([1,line,1,10],varVariant);
wksheet:=wkbook.Worksheets.add(emptyparam,emptyparam,emptyparam,emptyparam,SheetNumber)as _worksheet;
wksheet.Cells.HorizontalAlignment:=xlcenter;
wksheet.Name:=SalsOrdHdr.Fieldbyname('sono').asstring;
wksheet.cells.Item[1,1].columnwidth:=3;
wksheet.cells.Item[1,2].columnwidth:=5;
wksheet.cells.Item[1,3].columnwidth:=6;
wksheet.cells.Item[1,4].columnwidth:=11;
wksheet.cells.Item[1,5].columnwidth:=19;
wksheet.cells.Item[1,6].columnwidth:=7;
wksheet.cells.Item[1,7].columnwidth:=6;
wksheet.cells.Item[1,8].columnwidth:=5;
wksheet.cells.Item[1,9].columnwidth:=5;
wksheet.cells.Item[1,10].columnwidth:=6;
Datas[1,5] := 'COE LIMITED';
wksheet.Cells.Item[1,5].font.size:=22;
Datas[2,5] := 'G/F,3C KENT ROAD,KOWLOON TONG';
Datas[3,5] := 'KOWLOON,HONG KONG';
Datas[4,5] := 'TEL
852)23760133 FAX
852)23770971';
Datas[5,5] := 'E-MAIL:coeltd@netvigator.com';
wksheet.Range[wksheet.Cells.Item[2,5],wksheet.cells.Item[5,5]].Font.size:=8;
Datas[6,5] := 'PROFORMA INVOICE';
wksheet.Cells.Item[6,5].font.size:=22;
wksheet.Range[wksheet.cells.item[7,1],wksheet.cells.item[10,10]].font.size:=8;
Datas[7,7] := 'Form No: QR002-14-02 Edition:A';
Datas[8,1] := 'Proforma Invoice '+SalsOrdHdr.Fieldbyname('sono').asstring;
if SalsOrdHdr.Fieldbyname('pDate').AsString<>'' then
Datas[8,7] := 'Data : '+ Formatdatetime('mmm,dd,yyyy',SalsOrdHdr.Fieldbyname('pDate').value)
else
Datas[8,7] := 'Data : '+ Formatdatetime('mmm,dd,yyyy',date);
Datas[9,1] := 'Customer: ' + SalsOrdHdr.Fieldbyname('custname').asstring;
wksheet.Range[wksheet.cells.Item[8,1],wksheet.cells.item[9,1]].HorizontalAlignment:=xlleft;
Datas[9,7] := 'Ref.No: '+ SalsOrdHdr.Fieldbyname('ref_no').asstring;
Datas[10,2] := SalsOrdHdr.Fieldbyname('custaddr1').asstring;
Datas[10,7] := 'Order Data: '+ FormatDatetime('mmm,dd,yyyy',SalsOrdHdr.Fieldbyname('ord_date').value);
Datas[11,1] := 'List';
Datas[11,2] := 'Customer '+#13+'Model NO';
Datas[11,3] := 'COE '+#13+'Model No';
Datas[11,4] := 'Delivery'+#13+'Time';
Datas[11,5] := 'Description';
Datas[11,6] := 'Qty'+#13+'(Sets)';
Datas[11,7] := 'Unit Price'+#13+'USD FOB China';
Datas[11,8] := 'Amount'+#13+'(USD)';
Datas[11,9] := 'Unit'+#13+'Volume';
Datas[11,10] := 'Sub'+#13+'(CBM)';
wksheet.Range[wksheet.Cells.Item[11,1],wksheet.cells.item[11,10]].Font.size:=9;
with SalsOrdDet do
begin
DisableControls;
First;
while not Eof do
begin
if tempstr<>SalsOrdDetcust_pono.AsString then
begin
tempstr:=SalsOrdDetcust_pono.AsString;
wksheet.Range[wksheet.Cells.item[12+i,1],wksheet.cells.item[12+i,10]].Borders.item[3].LineStyle:=1;
datas[12+i,5]:='P.O:'+SalsOrdDetcust_pono.AsString;
inc(i);//inc(j);
datas[12+i,5]:=SalsOrdDetPName.AsString;
//j:=length(SalsOrdDetPName.AsString)div 19;
end
else
begin
datas[12+i,5]:=SalsOrdDetPName.AsString;
//j:=length(SalsOrdDetPName.AsString)div 19;
end;
{if j=32 then
wksheet.range[wksheet.cells.item[j,1],wksheet.cells.item[j,10]].Borders.item[4].LineStyle:=1;
}
Datas[12+i,1] := SalsOrdDetseq_calculate.Value;
Datas[12+i,2] :=#13+SalsOrdDetcust_pno.AsString;
Datas[12+i,3] :=#13+SalsOrdDetprod_no.AsString;
if SalsOrdDetprd_del_d.AsString<>'' then
Datas[12+i,4] := Formatdatetime('mmm,dd,yyyy',SalsOrdDetprd_del_d.Value)
else
Datas[12+i,4] := SalsOrdDetprd_del_d.AsString;
//Datas[12+i,5] := SalsOrdDetcust_pono.AsString+#13+' '+SalsOrdDetPName.AsString;
Datas[12+i,6] := SalsOrdDetord_q.asstring;
Datas[12+i,7] := SalsOrdDetunit_price.AsString;
Datas[12+i,8] := SalsOrdDetAmount.AsString;
Datas[12+i,9] := SalsOrdDetunit_volume.AsString;
Datas[12+i,10] := SalsOrdDetSubCbm.AsString;
if ADODataSet3.RecordCount<>0 then
begin
ADODataSet3.first;
z:=i+1;
while not ADODataSet3.Eof do
begin
i:=i+1;
Datas[12+i,3]:=ADODataSet3.fieldbyname('pno').asstring;
Datas[12+i,5]:=ADODataSet3.fieldbyname('pnoremark').asstring;
Datas[12+i,6]:=ADODataSet3.fieldbyname('qty_per').asstring;
adodataset3.next;
end;
end;
if SalsOrdDet.Fieldbyname('ord_q').asstring<>'' then
total1 :=total1+SalsOrdDet.Fieldbyname('ord_q').value;
if SalsOrdDet.Fieldbyname('Amount').asstring<>'' then
Total2 :=Total2+SalsOrdDet.Fieldbyname('Amount').value;
if SalsOrdDet.Fieldbyname('subcbm').asstring<>'' then
Total3 :=Total3+SalsOrdDet.Fieldbyname('Subcbm').value;
i:=i+1;
Next;
end;
EnableControls;
end;
wksheet.Range[wksheet.Cells.item[12,5],wksheet.cells.item[12+i,5]].HorizontalAlignment:=xlleft;
wksheet.Range[wksheet.Cells.item[12,1],wksheet.cells.item[12+i,10]].verticalAlignment:=xltop;
wksheet.range[wksheet.cells.item[11,1],wksheet.cells.item[12+i,10]].WrapText:=true;
SalsOrdInstruction.Open;
Datas[13+i,5] := 'TOTAL';
Datas[13+i,6] := floattostr(total1);
Datas[13+i,8] := floattostr(total2);
Datas[13+i,10] := floattostr(total3);
Datas[14+i,1] := 'Terms and L/C Shipping Instructions:';
Datas[15+i,1] := 'Payment Method '+ SalsOrdInstructionPaytermDesc.AsString;
Datas[16+i,1] := 'Delivery Method '+SalsOrdInstructiondel_mth.AsString;
Datas[17+i,1] := 'Port of Loading '+SalsOrdInstructionport_of_loading.AsString;
Datas[18+i,1] := 'Port of Discharge '+SalsOrdInstructionport_of_discharge.AsString;
Datas[19+i,1] := 'Forwarder '+SalsOrdInstructionforwarder.AsString;
Datas[20+i,1] := 'Packing '+SalsOrdInstructionPacking.AsString;
{CASE SalsOrdInstructionpartial_del.AsString[1] OF
'A'
atas[21+i,1] := 'Partial Delivery '+'ALLOWED' ;
'U'
atas[21+i,1] := 'Partial Delivery '+'UNALLOWED';
ELSE
Datas[21+i,1] := 'Partial Delivery '+'';
END;
CASE SalsOrdInstructiontranshipment.AsString[1] OF
'A'
atas[22+I,1] :='Transhipment '+'ALLOWED';
'U'
atas[22+i,1] :='Transhipment '+'UNALLOWED';
else
Datas[22+i,1] :='Transhipment ';
end;}
if SalsOrdInstructionpartial_del.AsString='A' then
Datas[21+i,1] := 'Partial Delivery '+'ALLOWED'
else if SalsOrdInstructionpartial_del.AsString='U' then
Datas[21+i,1] := 'Partial Delivery '+'UNALLOWED'
else
Datas[21+i,1] := 'Partial Delivery '+'';
if SalsOrdInstructiontranshipment.AsString='A' then
Datas[22+i,1] :='Transhipment '+'ALLOWED'
else if SalsOrdInstructiontranshipment.AsString='U' then
Datas[22+i,1] :='Transhipment '+'UNALLOWED'
else
Datas[22+i,1] :='Transhipment ';
Datas[23+i,1] := 'Destination '+SalsOrdInstructiondestination.AsString;
Datas[24+i,1] := 'Consignee '+SalsOrdInstructionconsignee.AsString;
Datas[25+i,1] := 'Insturance '+SalsOrdInstructioninsturance.AsString;
Datas[26+i,1] := 'Qty & Amount '+SalsOrdInstructionqty_amount.AsString;
Datas[27+i,1] := 'Inspection '+SalsOrdInstructioninspection.AsString;
Datas[28+i,1] := 'Re-Export C/O '+SalsOrdInstructionre_export.AsString;
Datas[29+i,1] := 'Bill of Lading '+SalsOrdInstructionbill_of_lading.AsString;
Datas[30+i,1] := 'L/C Charges '+SalsOrdInstructionlc_charges.AsString;
Datas[31+i,1] := 'Banker '+SalsOrdInstructionbanker_name.AsString;
Datas[32+i,1] := ' '+SalsOrdInstructionbanker_addr.AsString;
Datas[33+i,1] := ' '+SalsOrdInstructionbanker_ac_no.AsString;
Datas[34+i,1] := 'Remarks '+SalsOrdInstructionremarks.AsString;
wksheet.range[wksheet.cells.item[14+i,1],wksheet.cells.item[34+i,1]].font.size:=10;
wksheet.range[wksheet.cells.item[14+i,1],wksheet.cells.item[34+i,1]].HorizontalAlignment:=xlleft;
{ wkSheet:=wkBook.WorkSheets.Add(EmptyParam,
EmptyParam,EmptyParam,EmptyParam,0)
as _WorkSheet; }
with wkSheet do
begin
Range[cells.Item[1,1],cells.Item[line,10]].Value:=Datas;
end;
wksheet.Range[wksheet.cells.item[11,1],wksheet.cells.item[11,10]].borders.linestyle:=1;
wksheet.Range[wksheet.cells.item[11,1],wksheet.cells.item[13+i,10]].Borders.item[1].linestyle:=1;
wksheet.Range[wksheet.cells.item[11,1],wksheet.cells.item[13+i,10]].Borders.item[2].linestyle:=1;
wksheet.Range[wksheet.cells.item[13+i,1],wksheet.cells.item[13+i,10]].Borders.item[4].linestyle:=1;
Datas:=Unassigned;
with wkSheet.Range[wkSheet.Cells.Item[1,1],wkSheet.Cells.Item[6,10]],Font do
begin
Merge(True); //合并单元格
HorizontalAlignment:= xlCenter;
FontStyle:=Bold;
end;
end;