VB将excel的页面设置设为一页宽一页高

原本想着poi包应该支持设置一页宽一页高,设置是能设置,虽然值设置上去了,但是两个单选按钮无法实现固定,后来不得不使用VB了,唉

代码实现如下,

Imports System.IO
Module Module1

    Sub Main()
        Dim excelfileName As String
        Dim commandLine As String
        Dim commandArray() As String
        commandLine = Command()
        commandArray = Split(commandLine, ",")
        excelfileName = commandArray(0)
        Dim data As String = ""
        Dim buffer As String
        Dim sr As StreamReader = New StreamReader(commandArray(1), System.Text.Encoding.Default)
        Do While sr.Peek() > 0
            buffer = sr.ReadLine()
            data = data & buffer & " "
        Loop
        sr.Close()
        sr = Nothing
        Dim xlApp As Object
        xlApp = CreateObject("Excel.Application")
        xlApp.DisplayAlerts = False
        Dim xlBooks As Object = xlApp.Workbooks
        Dim xlBook As Object = xlBooks.Open(excelfileName)
        ' Dim xlSheets As Object = xlBook.Sheets
        Dim xlSheets As Object
        For Each xlSheets In xlBook.Sheets
            With xlSheets.PageSetup
                .Orientation = 2
                .Zoom = False
                .FitToPagesWide = 1
                .FitToPagesTall = 1
                .CenterFooter = data
            End With
        Next

        xlBook.save()
        xlBook.close()
        xlApp.Quit()
    End Sub

End Module
发布了9 篇原创文章 · 获赞 8 · 访问量 9508

猜你喜欢

转载自blog.csdn.net/qq_41482046/article/details/85240352