-- 作者:大红袍
-- 发布时间:2015/9/6 14:17:00
--
用vba设置也可以
Dim App As New MSExcel.Application Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\\Report.xls") Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) With Ws.PageSetup \'设置打印区域 .PrintArea = "A1:H10" \'打印工作表的指定区域 .PrintArea = Ws.UsedRange.Address \'打印工作表的使用区域 .PrintTitleColumns = Ws.Columns("A:H").Address \'打印列标题(在每一页的左边重复出现) .PrintTitleRows = Ws.Rows(1).Address \'打印行标题(在每一页的顶部重复出现) \'设置页面 .PaperSize = MSExcel.XlPaperSize.xlPaperA4 \'纸张大小 .LeftMargin = 30 \'页面左边距 .RightMargin = 30\'页面右边距 .TopMargin = 50 \'页面顶部边距 .BottomMargin = 50 \'页面底部边距 .HeaderMargin = 40 \'页面顶端到页眉的距离 .FooterMargin = 40 \'页脚到页面底端的距离 .CenterHorizontally = True \'页面水平居中 .CenterVertically = True \'页面垂直居中 \'设置页眉 .LeftHeader = "打印日期: &D" \'左页眉,&D表示日期 .CenterHeader = "&""隶书,常规""&20 数据分析表" \'中页眉,并将字体设置为隶书和20号字大小 .RightHeader = "打印者: " & App.UserName \'右页眉 \'设置页脚 .LeftFooter = "文件: &F &A" \'左页脚,&F表示文件名,&A表示工作表名 .CenterFooter = "" \'中页脚为空 .RightFooter = "第 &P 页 共 &N 页" \'右页脚 \'打印模式 .Orientation = MSExcel.xlPageOrientation.xlPortrait \'纵向打印 .Orientation = MSExcel.xlPageOrientation.xlLandscape \'横向打印 .PrintHeadings = True\'打印行号和列标 .PrintGridlines = True \'打印网格线 \'缩放打印 .Zoom = False\'以下设置将缩印在一页内 .FitToPagesWide = 1 \'按照1页的宽度打印 .FitToPagesTall = 1 \'按照1页的高度打印 End With App.Visible = True Ws.PrintPreview App.Quit
|