Excelファイルをプリンタに印刷する方法を記載します。
シートをプリンタに印刷する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
Dim xlApp As Excel.Application = New Excel.Application() Dim xlBook As Excel.Workbook = xlApp.Workbooks.Open("C:\work\myBook.xls") Dim xlSheet As Excel.Worksheet = xlBook.Worksheets("Sheet1") 'ヘッダー、フッターの記入 With xlSheet.PageSetup .Orientation = Excel.XlPageOrientation.xlLandscape .CenterHeader = "&12&B" & " ヘッダータイトル " & "&12&B&U" .RightHeader = Now().Year & "年" & Now.Month & "月" & Now.Day & "日" .CenterFooter = "&P / &N ページ" .Zoom = 100 End With xlApp.Application.DisplayAlerts = False -------------------------------------------------------------------- 'ファイルをセーブする xlBook.SaveAs(Filename:="C:\work\myBook4.xls", FileFormat:=Excel.XlFileFormat.xlExcel8) 'ファイルに保存 -------------------------------------------------------------------- 'プリンタに印刷する xlSheet.PrintOut() -------------------------------------------------------------------- 'プレビューサイズを指定する 'Dim xlWindow = xlApp.ActiveWindow 'xlWindow.View = Excel.XlWindowView.xlPageBreakPreview 'xlSheet.PageSetup.Zoom = 100 'xlWindow.Zoom = 75 -------------------------------------------------------------------- '印刷プレビューを表示する xlSheet.Activate() xlApp.Visible = True xlSheet.PrintPreview() -------------------------------------------------------------------- xlBook.Close() xlApp.Application.DisplayAlerts = True xlApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) |