如何删除中间的空行
how to remove empty line in between
如何去掉两个公司之间的空行。
{.....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)
代码正在做:
- 首先将所有的公司商店添加到一个数组中。
- 之后遍历所有数组。
- 每次用firm找文件去找land surveyor然后写到excel。
- 之后用land surveyor找一个跟着他的测量助手也写进excel.
问题:
每次循环通过公司都会添加一个新行,但似乎在两者之间给出了双行,知道我的代码的哪一部分是错误的。谢谢!
您在三个嵌套循环中有三个不同的行表示 row = row + 1
。如果您追溯第一个案例的逻辑,您会遇到三个测量助理 (sadoc) 中的每一个的其中一个,土地测量员 (lsdoc) 的一个,然后是公司的一个。那是你执行了五次row = row + 1
但是你只生成了三行数据,因为lsdoc信息和firm信息与第一个sadoc信息在同一行。
如果每个 lsdoc 总是 至少有一个 sadoc,并且每个公司 总是 只有一个土地测量员,那么答案很简单:只需去掉两个额外的 row = row + 1
行。不幸的是,我看到您有这样一种情况,一家公司有多个 lsdoc,而在同一种情况下,公司的第二个 lsdoc 没有 sadoc,所以事情不会那么简单。
您将不得不跟踪并仅在确实需要时才执行 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 也使用相同的技巧。
如何去掉两个公司之间的空行。
{.....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)
代码正在做:
- 首先将所有的公司商店添加到一个数组中。
- 之后遍历所有数组。
- 每次用firm找文件去找land surveyor然后写到excel。
- 之后用land surveyor找一个跟着他的测量助手也写进excel.
问题: 每次循环通过公司都会添加一个新行,但似乎在两者之间给出了双行,知道我的代码的哪一部分是错误的。谢谢!
您在三个嵌套循环中有三个不同的行表示 row = row + 1
。如果您追溯第一个案例的逻辑,您会遇到三个测量助理 (sadoc) 中的每一个的其中一个,土地测量员 (lsdoc) 的一个,然后是公司的一个。那是你执行了五次row = row + 1
但是你只生成了三行数据,因为lsdoc信息和firm信息与第一个sadoc信息在同一行。
如果每个 lsdoc 总是 至少有一个 sadoc,并且每个公司 总是 只有一个土地测量员,那么答案很简单:只需去掉两个额外的 row = row + 1
行。不幸的是,我看到您有这样一种情况,一家公司有多个 lsdoc,而在同一种情况下,公司的第二个 lsdoc 没有 sadoc,所以事情不会那么简单。
您将不得不跟踪并仅在确实需要时才执行 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 也使用相同的技巧。