두 회사 사이의 빈 줄을 제거하는 방법.
{.....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)
코드는 다음을 수행합니다.
문제 : 루프를 통과 할 때마다 회사는 새 줄을 추가하지만 그 사이에 이중 줄이있는 것 같습니다. 내 코드의 어느 부분이 잘못되었는지 알 수 있습니다. 감사!
row = row + 1
세 개의 중첩 된 루프 내에 라는 세 개의 다른 줄이 있습니다. 첫 번째 사례에 대한 논리를 추적하면 세 측량 보조원 (sadoc) 각각에 대해 하나, 토지 측량사 (lsdoc)에 대해 하나씩, 그리고 회사에 대해 하나씩이 중 하나가 발생합니다. 그것은 당신이 실행하는 다섯 번 row = row + 1
이지만 lsdoc 정보와 회사 정보가 첫 번째 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에 대해서도 동일한 트릭을 수행하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다