0%
Theme NexT works best with JavaScript enabled
依赖包
代码实现
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 using Spire.Xls;using System;using System.Collections.Generic;using System.Drawing.Printing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace PrintPreviewTest { class Program { static void Main (string [] args ) { PrintDialog printdialog = new PrintDialog(); Workbook workbook = new Workbook(); workbook.LoadFromFile(args[0 ]); Worksheet sheet = workbook.Worksheets[0 ]; sheet.PageSetup.PaperSize = PaperSizeType.PaperA4; sheet.PageSetup.Orientation = PageOrientationType.Portrait; sheet.PageSetup.PrintArea = "B2:F8" ; sheet.PageSetup.PrintTitleColumns = "$A:$B" ; sheet.PageSetup.PrintTitleRows = "$1:$2" ; sheet.PageSetup.Order = OrderType.DownThenOver; sheet.PageSetup.Order = OrderType.OverThenDown; PrintDialog dialog = new PrintDialog(); dialog.AllowPrintToFile = true ; dialog.AllowCurrentPage = true ; dialog.AllowSomePages = true ; dialog.PrinterSettings.Duplex = Duplex.Simplex; dialog.PrinterSettings.FromPage = 0 ; dialog.PrinterSettings.ToPage = 8 ; dialog.PrinterSettings.PrintRange = PrintRange.SomePages; dialog.PrinterSettings.Copies = 5 ; dialog.PrinterSettings.PrinterName = "HP LasterJet P1007" ; printdialog.Document = workbook.PrintDocument; if (printdialog.ShowDialog() == DialogResult.OK) { workbook.PrintDocument.PrinterSettings = printdialog.PrinterSettings; PrintPreviewDialog previewDialog = new PrintPreviewDialog(); previewDialog.Document = workbook.PrintDocument; previewDialog.ShowDialog(); } } } }
预览