//生产经营去向台帐// 跟你的要求一模一样
//单位 一类 二类 三类
1 200 300 400
你自己看一下吧
procedure Treportfrm.shjyqxtz1;
var
i,J,dwbh,row,colmn,a:integer;
filetype:smallint;
month,year,day:word;
begin
with datamodule1.REPORTQRY1do
begin
close;
sql.Clear;
sql.Add('truncate table report');
execsql;
close;
sql.Clear;
sql.add('insert into report select dwbh,bh,fcj from clmx where dwbh is not null ');
sql.add(' union all select dwbh,bh,fcj from clmxyk where dwbh is not null');
execsql;
close;
end;
decodedate(now,year,month,day);
filetype:=F1FileExcel5;
f1book1.read(ExtractFileDir(paramstr(0))+'/f1book1.xls',filetype);
REPORTFRM.Refresh;
//表1
row:=1;DWBH:=-1;
f1book1.sheet:=1;
with DATAMODULE1.REPORTQRY1do
begin
CLOSE;
SQL.CLEAR;
SQL.ADD('select dwbh,bh,sum(fcj) from report where dwbh is not null group by dwbh,bh order by dwbh,bh ' );
OPEN;
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eofdo
begin
IF DWBH<>fieldbyname('dwbh').asinteger then
begin
ROW:=ROW+1;
DWBH:=fieldbyname('dwbh').asinteger;
end;
colmn:=fieldbyname('bh').asinteger;
IF COLMN>19 then
begin
next;
CONTINUE;
end;
f1book1.textrc[row+4,1]:=fields[0].asSTRING;
f1book1.numberrc[row+4,colmn+2]:=fields[2].asfloat;
next;
end;
end;
a:=row+4;
//
ROW:=1;
DWBH:=-1;
with DATAMODULE1.REPORTQRy2do
begin
CLOSE;
SQL.CLEAR;
SQL.ADD('SELECT DWBH,SUM(FCJ) FROM report WHERE DWBH IS NOT NULL GROUP BY DWBH ORDER BY DWBH');
OPEN;
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eofdo
begin
IF DWBH<>fieldbyname('dwbh').asinteger then
begin
ROW:=ROW+1;
DWBH:=fieldbyname('dwbh').asinteger;
end;
if f1book1.TextRC[row+4,1]='' then
f1book1.textrc[row+4,1]:=fields[0].asSTRING;
f1book1.numberrc[row+4,2]:=fields[1].asfloat;
next;
end;
F1BOOK1.FormulaRC[4,2]:='SUM(B4:B80)';
f1book1.TextRC[1,1]:='1--'+inttostr(month)+'月份生产(经营)耗用物资及去向台帐';
f1book1.TextRC[2,2]:=datetostr(now);
end;
//OK }
//table 2
f1book1.Sheet:=2;
row:=1;DWBH:=-1;
with DATAMODULE1.REPORTqry1do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eofdo
begin
IF DWBH<>fieldbyname('dwbh').asinteger then
begin
ROW:=ROW+1;
DWBH:=fieldbyname('dwbh').asinteger;
end;
colmn:=fieldbyname('bh').asinteger;
IF (COLMN<=19) or (colmn>=40) then
begin
next;
CONTINUE;
end;
f1book1.textrc[row+4,1]:=fields[0].asSTRING;
f1book1.numberrc[row+4,colmn-18]:=fields[2].asfloat;
next;
end;
end;
//
ROW:=1;dwbh:=-1;
with DATAMODULE1.REPORTqry2do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eofdo
begin
IF DWBH<>fieldbyname('dwbh').asinteger then
begin
ROW:=ROW+1;
DWBH:=fieldbyname('dwbh').asinteger;
end;
if f1book1.TextRC[row+4,1]='' then
f1book1.textrc[row+4,1]:=fields[0].asSTRING;
next;
end;
f1book1.TextRC[1,1]:='1--'+inttostr(month)+'月份生产(经营)耗用物资及去向台帐(续一)';
f1book1.TextRC[2,2]:=datetostr(now);
end;
//
//table 3
f1book1.Sheet:=3;
row:=1;DWBH:=-1;
with DATAMODULE1.REPORTqry1do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eofdo
begin
IF DWBH<>fieldbyname('dwbh').asinteger then
begin
ROW:=ROW+1;
DWBH:=fieldbyname('dwbh').asinteger;
end;
colmn:=fieldbyname('bh').asinteger;
IF (COLMN<40) then
begin
next;
CONTINUE;
end;
f1book1.textrc[row+4,1]:=fields[0].asSTRING;
if colmn=99 then
f1book1.numberrc[row+4,21]:=fields[2].asfloat
else
f1book1.numberrc[row+4,colmn-38]:=fields[2].asfloat;
next;
end;
CLOSE;
end;
//
ROW:=1;dwbh:=-1;
with DATAMODULE1.REPORTqry2do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eofdo
begin
IF DWBH<>fieldbyname('dwbh').asinteger then
begin
ROW:=ROW+1;
DWBH:=fieldbyname('dwbh').asinteger;
end;
if f1book1.TextRC[row+4,1]='' then
f1book1.textrc[row+4,1]:=fields[0].asSTRING;
next;
end;
CLOSE;
end;
f1book1.TextRC[1,1]:='1--'+inttostr(month)+'月份生产(经营)耗用物资及去向台帐(续二)';
f1book1.TextRC[2,2]:=datetostr(now);
with DATAMODULE1.REPORTqry1do
begin
CLOSE;
SQL.CLEAR;
SQL.ADD('select bh,sum(fcj) from report where dwbh is not null group by bh order by bh');
OPEN;
first;
while not eofdo
begin
colmn:=strtoint(fields[0].asstring);
if colmn<=19 then
begin
f1book1.sheet:=1;
f1book1.numberRC[4,colmn+2]:=fields[1].asfloat;
end;
if (colmn>19) and (colmn<=39) then
begin
f1book1.sheet:=2;
f1book1.numberRC[4,colmn-18]:=fields[1].asfloat;
end;
if colmn>39 then
begin
f1book1.sheet:=3;
if colmn<>99 then
f1book1.numberRC[4,colmn-38]:=fields[1].asfloat
else
f1book1.numberRC[4,21]:=fields[1].asfloat;
end;
next;
end;
end;
WITH DATAMODULE1.REPORTQRY1do
begin
CLOSE;
SQL.CLEAR;
SQL.ADD('SELECT * FROM YLDWMX');
OPEN;
end;
FOR I:=1 TO 3do
begin
F1BOOK1.SHEET:=I;
f1book1.SetRowHeight(4,80,365,true);
FOR J:=5 TO 80do
IF F1BOOK1.TEXTRC[J,1]<>'' then
IF DATAMODULE1.REPORTQRY1.LOCATE('DWBH',F1BOOK1.TEXTRC[J,1],[]) then
F1BOOK1.TEXTRC[J,1]:=DATAMODULE1.REPORTQRY1.FIELDS[0].ASSTRING;
end;
f1book1.sheet:=1;
filetype:= F1FileExcel5;
f1book1.write(ExtractFileDir(paramstr(0))+'/SHHH.xls',filetype);
MsExcel:= CreateOleObject('Excel.Application');
WBook:=MsExcel.Application;
WBook.Visible:= True;
wbook.workbooks.Open(ExtractFileDir(paramstr(0))+'/SHHH.xls');
WSheet:=WBook.ActiveSheet;
REPORTFRM.Close;
wbook.Sheets['表1'].Select;
setgridline(3,A,'U');
WSheet.pagesetup.LeftMargin:=msexcel.InchesToPoints(0.196850393700787);
WSheet.pagesetup.RightMargin:=msexcel.InchesToPoints(0.196850393700787);
wbook.Sheets['表2'].Select;
setgridline(3,A,'U');
WSheet.pagesetup.LeftMargin:=msexcel.InchesToPoints(0.196850393700787);
WSheet.pagesetup.RightMargin:=msexcel.InchesToPoints(0.196850393700787);
wbook.Sheets['表3'].Select;
setgridline(3,A,'U');
WSheet.pagesetup.LeftMargin:=msexcel.InchesToPoints(0.196850393700787);
WSheet.pagesetup.RightMargin:=msexcel.InchesToPoints(0.196850393700787);
wbook.Sheets['表1'].Select;
end;