2017-03-22 55 views
0

如何刪除兩行之間的空行。如何刪除空行之間

{.....some code for calling excel template and write 

    Dim lsvw As NotesView, lsdoc As NotesDocument, lsdc As NotesDocumentCollection 
    Dim savw As NotesView, sadoc As NotesDocument, sadc As NotesDocumentCollection 
    Dim firmvw As NotesView, firmdoc As NotesDocument 
    Dim firmve As NotesViewEntry 
    Dim firmvc As NotesViewEntryCollection 
    Dim tmpve As NotesViewEntry ' temporary use 

    Dim firmArr   ' array that contain Company ID 
    Dim firmid   ' firm id to store all firm 


    Set firmvw = db.Getview("Company Information by Co_ID") 
    Set lsvw = db.Getview("(LS sort by Co_ID)") 
    Set savw = db.Getview("SA sort by LS Num") 


    Set firmvc = firmvw.Allentries  ' get all entries 
    If firmvc.Count = 0 Then   ' if all view entry collection is empty 
     Print "No Company information!" 
     Exit Sub 
    End If 

    Set firmve = firmvc.Getfirstentry() 

    firmArr = "" 
    firmid = "" 
    Do While Not firmVe Is Nothing 
     Set firmdoc =firmve.Document 
     firmid = firmid + firmdoc.Co_ID(0) + ";" ' put all co Id store inside firmID 
     Set tmpve = firmvc.Getnextentry(firmVe) 
     Set firmVe = tmpve 
    Loop 

    firmArr = FullTrim(ArrayUnique(Split(firmid, ";"))) ' split all firm with ";" so become array 

    ' ForAll refvar In container 
    '  [statement] 
    ' End ForAll 

    row = 2 
    ForAll firm In firmArr 
     Dim codoc As NotesDocument 
     Set codoc = firmvw.Getdocumentbykey(firm,True) 
     If Not codoc Is Nothing Then 
      xlsht.Cells(row, 1) = Codoc.Co_Name(0) 
     End If 
     Set lsdc = lsvw.GetAllDocumentsByKey(firm,True) 
     Set lsdoc = lsdc.GetFirstDocument 

     Do While Not lsdoc Is Nothing 

      xlsht.Cells(row, 2) = lsdoc.Name(0) 

      Set sadc = savw.GetAllDocumentsByKey(lsdoc.Reg_Num_LS(0),True) 
      Set sadoc = sadc.GetFirstDocument 

      Do While Not sadoc Is Nothing 

       xlsht.Cells(row, 3) = sadoc.Name(0) 
       xlsht.Cells(row, 4) = sadoc.NRIC(0) 
       xlsht.Cells(row, 5) = sadoc.Date_Apprv_Cr(0) 
       row = row +1 
       Set sadoc = sadc.GetNextDocument(sadoc) 

      Loop 

      row = row +1 
      Set lsdoc = lsdc.GetNextDocument(lsdoc) 
     Loop 

     row = row + 1 ' write every row during pass one company 
    End ForAll 


Call xlWbk.Save 
Call xlWbk.Close 
Set xlWbk = Nothing 
Call xl.Quit 
Set xl = Nothing 

Set rtitem = New NotesRichTextItem(doc, "Attachment") 
Call rtitem.Embedobject(EMBED_ATTACHMENT, "", template) 
If template <> "" And Dir$(template, 0) <> "" Then Kill template 


Call doc.Save(True, False) 

代碼做什麼:

  1. 首先增加一個陣列中的所有企業存儲。
  2. 之後循環遍歷所有數組。
  3. 每次使用公司尋找文件去尋找土地測量師,然後寫入Excel。
  4. 之後,使用土地測量師尋找一名跟隨他的測量助理,並寫入excel。

問題: 每次循環傳遞一個公司都會添加一個新行,但它似乎在兩行之間,任何想法我的代碼的哪一部分是錯誤的。謝謝!

enter image description here

回答

1

你有三個不同的線路是說row = row + 1,在三個嵌套循環。如果你追蹤第一個案例的邏輯,你會遇到三個測量助理(sadoc)中的每一個,一個給土地測量員(lsdoc),另一個給公司。這是執行row = row + 1的五倍,但您只生成三行數據,因爲lsdoc信息和公司信息與第一個sadoc信息位於同一行。

如果總是每個lsdoc至少一個薩多克和總是只有一個土地測量師對每家公司,那麼答案很簡單:剛剛擺脫了兩個額外的row = row + 1線。不幸的是,我看到你有一個案例,一家公司有多個lsdoc,在這種情況下,對於公司的第二個lsdoc沒有問題,所以它不會那麼簡單。

如果真的有必要,您將不得不保持跟蹤並僅執行row = row + 1。即,改變這種

row = row +1 
Set sadoc = sadc.GetNextDocument(sadoc) 

對此

Set sadoc = sadc.GetNextDocument(sadoc) 
If not sadoc is Nothing then 
    row = row +1 
End If 

而對於lsdoc做同樣的伎倆了。

+0

謝謝你!我把「行」放在錯誤的行上〜你救了我一天,我的行計算錯了! –