2017-03-22 56 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

谢谢你!我把“行”放在错误的行上〜你救了我一天,我的行计算错了! –