procedure Treportfrm.shjyqxtz1;
var
i,J,dwbh,row,colmn,a:integer;
filetype:smallint;
month,year,day:word;
begin
with datamodule1.REPORTQRY1 do
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.REPORTQRY1 do
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 eof do
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.REPORTQRy2 do
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 eof do
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.REPORTqry1 do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eof do
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.REPORTqry2 do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eof do
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.REPORTqry1 do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eof do
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.REPORTqry2 do
begin
FIRST;
dwbh:=fieldbyname('dwbh').asinteger;
while not eof do
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.REPORTqry1 do
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 eof do
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.REPORTQRY1 DO
BEGIN
CLOSE;
SQL.CLEAR;
SQL.ADD('SELECT * FROM YLDWMX');
OPEN;
END;
FOR I:=1 TO 3 DO
BEGIN
F1BOOK1.SHEET:=I;
f1book1.SetRowHeight(4,80,365,true);
FOR J:=5 TO 80 DO
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;
procedure Treportfrm.setgridline(startline, endline: integer;
endclomn: string);
begin
wsheet:=wbook.activesheet;
WSHEEt.PageSetup.PrintGridlines:=False;
WSHEEt.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlDiagonalDown].LineStyle:= xlNone;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlDiagonalUp].LineStyle:=xlNone;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeLeft].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeTop].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeBottom].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlEdgeRight].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlInsideVertical].LineStyle:=xlContinuous;
WSHEET.Range['A'+inttostr(startline)+':'+endclomn+inttostr(endline)].Borders[xlInsideHorizontal].LineStyle:=xlContinuous;
end;