报表通常需要上下封顶的表格线,可以使用Borders集合属性。要注意,VBA中的集合对象通常都有一个缺省的Item属性,Delphi中是不能省略的。Weight属性用于定义表格线的粗细: with Aname.RefersToRange,Borders do begin HorizontalAlignment:= xlRight; Item[xlEdgeBottom].Weight:=xlMedium; Item[xlEdgeTop].Weight:=xlMedium; Item[xlInsideHorizontal].Weight:=xlThin; item[xlInsideVertical].Weight:=xlThin; end;
with Aname.RefersToRange,Borders do
begin
HorizontalAlignment:= xlRight;
Item[xlEdgeBottom].Weight:=xlMedium;
Item[xlEdgeTop].Weight:=xlMedium;
Item[xlInsideHorizontal].Weight:=xlThin;
item[xlInsideVertical].Weight:=xlThin;
end;
//先全加上边框
If RowsNum < 26 then
begin
Ranges := sheet.Range['A2:'+ char(Length(TimeNum) + 65)
+ IntToStr(Query1.RecordCount + 4)];
ranges.Borders.LineStyle := xlContinuous;
Ranges.WrapText := True;
end
else if RowsNum = 26 then
begin
Ranges := sheet.Range['A2:Z' + IntToStr(Query1.RecordCount + 4)];
ranges.Borders.LineStyle := xlContinuous;
Ranges.WrapText := True;
end
else if (RowsNum > 26) and (RowsNum <= 52) then
//Èç¹ûÓÐ26¸öº½°àÒÔÉÏ
begin
Ranges := sheet.Range['A2:A'+ char(Length(TimeNum) + 39)
+ IntToStr(Query1.RecordCount + 4)];
ranges.Borders.LineStyle := xlContinuous;
Ranges.WrapText := True;
end
else if (RowsNum > 52) and (RowsNum <= 78) then
//Èç¹ûÓÐ52¸öº½°àÒÔÉÏ78°àÒÔÏÂ
begin
Ranges := sheet.Range['A2:B'+ char(Length(TimeNum) + 13)
+ IntToStr(Query1.RecordCount + 4)];
ranges.Borders.LineStyle := xlContinuous;
Ranges.WrapText := True;
end
else if (RowsNum > 78) and (RowsNum <= 104) then
//Èç¹ûÓÐ52¸öº½°àÒÔÉÏ78°àÒÔÏÂ
begin
Ranges := sheet.Range['A2:C'+ char(Length(TimeNum) + 13)
+ IntToStr(Query1.RecordCount + 4)];
ranges.Borders.LineStyle := xlContinuous;
Ranges.WrapText := True;
end;
//再把不要的边框去掉
Ranges := sheet.Range['A3:A3'];
Ranges.borders[xlEdgeTop].LineStyle := xlNone;