|
楼主 |
发表于 2006-12-31 08:07:26
|
显示全部楼层
procedure TMainForm.CopyInfoAreasToDstSheet(ASrcData: TInfo; ASrcSheet, ADstSheet: TSheet;
AAreas: TAreaList; var ALeft, ATop: Integer);
var
I, J, lLeft, lTop, TempLeft, TempRight, TempCount, lOldRowCount: Integer;
lDataset: TDataset;
TempArea, lNextArea, lEndArea, lSubArea: TSheetArea;
lIsNullDataset: Boolean;
begin
AAreas.SortAreaBounds;
for I := 0 to AAreas.Count - 1 do
begin
TempArea := AAreas[I];
//¿¼Âǵ½Ò³Í·ÇøÓòµÈûÓÐÊý¾Ý¼¯µÄÇøÓò£¬¾ÍÖ±½Ócopy¹ýÀ´¡£
if not (TempArea is TDataSheetArea) then
begin
//***************¿¼ÂÇҳͷÇøÓòµÈûÓÐÊý¾Ý¼¯µÄÇøÓò*********************//
TempCount := TempArea.Bottom - TempArea.Top;
//ÉèÖÃÿÐеÄÐиß
lOldRowCount := ADstSheet.RowCount;
ADstSheet.RowCount := ADstSheet.RowCount + TempCount;
for J := 0 to TempCount - 1 do
ADstSheet.RowHeights[lOldRowCount + J] := ASrcSheet.RowHeights[TempArea.Top + J];
TempLeft := TempArea.Left;
TempRight := TempArea.Right;
ADstSheet.CopyClientSection(ASrcSheet, Types.Rect(TempLeft, TempArea.Top, TempRight, TempArea.Bottom), ALeft, ATop, False, False, TOutProp.opAll, False);
ATop := ATop + TempCount;
end
else
begin
//°´Êý¾Ý¼¯µÄ¼Ç¼ÊýÌí¼ÓÇøÓò
lDataset := ASrcData.DatasetByID((TempArea as TDataSheetArea).DataSetDefID);
lDataset.First;
if lDataset.Eof then
lIsNullDataset := True
else
lIsNullDataset := False;
ADstSheet.CopyClientSection(ASrcSheet, TempArea.TopFixRect, ALeft, ATop, False, False, TOutProp.opAll, False);
ATop := ATop + TempArea.TopFixRows;
while (not lDataset.Eof) or lIsNullDataset do
begin
lIsNullDataset := False;
//***************¿½±´µ±Ç°ÇøÓòÖе±Ç°ÇøÓòµÄÍ·µ½µÚÒ»¸ö×ÓÇøÓòÍ·µÄ²¿·Ö********//
if TempArea.SubAreas.Count > 0 then
begin
lSubArea := TempArea.SubAreas[0];
//ÉèÖÃÿÐеÄÐиß
TempCount := lSubArea.Top - TempArea.Top;
lOldRowCount := ADstSheet.RowCount;
ADstSheet.RowCount := ADstSheet.RowCount + TempCount;
for J := 0 to TempCount - 1 do
ADstSheet.RowHeights[lOldRowCount + J] := ASrcSheet.RowHeights[TempArea.Top + J];
ADstSheet.CopyClientSection(ASrcSheet, Types.Rect(TempArea.Left, TempArea.Top, TempArea.Right, lSubArea.Top), ALeft, ATop, False, False, TOutProp.opAll, False);
ATop := ATop + TempCount;//Ö»ÉèÖÃÁËtop£¬ ûÓÐÉèÖÃleft
CopyInfoAreasToDstSheet(ASrcData, ASrcSheet, ADstSheet, TempArea.SubAreas, ALeft, ATop);
//**********************************************************//
end else
begin
//******Èç¹ûûÓÐ×ÓÇøÓò£¬ÄÇô¾Í°Ñµ±Ç°ÇøÓò¿½±´¹ýÈ¥*********//
TempCount := TempArea.ClientHeight;
//ÉèÖÃÿÐеÄÐиß
lOldRowCount := ADstSheet.RowCount;
ADstSheet.RowCount := ADstSheet.RowCount + TempCount;
for J := 0 to TempCount - 1 do
ADstSheet.RowHeights[lOldRowCount + J] := ASrcSheet.RowHeights[TempArea.Top + J];
if Assigned(TempArea.ParentArea) then
begin
TempLeft := TempArea.ParentArea.Left;
TempRight := TempArea.ParentArea.Right;
end else
begin
TempLeft := TempArea.Left;
TempRight := TempArea.Right;
end;
ADstSheet.CopyClientSection(ASrcSheet, TempArea.ClientRect{ Types.Rect(TempLeft, TempArea.Top, TempRight, TempArea.Bottom)}, ALeft, ATop, False, False, TOutProp.opAll, False);
ATop := ATop + TempCount;
//**********************************************************//
end;
lDataset.Next;
end;
//********copy Á½¸öͬ¼¶ÇøÓòÖ®¼äµÄ¿Õ¼ä£¨µ±Ç°ÇøÓòϵÄÖ÷ÇøÓòµÄ¿Õ¼ä)**********//
if I < AAreas.Count - 1 then
begin
lNextArea := AAreas[I+1];
if TempArea.Bottom < lNextArea.Bottom then
begin
TempCount := lNextArea.Top - TempArea.Bottom;
//ÉèÖÃÿÐеÄÐиß
lOldRowCount := ADstSheet.RowCount;
ADstSheet.RowCount := ADstSheet.RowCount + TempCount;
for J := 0 to TempCount - 1 do
ADstSheet.RowHeights[lOldRowCount + J] := ASrcSheet.RowHeights[TempArea.Bottom + J];
if Assigned(TempArea.ParentArea) then
begin
TempLeft := TempArea.ParentArea.Left;
TempRight := TempArea.ParentArea.Right;
end else
begin
TempLeft := TempArea.Left;
TempRight := TempArea.Right;
end;
ADstSheet.CopyClientSection(ASrcSheet, Types.Rect(TempLeft, TempArea.Bottom, TempRight, lNextArea.Top), ALeft, ATop, False, False, TOutProp.opAll, False);
ATop := ATop + TempCount;
end;
end
//**********************************************************//
//********¿½±´×îºóÒ»¸ö×ÓÇøÓòµ½µ±Ç°ÇøÓòÄ©µÄµ±Ç°ÇøÓòµÄ²¿·Ö**************//
else if I = AAreas.Count - 1 then
begin
lEndArea := AAreas[AAreas.Count - 1];
if Assigned(lEndArea.ParentArea) and (lEndArea.Bottom < lEndArea.ParentArea.Bottom) then
begin
TempCount := lEndArea.ParentArea.Bottom - lEndArea.Bottom;
//ÉèÖÃÿÐеÄÐиß
lOldRowCount := ADstSheet.RowCount;
ADstSheet.RowCount := ADstSheet.RowCount + TempCount;
for J := 0 to TempCount - 1 do
ADstSheet.RowHeights[lOldRowCount + J] := ASrcSheet.RowHeights[lEndArea.Bottom + J];
ADstSheet.CopyClientSection(ASrcSheet, Types.Rect(lEndArea.ParentArea.Left, lEndArea.Bottom, lEndArea.ParentArea.Right, lEndArea.ParentArea.Bottom), ALeft, ATop, False, False, TOutProp.opAll, False);
ATop := ATop + TempCount;
end;
end;
//**********************************************************//
end;
end;
end;
这段代码里哪一段是循环取SHEET数据的?看的晕乎晕乎的。现在EXCEL表中只能返回第一行数据。 |
|