Advertisement
imjyb1008work

將view的畫面匯出成Excel

Jul 11th, 2014
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Initialize
  2.     Dim session As New NotesSession
  3.     Dim cdoc As NotesDocument
  4.     Dim doc As NotesDocument
  5.     Dim ddoc As NotesDocument
  6.     Dim strr As String
  7.     Dim db As NotesDatabase
  8.     Dim sdate As String
  9.     Dim edate As String
  10.     Dim htmlstr As String  '表格的html
  11.     Dim dateTime As New NotesDateTime("1911/01/01")
  12.     Dim docColl As NotesDocumentCollection
  13.     Dim wdoc As NotesDocument
  14.     Dim view As notesview
  15.    
  16.    
  17.     Set db = session.CurrentDatabase
  18.     Set view = db.GetView("vProcessByEmpId")
  19.     Set wdoc = db.GetProfileDocument("fWinDoc")
  20.     On Error Goto h
  21.     Set cdoc = session.DocumentContext
  22.    
  23.     sdate =cdoc.datStart(0)
  24.     edate =cdoc.datEnd(0)
  25.    
  26.     If cdoc.DataForm(0) <> "All" Then
  27.         strr = {Form = "}+cdoc.DataForm(0)  + {"}
  28.     Else
  29.         strr = {(Form = "LeaveDoc" | Form = "CancelLeaveFlow") }   
  30.     End If 
  31.    
  32.     If cdoc.DataStatus(0)="" Or  cdoc.DataStatus(0) ="All" Then
  33.         strr = strr + { & state != "Draf" & state != "Dept99" & DeleteFlag!="1" }
  34.     Else
  35.         strr = strr + { & state = "}+cdoc.DataStatus(0)+{" & DeleteFlag!="1"}
  36.     End If
  37.    
  38.     If cdoc.DataEmpno(0)<>"" Then
  39.         strr = strr + {& ApplyEmpNo="}+cdoc.DataEmpno(0)+{"}
  40.     End If
  41.    
  42.     If cdoc.DataType(0)<>"" Then
  43.         strr = strr + {& VacationTypeList="}+cdoc.DataType(0)+{"}
  44.     End If
  45.    
  46.     If cdoc.DataDept(0)<>"" Then
  47.         strr = strr + {& ApplyDept="}+cdoc.DataDept(0)+{"}
  48.     End If
  49.    
  50.     If sdate="" And edate="" Then
  51.     Elseif edate="" Then
  52.         strr = strr + {& @TextToTime("}+sdate+{")<= datStart }
  53.     Elseif sdate=""  Then
  54.         strr = strr + {& datEnd<= @TextToTime("}+edate+{")}
  55.     Else
  56.         strr = strr + {& @TextToTime("}+sdate+{")<= datStart & datEnd<= @TextToTime("}+edate+{")}
  57.     End If
  58.    
  59.     If  cdoc.DataSign(0)="1" Then
  60.         Msgbox "excel"
  61.         strr = strr+{ & Author="}+wdoc.GM(0)+{"}
  62.     End If
  63.    
  64.     Msgbox STRR
  65.     Set docColl = db.Search(strr,dateTime,0)
  66.     Msgbox Cstr(doccoll.Count)
  67.     Set doc = docColl.GetFirstDocument
  68.    
  69.    
  70.     If  Cstr(doccoll.Count)<>"0" Then
  71.         Print |Content-Disposition:attachment;filename=LeaveList.xls|
  72.         Print |Content-type:application/vnd.ms-excel;charset=utf-8|
  73.         If cdoc.DataSign(0)="1" Then
  74.             Print |<table id='bgTab' width='805' align='center' border='1' cellspacing='0' cellpadding='0'><tr><td  align='center'>申請日期</td><td align='center'>單位名稱</td><td  align='center'>員工編號</td><td  align='center'>員工姓名</td><td  align='center'>職稱</td><td  align='center'>假別</td><td  align='center'>開始時間</td><td  align='center'>結束時間</td><td  align='center'>總時數</td><td  align='center'>請假原因(備註)</td><td  align='center'>主管簽核紀錄</td><td  align='center'>呈核總經理</td></tr>|
  75.         Else
  76.             Print |<table id='bgTab' width='805' align='center' border='1' cellspacing='0' cellpadding='0'><tr><td  align='center'>申請日期</td><td  align='center'>申請狀態</td><td align='center'>單位代碼</td><td align='center'>單位名稱</td><td  align='center'>員工編號</td><td  align='center'>員工姓名</td><td  align='center'>假別代碼</td><td  align='center'>假別</td><td  align='center'>開始時間</td><td  align='center'>結束時間</td><td  align='center'>總時數</td><td  align='center'>人資簽核日期</td><td  align='center'>請假原因(備註)</td></tr>|
  77.         End If
  78.         While Not doc Is Nothing
  79.             Msgbox Format(doc.CreateDate(0),"yyyy/mm/dd")
  80.             Msgbox Format(doc.applydeptno(0))
  81.             Msgbox Format(doc.applyEmpno(0))
  82.             Msgbox Format(doc.VacationTypeList(0))
  83.             Msgbox Format(Cstr(doc.datstart(0)))
  84.             Msgbox Format(Cstr(doc.datend(0)))
  85.             Msgbox Format(doc.leavehours(0))
  86.             Msgbox Format(Format(doc.CreateDate(0),"yyyy/mm/dd"))
  87.             signcommdat = ""
  88.             If doc.state(0) = "Complet" Then signcommdat = Cstr(doc.LAppDate(0))
  89.             If cdoc.DataSign(0)="1" Then
  90.                 tmpcomment=Evaluate({@replacesubstring(SignComm;@newline;"<br>")},doc)
  91.                 Print |<tr><td  align='center'>|+Format(doc.CreateDate(0),"yyyy/mm/dd")+|</td><td  align='center'>|+doc.applydept(0)+|</td><td  align='center'>|+doc.applyEmpno(0)+|</td><td  align='center'>|+doc.applycname(0)+|</td><td  align='center'>|+doc.ApplyTitle(0)+|</td><td  align='center'>|+doc.VacationType(0)+|</td><td  align='center'>|+Cstr(doc.datstart(0))+" "+doc.FromTimeS0(0)+":"+doc.FromTimeS1(0)+|</td><td  align='center'>|+Cstr(doc.datend(0))+" "+doc.ToTimeE0(0)+":"+doc.ToTimeE1(0)+|</td><td  align='center'>|+Cstr(doc.leavehours(0))+|</td><td  align='center'>|+doc.FormMemo(0)+|</td><td  align='center'>|+tmpcomment(0)+|</td><td  align='center'>|+""+|</td></tr>|
  92.                 If doc.othapply(0)<>"" Then
  93.                     Msgbox Cstr(Ubound(doc.othapply))
  94.                     For i = 0 To Ubound(doc.othapply)
  95.                         Set ddoc = view.GetDocumentByKey(doc.othapply(i),True)
  96.                         If Not ddoc Is Nothing Then
  97.                             tmpcomment=Evaluate({@replacesubstring(SignComm;@newline;"<br>")},ddoc)
  98.                             Print |<tr><td  align='center'>|+Format(ddoc.CreateDate(0),"yyyy/mm/dd")+|</td><td  align='center'>|+ddoc.applydept(0)+|</td><td  align='center'>|+ddoc.applyEmpno(0)+|</td><td  align='center'>|+ddoc.applycname(0)+|</td><td  align='center'>|+ddoc.ApplyTitle(0)+|</td><td  align='center'>|+ddoc.VacationType(0)+|</td><td  align='center'>|+Cstr(ddoc.datstart(0))+" "+ddoc.FromTimeS0(0)+":"+ddoc.FromTimeS1(0)+|</td><td  align='center'>|+Cstr(ddoc.datend(0))+" "+ddoc.ToTimeE0(0)+":"+ddoc.ToTimeE1(0)+|</td><td  align='center'>|+Cstr(ddoc.leavehours(0))+|</td><td  align='center'>|+ddoc.FormMemo(0)+|</td><td  align='center'>|+tmpcomment(0)+|</td><td  align='center'>|+"連續假單"+|</td></tr>|
  99.                         End If
  100.                     Next
  101.                 End If
  102.             Else
  103.                 If doc.Form(0)="CancelLeaveFlow" Then
  104.                     Print |<tr><td  align='center'>|+Format(doc.CreateDate(0),"yyyy/mm/dd")+|</td><td  align='center'>銷假</td><td  align='center'>|+doc.applydeptno(0)+|</td><td  align='center'>|+doc.applydept(0)+|</td><td  align='center'>|+doc.applyEmpno(0)+|</td><td  align='center'>|+doc.applycname(0)+|</td><td  align='center'>|+doc.VacationTypeList(0)+|</td><td  align='center'>|+doc.VacationType(0)+|</td><td  align='center'>|+Cstr(doc.datstart(0))+" "+doc.FromTimeS0(0)+":"+doc.FromTimeS1(0)+|</td><td  align='center'>|+Cstr(doc.datend(0))+" "+doc.ToTimeE0(0)+":"+doc.ToTimeE1(0)+|</td><td  align='center'>|+Cstr(doc.leavehours(0))+|</td><td  align='center'></td><td  align='center'>|+doc.FormMemo(0)+|</td></tr>|
  105.                 Else
  106.                     Print |<tr><td  align='center'>|+Format(doc.CreateDate(0),"yyyy/mm/dd")+|</td><td  align='center'>|+doc.DocStatus(0)+|</td><td  align='center'>|+doc.applydeptno(0)+|</td><td  align='center'>|+doc.applydept(0)+|</td><td  align='center'>|+doc.applyEmpno(0)+|</td><td  align='center'>|+doc.applycname(0)+|</td><td  align='center'>|+doc.VacationTypeList(0)+|</td><td  align='center'>|+doc.VacationType(0)+|</td><td  align='center'>|+Cstr(doc.datstart(0))+" "+doc.FromTimeS0(0)+":"+doc.FromTimeS1(0)+|</td><td  align='center'>|+Cstr(doc.datend(0))+" "+doc.ToTimeE0(0)+":"+doc.ToTimeE1(0)+|</td><td  align='center'>|+Cstr(doc.leavehours(0))+|</td><td  align='center'>|+signcommdat+|</td><td  align='center'>|+doc.FormMemo(0)+|</td></tr>|
  107.                 End If
  108.             End If
  109.             Set doc = docColl.GetNextDocument(doc)
  110.         Wend
  111.     Else
  112.         Print |Content-Disposition:attachment;filename=LeaveList.xls|
  113.         Print |Content-type:application/vnd.ms-excel;charset=big5|
  114.         'Print |Content-type:application/vnd.ms-excel;charset=utf-8|
  115.         If cdoc.DataSign(0)="1" Then
  116.             Print |<table id='bgTab' width='805' align='center' border='1' cellspacing='0' cellpadding='0'><tr><td  align='center'>申請日期</td><td align='center'>單位名稱</td><td  align='center'>員工編號</td><td  align='center'>員工姓名</td><td  align='center'>職稱</td><td  align='center'>假別</td><td  align='center'>開始時間</td><td  align='center'>結束時間</td><td  align='center'>總時數</td><td  align='center'>請假原因(備註)</td><td  align='center'>主管簽核紀錄</td><td  align='center'>呈核總經理</td></tr>|
  117.         Else
  118.             Print |<table id='bgTab' width='805' align='center' border='1' cellspacing='0' cellpadding='0'><tr><td  align='center'>申請日期</td><td  align='center'>申請狀態</td><td align='center'>單位代碼</td><td align='center'>單位名稱</td><td  align='center'>員工編號</td><td  align='center'>員工姓名</td><td  align='center'>假別代碼</td><td  align='center'>假別</td><td  align='center'>開始時間</td><td  align='center'>結束時間</td><td  align='center'>總時數</td><td  align='center'>人資簽核日期</td><td  align='center'>請假原因(備註)</td></tr>|
  119.         End If
  120.     End If
  121.    
  122. h:
  123.     Msgbox "Error: "&Cstr(Err)&" : "&Error$&" at line: "& Cstr(Erl)
  124.    
  125. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement