Domino中通用的檢視列印(利用Excel列印)

genusBIT發表於2010-01-28

Sub Initialize
 Dim session As New notessession
 Dim db As notesdatabase
 Set db=session.currentdatabase
 
 Dim view As notesview
 Set view=db.getview("PrintView")
 
 iPageLine=Int(Inputbox("每頁行數?"))
 
 Dim excelApplication As Variant
 Dim excelWorkbook As Variant
 Dim excelSheet As Variant  
 
 Set excelApplication = CreateObject("Excel.Application")
 excelApplication.Visible = True
 Set excelWorkbook = excelApplication.Workbooks.Add
 Set excelSheet = excelWorkbook.Worksheets("Sheet1")
 
 REM 輸出開始
 '設定行高
 excelSheet.Rows.RowHeight=40
 '完成
 '垂直居中
 excelSheet.Rows.VerticalAlignment =2
 '完成
 
 
 
 Dim navigator As notesviewnavigator
 Dim entry As notesviewentry
 Set navigator=view.createviewnav()
 Set entry=navigator.getfirst
 
 i=0
 Do While(Not entry Is Nothing)
  If i Mod iPageLine=0 Then '10行換頁[A4]
   If i<>0 Then
    j=1
    Forall columnvalue In Entry.columnvalues
     excelSheet.Cells(i,j)=columnvalue
     j=j+1
    End Forall
    Set entry=navigator.getnext(entry)
   End If
   excelSheet.Range(Cstr(i+1)+":"+Cstr(i+1)).Font.Size=18
   excelSheet.Range(Cstr(i+1)+":"+Cstr(i+1)).Borders.Weight=1
   excelSheet.Rows(i+1).RowHeight=60
   excelSheet.Range("A"+Cstr(i+1)+":"+"E"+Cstr(i+1)).Merge(True) '合併單元格
   excelSheet.Range("A"+Cstr(i+1)+":"+"E"+Cstr(i+1)).MergeCells=True '合併單元格
   excelSheet.Cells(i+1,1)="報表名稱"
   excelSheet.Cells(i+1,1).HorizontalAlignment=3
   excelSheet.Cells(i+1,1).VerticalAlignment=3
  
   k=1
   Forall m In view.columns
    excelSheet.Cells(i+2,k)=m.title
    excelSheet.Cells(i+2,k).HorizontalAlignment=3
    k=k+1
   End Forall     
   i=i+3
  Else
   j=1
   Forall columnvalue In Entry.columnvalues
    excelSheet.Cells(i,j)=columnvalue
    '設定列寬
    excelSheet.Columns(j).ColumnWidth=20
    '完成
    j=j+1
   End Forall
   Set entry=navigator.getnext(entry)
   i=i+1
  End If 
 Loop
 i=i-1
 If i Mod iPageLine<>0 Then
  For k=1 To iPageLine-(i Mod iPageLine)
   excelSheet.Cells(i+k,1)=" "
  Next 
 End If
 
 REM 輸出結束 
 
 excelSheet.UsedRange.Select
 'excelSheet.UsedRange.EntireColumn.AutoFit
 excelSheet.UsedRange.WrapText=True
 
 excelSheet.UsedRange.Borders.Weight=2
 excelSheet.UsedRange.VerticalAlignment = 3
 'excelSheet.UsedRange.HorizontalAlignment=4'水平右對齊
 
 
 excelWorkbook.PersonalViewPrintSettings=True '單元格中文字自動換行
 
 excelWorkbook.PrintPreview
 REM excelWorkbook.PrintOut 
 
 excelApplication.quit
 Set excelSheet=Nothing
End Sub

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14751907/viewspace-626220/,如需轉載,請註明出處,否則將追究法律責任。

相關文章