基于VB和EXCEL的报表设计及打印

时间:2021-10-25 08:07:51

Dim zsbexcel As Excel.Application

Private Sub Command1_Click()
Set zsbexcel = New Excel.Application
    zsbexcel.Visible = True
    zsbexcel.SheetsInNewWorkbook = 1
Set zsbworkbook = zsbexcel.Workbooks.Add

With zsbexcel.ActiveSheet.Range("A2:C9").Borders      
     .LineStyle = xlBorderLineStyleContinuous
     .Weight = xlThin
     .ColorIndex = 1
End With

With zsbexcel.ActiveSheet.Range("A3:C9").Font    
     .Size = 14
     .Bold = True
     .Italic = True
     .ColorIndex = 3
End With

zsbexcel.ActiveSheet.Rows.HorizontalAlignment = xlVAlignCenter     
zsbexcel.ActiveSheet.Rows.VerticalAlignment = xlVAlignCenter       

With zsbexcel.ActiveSheet
     .Cells(1, 2).Value = "100"
     .Cells(2, 2).Value = "200"
     .Cells(3, 2).Value = "=SUM(B1:B2)"
     .Cells(1, 3).Value = "TextHere"
     .Range("A3:A9") = "50"
End With

'这一段用来打印

'zsbexcel.ActiveSheet.PageSetup.Orientation = xlPortrait       'xlLandscape
'zsbexcel.ActiveSheet.PageSetup.PaperSize = xlPaperA4
'zsbexcel.ActiveSheet.PrintOut
'zsbexcel.DisplayAlerts = False
'zsbexcel.Quit
'zsbexcel.DisplayAlerts = True
Set zsbexcel = Nothing

End Sub