C
crpp0602
Unregistered / Unconfirmed
GUEST, unregistred user!
要求将本厂所有的报表都比较好的输出到 Excel 中,因报表较多,且做得不统一,报表都是通过quickrep 做出来的。我用 QRCSVFilter 和 QRExcelFilter 组件输出都得不到老大可以接受的结果,自己采用了如下方法:用 ExcelApplication 或 OLE 连接 Excel 软件,在每一个 band 的BeforePrint事件中调用如下的过程。该过程的目的是每次触发band 的BeforePrint事件时将该 band 上显示的内容输出到 Excel 中,但存在的问题是:报 无效的指针操作或读地址内存错误,这个错误很有可能在里面的二重循环中,该二重循环很简单的,还有一个问题: TQRExpr 和 TQRExprMemo 类上显示的内容输出不到 excel 中,特恳请各位帮忙。
procedure OutPutToExcel(Sender: TQRCustomBand);
var
n,k:integer;
TmpIntLeft:array of integer;
tmpint,length0:integer;
begin
with senderdo
begin
length0:=(sender as TQRCustomBand).ControlCount;
setlength(TmpIntLeft,length0);
for n:=0 to length0-1do
TmpIntLeft[n]:=controls[n].Left;
for k:=0 to length0-2do
//冒泡排序法排列各个组件的 left 属性值 ??
begin
for n:=0 to length0-1-kdo
begin
if TmpIntLeft[n]>TmpIntLeft[n+1] then
begin
tmpint:=TmpIntLeft[n];
TmpIntLeft[n]:=TmpIntLeft[n+1];
TmpIntLeft[n+1]:=tmpint;
end;
end;
end;
end;
with senderdo
//用二重循环将 band 组件上显示的内容依其 left 属性值的大小次序输出到 excel 的单元格中
begin
i:=1;
for n:=0 to length0-1do
begin
for k:=0 to length0-1do
begin
if controls[k].Left=TmpIntLeft[n] then
begin
if controls[k] is TQRLabel then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRLabel).Caption;
if controls[k] is TQRDBText then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRDBText).DataSet.fieldbyname((controls[k] as TQRDBText).DataField).asstring;
if controls[k] is TQRExpr then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRExpr).Caption;
if controls[k] is TQRSysData then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRSysData).Caption;
if controls[k] is TQRMemo then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRMemo).Lines.Text;
if controls[k] is TQRExprMemo then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRExprMemo).Caption;
if controls[k] is TQRRichText then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRRichText).Lines.Text;
if controls[k] is TQRDBRichText then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRDBRichText).DataSet.fieldbyname((controls[k] as TQRDBRichText).DataField).asstring;
inc(i);
end;
end;
end;
inc(j);
end;
end;
procedure OutPutToExcel(Sender: TQRCustomBand);
var
n,k:integer;
TmpIntLeft:array of integer;
tmpint,length0:integer;
begin
with senderdo
begin
length0:=(sender as TQRCustomBand).ControlCount;
setlength(TmpIntLeft,length0);
for n:=0 to length0-1do
TmpIntLeft[n]:=controls[n].Left;
for k:=0 to length0-2do
//冒泡排序法排列各个组件的 left 属性值 ??
begin
for n:=0 to length0-1-kdo
begin
if TmpIntLeft[n]>TmpIntLeft[n+1] then
begin
tmpint:=TmpIntLeft[n];
TmpIntLeft[n]:=TmpIntLeft[n+1];
TmpIntLeft[n+1]:=tmpint;
end;
end;
end;
end;
with senderdo
//用二重循环将 band 组件上显示的内容依其 left 属性值的大小次序输出到 excel 的单元格中
begin
i:=1;
for n:=0 to length0-1do
begin
for k:=0 to length0-1do
begin
if controls[k].Left=TmpIntLeft[n] then
begin
if controls[k] is TQRLabel then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRLabel).Caption;
if controls[k] is TQRDBText then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRDBText).DataSet.fieldbyname((controls[k] as TQRDBText).DataField).asstring;
if controls[k] is TQRExpr then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRExpr).Caption;
if controls[k] is TQRSysData then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRSysData).Caption;
if controls[k] is TQRMemo then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRMemo).Lines.Text;
if controls[k] is TQRExprMemo then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRExprMemo).Caption;
if controls[k] is TQRRichText then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRRichText).Lines.Text;
if controls[k] is TQRDBRichText then
ExcelWorksheet1.Cells.Item[j,i]:=(controls[k] as TQRDBRichText).DataSet.fieldbyname((controls[k] as TQRDBRichText).DataField).asstring;
inc(i);
end;
end;
end;
inc(j);
end;
end;