用delphi 打开excel 2003 文件,并进行打印设置,行列字体设置(200)

  • 主题发起人 主题发起人 阻击手
  • 开始时间 开始时间

阻击手

Unregistered / Unconfirmed
GUEST, unregistred user!
用delphi 打开excel 2003 文件,并进行打印设置,行列字体设置,页眉和页脚设置
 
打开Excell:var FExcelApp: Variant;
FWorkBook: Variant;
FSheet: Variant;
begin
FExcelApp := ComObj.CreateOleObject('Excel.Application');
FExcelApp.Caption := Apptitle;
FAppHandle := FindWindow(nil, Apptitle);
FExcelApp.DisplayAlerts := False;
//防止删除Sheet的时候,提示存在数据是否确认删除数据 FExcelApp.WorkBooks.Open(filename);拷贝sheet1的打印设置给sheet2: if sheet2.PageSetup.PrintTitleRows <> sheet1.PageSetup.PrintTitleRows then
sheet2.PageSetup.PrintTitleRows := sheet1.PageSetup.PrintTitleRows;
if sheet2.PageSetup.PrintTitleColumns <> sheet1.PageSetup.PrintTitleColumns then
sheet2.PageSetup.PrintTitleColumns := sheet1.PageSetup.PrintTitleColumns;
if sheet2.PageSetup.PrintArea <> sheet1.PageSetup.PrintArea then
sheet2.PageSetup.PrintArea := sheet1.PageSetup.PrintArea;
if sheet2.PageSetup.LeftHeader <> sheet1.PageSetup.LeftHeader then
sheet2.PageSetup.LeftHeader := sheet1.PageSetup.LeftHeader;
if sheet2.PageSetup.CenterHeader <> sheet1.PageSetup.CenterHeader then
sheet2.PageSetup.CenterHeader := sheet1.PageSetup.CenterHeader;
if sheet2.PageSetup.RightHeader <> sheet1.PageSetup.RightHeader then
sheet2.PageSetup.RightHeader := sheet1.PageSetup.RightHeader;
if sheet2.PageSetup.LeftFooter <> sheet1.PageSetup.LeftFooter then
sheet2.PageSetup.LeftFooter := sheet1.PageSetup.LeftFooter;
if sheet2.PageSetup.CenterFooter <> sheet1.PageSetup.CenterFooter then
sheet2.PageSetup.CenterFooter := sheet1.PageSetup.CenterFooter;
if sheet2.PageSetup.RightFooter <> sheet1.PageSetup.RightFooter then
sheet2.PageSetup.RightFooter := sheet1.PageSetup.RightFooter;
if sheet2.PageSetup.LeftMargin <> sheet1.PageSetup.LeftMargin then
sheet2.PageSetup.LeftMargin := sheet1.PageSetup.LeftMargin;
if sheet2.PageSetup.RightMargin <> sheet1.PageSetup.RightMargin then
sheet2.PageSetup.RightMargin := sheet1.PageSetup.RightMargin;
if sheet2.PageSetup.TopMargin <> sheet1.PageSetup.TopMargin then
sheet2.PageSetup.TopMargin := sheet1.PageSetup.TopMargin;
if sheet2.PageSetup.BottomMargin <> sheet1.PageSetup.BottomMargin then
sheet2.PageSetup.BottomMargin := sheet1.PageSetup.BottomMargin;
if sheet2.PageSetup.HeaderMargin <> sheet1.PageSetup.HeaderMargin then
sheet2.PageSetup.HeaderMargin := sheet1.PageSetup.HeaderMargin;
if sheet2.PageSetup.FooterMargin <> sheet1.PageSetup.FooterMargin then
sheet2.PageSetup.FooterMargin := sheet1.PageSetup.FooterMargin;
if sheet2.PageSetup.PrintHeadings <> sheet1.PageSetup.PrintHeadings then
sheet2.PageSetup.PrintHeadings := sheet1.PageSetup.PrintHeadings;
if sheet2.PageSetup.PrintGridlines <> sheet1.PageSetup.PrintGridlines then
sheet2.PageSetup.PrintGridlines := sheet1.PageSetup.PrintGridlines;
if sheet2.PageSetup.PrintComments <> sheet1.PageSetup.PrintComments then
sheet2.PageSetup.PrintComments := sheet1.PageSetup.PrintComments;
if sheet2.PageSetup.CenterHorizontally <> sheet1.PageSetup.CenterHorizontally then
sheet2.PageSetup.CenterHorizontally := sheet1.PageSetup.CenterHorizontally;
if sheet2.PageSetup.CenterVertically <> sheet1.PageSetup.CenterVertically then
sheet2.PageSetup.CenterVertically := sheet1.PageSetup.CenterVertically;
if sheet2.PageSetup.Orientation <> sheet1.PageSetup.Orientation then
sheet2.PageSetup.Orientation := sheet1.PageSetup.Orientation;
if sheet2.PageSetup.Draft <> sheet1.PageSetup.Draft then
sheet2.PageSetup.Draft := sheet1.PageSetup.Draft;
if sheet2.PageSetup.PaperSize <> sheet1.PageSetup.PaperSize then
sheet2.PageSetup.PaperSize := sheet1.PageSetup.PaperSize;
if sheet2.PageSetup.FirstPageNumber <> sheet1.PageSetup.FirstPageNumber then
sheet2.PageSetup.FirstPageNumber := sheet1.PageSetup.FirstPageNumber;
if sheet2.PageSetup.Order <> sheet1.PageSetup.Order then
sheet2.PageSetup.Order := sheet1.PageSetup.Order;
if sheet2.PageSetup.BlackAndWhite <> sheet1.PageSetup.BlackAndWhite then
sheet2.PageSetup.BlackAndWhite := sheet1.PageSetup.BlackAndWhite;
if sheet2.PageSetup.Zoom <> sheet1.PageSetup.Zoom then
sheet2.PageSetup.Zoom := sheet1.PageSetup.Zoom;
if sheet2.PageSetup.PrintErrors <> sheet1.PageSetup.PrintErrors then
sheet2.PageSetup.PrintErrors := sheet1.PageSetup.PrintErrors;
end;
------------------建议通过菜单 工具/宏/录制新宏,然后操作,操作完成后,执行菜单 工具/宏/停止录制宏,然后通过 Alt+F11查看自动生成的代码
 
代码在d2007下调式没通过,能不能发一个例程到我的邮箱,通过就给分。
 
88066076@163.com
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
886
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部