procedure TrepForm.doit;
var
i,j,k1,k2,kkkk:integer;
memolist:tstringlist;
s_dj,s_zj:string;
tot:real;
begin
tot:=0;
try
MsExcel:=CreateOleObject('Excel.Application');
MsExcelWorkBook:=MsExcel.WorkBooks.Add;
MsExcelWorkSheet:=MsExcel.Sheets['Sheet1'];
except
showerror('无法打开 EXCEL 97');
exit;
end;
memolist:=tstringlist.Create;
MsExcel.Visible:=True;
MsExcelWorkSheet.Range['A2:E2'].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=3;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A2:E2'].value:='采购合同';
kkkk:=4;
MsExcelWorkSheet.Range['C'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['C'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='合同号码:'+maintable.fieldbyname('ht_id').asstring;
memolist.assign(maintable.fieldbyname('bftt'));
if memolist.count=0 then
memolist.add(maintable.fieldbyname('wfgs').asstring);
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':B'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':B'+inttostr(kkkk)].value:='买方:'+memolist.strings[0];
for i:=1 to (memolist.count-1)do
begin
MsExcelWorkSheet.Range['A'+inttostr(kkkk+i)+':B'+inttostr(kkkk+i)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+i)+':B'+inttostr(kkkk+i)].value:=kong(7)+memolist.strings
;
end;
kkkk:=kkkk+memolist.count;
MsExcelWorkSheet.Range['C'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['C'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='合同日期:'+maintable.fieldbyname('dateis').asstring;
memolist.assign(maintable.fieldbyname('ttr'));
if memolist.count=0 then
memolist.add(maintable.fieldbyname('supplier').asstring);
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':B'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':B'+inttostr(kkkk)].value:='卖方:'+memolist.strings[0];
for i:=1 to (memolist.count-1)do
begin
MsExcelWorkSheet.Range['A'+inttostr(kkkk+i)+':B'+inttostr(kkkk+i)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+i)+':B'+inttostr(kkkk+i)].value:=kong(8)+memolist.strings;
end;
kkkk:=kkkk+memolist.count;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':B'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':B'+inttostr(kkkk)].value:='签约地点:'+maintable.fieldbyname('qddd').asstring;
MsExcelWorkSheet.Range['C'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['C'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='交货日期:'+maintable.fieldbyname('jhdate').asstring;
kkkk:=kkkk+2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='一、品名、规格、数量、金额:';
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)].Value:='货号';
MsExcelWorkSheet.Range['A'+inttostr(kkkk)].select;
MsExcel.selection.columnwidth:=15;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['B'+inttostr(kkkk)].Value:='品质说明';
MsExcelWorkSheet.Range['B'+inttostr(kkkk)].select;
MsExcel.selection.columnwidth:=30;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['C'+inttostr(kkkk)].Value:='数量';
MsExcelWorkSheet.Range['C'+inttostr(kkkk)].select;
MsExcel.selection.columnwidth:=10;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['D'+inttostr(kkkk)].Value:='单价';
MsExcelWorkSheet.Range['D'+inttostr(kkkk)].select;
MsExcel.selection.columnwidth:=12;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['E'+inttostr(kkkk)].Value:='总价';
MsExcelWorkSheet.Range['E'+inttostr(kkkk)].select;
MsExcel.selection.columnwidth:=10;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':'+'E'+inttostr(kkkk)].select;
msexcel.selection.Borders[7].LineStyle:=1;//left
msexcel.selection.Borders[8].LineStyle:=1;//top
msexcel.selection.Borders[9].LineStyle:=1;//bottom
msexcel.selection.Borders[10].LineStyle:=1;//right
msexcel.selection.Borders[11].LineStyle:=1;//内部垂直
if qtsql.active then
qtsql.close;
qtsql.sql.clear;
qtsql.sql.Add('select * from nxhtsheet99');
qtsql.sql.Add('where ht_id='+''''+maintable.fieldbyname('ht_id').asstring+'''');
qtsql.open;
qtsql.first;
j:=1;
while qtsql.eof=falsedo
begin
memolist.Assign(qtsql.fieldbyname('shm'));
if memolist.count=0 then
memolist.add('');
s_dj:=maintable.fieldbyname('hbdm').asstring+qtsql.fieldbyname('unite_price').asstring+'/'+qtsql.fieldbyname('dw1').asstring;
s_zj:=maintable.fieldbyname('hbdm').asstring+format('%.2f',[qtsql.fieldbyname('unite_price').asfloat*qtsql.fieldbyname('pcs').asfloat]);
tot:=tot+qtsql.fieldbyname('unite_price').asfloat*qtsql.fieldbyname('pcs').asfloat;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+j)].Value:=qtsql.fieldbyname('product_id').asstring;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['B'+inttostr(kkkk+j)].Value:=memolist.strings[0];
MsExcelWorkSheet.Range['B'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['C'+inttostr(kkkk+j)].Value:=qtsql.fieldbyname('pcs').asstring+qtsql.fieldbyname('dw1').asstring;
MsExcelWorkSheet.Range['C'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['D'+inttostr(kkkk+j)].Value:=s_dj;
MsExcelWorkSheet.Range['D'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['E'+inttostr(kkkk+j)].Value:=s_zj;
MsExcelWorkSheet.Range['E'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
k1:=j;
for i:=1 to (memolist.count-1)do
begin
j:=j+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+j)].Value:='';
MsExcelWorkSheet.Range['A'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['B'+inttostr(kkkk+j)].Value:=memolist.strings;
MsExcelWorkSheet.Range['B'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['C'+inttostr(kkkk+j)].Value:='';
MsExcelWorkSheet.Range['C'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['D'+inttostr(kkkk+j)].Value:='';
MsExcelWorkSheet.Range['D'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcelWorkSheet.Range['E'+inttostr(kkkk+j)].Value:='';
MsExcelWorkSheet.Range['E'+inttostr(kkkk+j)].select;
MsExcel.Selection.HorizontalAlignment:=2;
end;
k2:=j;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+k1)+':A'+inttostr(kkkk+k2)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=1;
// MsExcelWorkSheet.Range['B'+inttostr(kkkk+k1)+':B'+inttostr(kkkk+k2)].select;
// MsExcel.Selection.merge;
MsExcelWorkSheet.Range['C'+inttostr(kkkk+k1)+':C'+inttostr(kkkk+k2)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=1;
MsExcelWorkSheet.Range['D'+inttostr(kkkk+k1)+''+inttostr(kkkk+k2)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=1;
MsExcelWorkSheet.Range['E'+inttostr(kkkk+k1)+':E'+inttostr(kkkk+k2)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+k1)+':E'+inttostr(kkkk+k2)].select;
msexcel.selection.Borders[7].LineStyle:=1;//left
msexcel.selection.Borders[8].LineStyle:=1;//top
msexcel.selection.Borders[9].LineStyle:=1;//bottom
msexcel.selection.Borders[10].LineStyle:=1;//right
msexcel.selection.Borders[11].LineStyle:=1;//内部垂直
j:=j+1;
qtsql.next;
end;
kkkk:=kkkk+j;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+''+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=4;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+''+inttostr(kkkk)].value:='金额合计:';
MsExcelWorkSheet.Range['E'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['E'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:=maintable.fieldbyname('hbdm').asstring+format('%.2f',[tot]);
kkkk:=kkkk+2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='二、质量技术标准:'+maintable.fieldbyname('zlyq').asstring;
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='三、交货地点:'+maintable.fieldbyname('fhyq').asstring;
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='四、包装要求:'+maintable.fieldbyname('bzyq').asstring;
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='五、质量检验:'+maintable.fieldbyname('jfcl').asstring;
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='六、结算方式:'+maintable.fieldbyname('jsfs').asstring;
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='七、运输要求:'+maintable.fieldbyname('ysfs').asstring;
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='八、损耗计算:'+maintable.fieldbyname('shjs').asstring;
kkkk:=kkkk+1;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='九、配件供应:'+maintable.fieldbyname('pjgy').asstring;
memolist.assign(maintable.fieldbyname('memo'));
if memolist.count=0 then
memolist.add('');
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk)+':E'+inttostr(kkkk)].value:='十、合同备注:'+memolist.strings[0];
for i:=1 to (memolist.count-1)do
begin
MsExcelWorkSheet.Range['A'+inttostr(kkkk+i)+':E'+inttostr(kkkk+i)].select;
MsExcel.Selection.merge;
MsExcel.Selection.HorizontalAlignment:=2;
MsExcel.Selection.VerticalAlignment:=2;
MsExcelWorkSheet.Range['A'+inttostr(kkkk+i)+':E'+inttostr(kkkk+i)].value:=kong(19)+memolist.strings;
end;
memolist.free;
end;