请问如何通过OLE在EXCEL中插入分页符?(50分)

  • 主题发起人 主题发起人 beyondeast
  • 开始时间 开始时间
B

beyondeast

Unregistered / Unconfirmed
GUEST, unregistred user!
excel 会自己分页
 
就是要想实现强制分页!
 
ActiveWindow.SelectedSheets.HPageBreaks.Add(activecell)
 
procedure Tform1.PrintPre;
var
Range,Range1,Range2,Sheet: Variant;
i,hi1,hi2,usedRows:integer;
tmpstr:string;
begin
Sheet:= XLApp1.Workbooks[1].WorkSheets['毕业生录入'];
usedRows:= Sheet.UsedRange.Rows.Count;//得到用掉的行数
if usedRows>maxuser then
begin
showmessage('数据太多了,处理不了');
exit;
end else
begin
hi2:=((usedRows-4) div 20)+1;
hi1:=hi2*21+4;
if hi2>1 then
for i:=1 to hi2 do
begin
sheet.range['a'+inttostr(i*21+3)+':m'+inttostr(i*21+3)].insert;//插入小计行
sheet.cells[(i*21+3),1]:='小计:';
sheet.cells[(i*21+3),1].Characters.Font.FontStyle :='加粗';
sheet.cells[(i*21+3),2].FormulaR1C1:= '=max(R[-20]C:R[-1]C)';//公式
sheet.cells[(i*21+3),12].FormulaR1C1:= '=SUM(R[-20]c:R[-1]c)';
if i< hi2 then
Sheet.HPageBreaks.add(Sheet.Cells[i*21+4,1]);//插入分页符
end;
sheet.range['a'+inttostr(hi1)+':m'+inttostr(hi1)].insert;//插入合计行
sheet.cells[hi1,1]:='合计:';
sheet.cells[hi1,1].Characters.Font.FontStyle :='加粗';
sheet.cells[hi1,1].RowHeight := 16;//高
if hi1> 25 then
sheet.cells[hi1,12].FormulaR1C1:= '=SUM(R[-'
+inttostr(hi1-4)+']c:R[-1]c)/2'
else sheet.cells[hi1,12].FormulaR1C1:= '=SUM(R[-21]c:R[-1]c)';
tmpstr:='A3'+':'+'u'+inttostr(hi1);
Range := XLApp1.Workbooks[1].WorkSheets['毕业生录入'].Range[tmpstr];
Range.Borders.LineStyle:=1;//划框线。
Range.Borders.weight:=strtoint(edit2.text);//划框线。
XLApp1.Visible :=True;
sheet.PrintPreView;//打印予显;
end;
end;

procedure Tform1.InsertData;
var Sheet, Range: Variant;
tmpstr:string;
begin
Range :=XLApp1.Workbooks[1].WorkSheets['毕业生录入'].Range['A1:M1'];//
range.ClearContents;
Range :=XLApp1.Workbooks[1].WorkSheets['毕业生录入'].Range['A1:M2'];//
range.insert;//插入空行
Range :=XLApp1.Workbooks[1].WorkSheets['毕业生录入'].Range['A1:M1'];//
Range.HorizontalAlignment := xlCenter;//
Range.VerticalAlignment := xlCenter;//格式
Range.WrapText := False;
Range.Orientation := 0;
Range.AddIndent := False;
Range.ShrinkToFit := False;
Range.MergeCells := False;
Range.Merge;//合并单元格
Range.Rows.RowHeight := 46;//高
 
接受答案了.
 
后退
顶部