• Spire.XLS打印页面设置教程 C# VB.NET Excel直接打印


     
     
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim csclsNPOI As New clsNPOI(Application.StartupPath & "\Demo.xls")
            Dim csMemoryStream As MemoryStream = csclsNPOI.GetStream()
            Dim workbook As New Spire.Xls.Workbook()
            workbook.LoadFromStream(csMemoryStream)
            Dim worksheet As Worksheet = workbook.Worksheets(0)
     
     
            '设置打印参数
            With worksheet.PageSetup
                '表示页眉页脚边距是否与页边距对齐。默认值为1
                '.AlignWithMargins = 1
    #Region "页面设置"
                '一:页面
                '1.1方向
                '1.1.1纸张横向
                ' .Orientation = PageOrientationType.Landscape
                '1.1.2纸张竖向
                '.Orientation = PageOrientationType.Portrait
                '2:缩放
                '2.1缩放比例(A): between 10% and 400% percent
                ' .Zoom = 80%
                '2.2调整为(F):
                '2.2.1当FitToPagesTall=1  FitToPagesWide=1  将工作表调整为一页
                '2.2.2当FitToPagesTall=0  FitToPagesWide=1  将所有列调整为一页
                '2.2.3当FitToPagesTall=1  FitToPagesWide=0  将所有行调整为一页
                ''调整为(F):页高
                .FitToPagesTall = 0
                ''调整为(F):页宽
                .FitToPagesWide = 1
                '3.纸张大小(Z):
                '3.1设置纸张大小
                .PaperSize = PaperSizeType.PaperA5
                '3.2打印质量(Q):
                '.PrintQuality = 180
                '4起始页码(R):
                ' .FirstPageNumber = 0
                '二、页边距
                '页眉页边距
                '.HeaderMarginInch = 2
                '页脚页边距
                ' .FooterMarginInch = 2
                ''页边距_上
                ' .TopMargin = 0
                ''页边距_下
                ' .BottomMargin = 0
                ''页边距_左
                ' .LeftMargin = 0.1
                ''页边距_右
                ' .RightMargin = 0
                '居中方式   
                '水平(Z)
                '.CenterHorizontally = True
                '垂直(V)
                ' .VResolution = True
                '三、页眉/页脚
                '页眉(A):
                '四、工作表
                '4.1打印区域(A):
                '  .PrintArea = "A1:K35"
                '4.2打印标题
                '左端标题列(C):
                ' .PrintTitleRows = "$1:$2"
                '顶端标题行(R):
                ' .PrintTitleColumns = "$A:$B"
                '4.3打印
                '网格线(G)
                ' .IsPrintGridlines = True
                '行号列标(L)
                ' .IsPrintHeadings = True
                '黑白模式打印
                ' .BlackAndWhite = True
                '批注(M):
                ' .PrintComments = PrintCommentType.InPlace
                '草稿品质(Q)
                ' .Draft = True
                '错误单元格打印为(E):
                '.PrintErrors = PrintErrorsType.NA
                '先列后行(D)
                '.Order = OrderType.DownThenOver
                '先行后列(V)
                ' .Order = OrderType.OverThenDown
    #End Region
            End With
            Dim CS As New MemoryStream
            worksheet.SaveToPdf("C:\123.pdf")
            ' GetMX("C:\123.pdf")
            worksheet.SaveToPdfStream(CS)
            Dim printDoc = New Patagames.Pdf.Net.Controls.WinForms.PdfPrintDocument(Patagames.Pdf.Net.PdfDocument.Load(CS))
            printDoc.Print()
        End Sub
     
        Private Sub GetMX(args As String)
            '加载PDF文档
            Dim doc As New PdfDocument()
            doc.LoadFromFile(args)
     
            '获取第一页
            Dim page As PdfPageBase = doc.Pages(0)
            '获取页面宽度和高度
            Dim pointWidth As Single = page.Size.Width
            Dim pointHeight As Single = page.Size.Height
     
            '将度量单位转换为厘米
            Dim unitCvtr As New PdfUnitConvertor()
            Dim centimeterWidth As Single = unitCvtr.ConvertUnits(pointWidth, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter)
            Dim centimeterHeight As Single = unitCvtr.ConvertUnits(pointHeight, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter)
     
            '输出文本文档
            Dim content As New StringBuilder()
            content.AppendLine("该PDF的页面大小为(宽: " + pointWidth + "pt, 高: " + pointHeight + "pt).")
            content.AppendLine("该PDF的页面大小为(宽: " + centimeterWidth + "cm, 高: " + centimeterHeight + "cm.)")
     
            Dim output As [String] = "GetPageSize_out.txt"
     
            'Save them to a txt file
            File.WriteAllText(output, content.ToString())
     
     
        End Sub
     
  • 相关阅读:
    Markdown语法入门
    Android开发——绘图基础
    数据结构(java版)学习笔记(三)——线性表之单链表
    数据结构(java版)学习笔记(二)——线性表之顺序表
    数据结构(java版)学习笔记(一)——线性表
    优化电脑方法收集(一)——加内存系统没变化?改几项注册表再感受下
    数据结构(java版)学习笔记(序章)
    基础:从概念理解Lucene的Index(索引)文档模型
    lucene之排序、设置权重、优化、分布式搜索(转)
    Lucene提供的条件判断查询
  • 原文地址:https://www.cnblogs.com/Fooo/p/16252353.html
Copyright © 2020-2023  润新知