-- 作者:有点甜
-- 发布时间:2014/11/5 16:22:00
--
Dim n As Integer=0 For Each r As Row In Tables("sj1").Rows Dim Book As New XLS.Book(ProjectPath & "Attachments\\交费收据.xls") Dim Sheet As XLS.Sheet = Book.Sheets(0) Sheet(3,1).Value = "学生姓名:" & r("学生姓名") Sheet(5,1).Value = r("收费项目") Sheet(5,2).Value = r("数量") Sheet(5,3).Value = r("单价") Sheet(5,4).Value = r("金额") Sheet(5,5).Value = r("备注") Sheet(3,5).Value = "票据编号:" & r("票据号") Dim fl As String = ProjectPath & "Reports\\交费收据" & N & ".Xls" n=n+1 Book.Build() \'生成细节区 Book.Save(fl) \'保存工作簿 Dim Proc As New Process \'打开工作簿 Proc.File = fl Proc.Verb = "Print" \'指定动作 Proc.Start() Next
\' \' \'Sheet(6,6).Value = "制单人:" & User.Name \'修改模板,加入制单人信息 \'Book.Build() \'生成细节区 \'Book.Save("c:\\reports\\test.xls") \'保存工作簿 \'Dim Proc As New Process \'打开工作簿 \'Proc.File = "c:\\reports\\test.xls" \'Proc.Start()
|
-- 作者:有点甜
-- 发布时间:2014/11/5 19:12:00
--
用vba
打印输出
利用PageSetup属性,可进行各种打印设置。如:
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
\'ws.print App.Quit
|