尝试导出视图但只重复获取第一行数据

时间:2015-03-30 16:33:13

标签: lotus-notes lotusscript

我正在尝试使用LotusScript导出视图。视图中的某些列显示多值字段值,这些值显示在视图中的单独行上。我对从Web导入的代码进行了一些更改。我将分隔符从逗号更改为管道“|”因为文档中的字段可能包含逗号。

我遇到的问题是我正在为视图中的条目数重复第一行数据。

我的观点与此类似: (出于显示目的,我使用逗号分隔3个不同的项目)

第一栏:ReqNum包含

A93120,A93120,A94192

第二栏:数量包含 1,16,10

第三栏:描述

税,APXT918 7“Bolt,391”钣金

我正在使用的视图显示了需要导出的字段。第二和第三列是多值字段。

当我导出视图时,我在文件中重复了第3个项目,因为视图知道它们是视图中的3个条目。

导出的文件如下所示:

| ReqNumber |数量|说明

| A93120 | 1 |税

| A93120 | 1 |税

| A93120 | 1 |税

而不是这样:

| ReqNumber |数量|说明

| A93120 | 1 |税

| A93120 | 16 | APXT918 7“Bolt

| A94192 | 10 | 391“钣金

有人可以告诉我,我错过了哪一部分可以移动到视图中的下一条记录吗?

提前感谢您的帮助......非常感谢。

Jean Stachler

%REM
    Agent Copied Export Code
    Mar 26, 2015 by Jean Stachler
    Description: Comments for Agent
%END REM
Option Public
Option Declare
%Include "lsconst.lss"


%REM
    Agent View Export
    Created Mar 27, 2013 by Karl-Henry Martinsson
    Description: Code to export a specified view as CSV.
    Copyright (c) 2013 by Karl-Henry Martinsson
    This code is distributed under the terms of 
    the GNU General Public License V3. 
    See http://www.gnu.org/licenses/gpl.txt
%END REM


Class RowData
    Public column List As String

    Public Sub New()
    End Sub

    Public Sub SetColumnHeader(view As NotesView)
        Dim viewcolumn As NotesViewColumn
        Dim cnt As Integer
        ForAll vc In view.Columns
            Set viewcolumn = vc
            column(CStr(cnt)) = viewcolumn.Title 
            cnt = cnt + 1
        End ForAll  
    End Sub

    Public Sub SetColumnValues(values As Variant)
        Dim cnt As Integer
        Dim tmp As String 
        ForAll v In values
            If IsArray(v) Then
                ForAll c In v
                '    tmp = tmp + c + Chr$(13)
                    tmp = c + Chr$(13)
                    Messagebox tmp
                End ForAll
                column(CStr(cnt)) = Left$(tmp,Len(tmp)-1)
                Messagebox column(CStr(cnt))
            Else
                column(CStr(cnt)) = v 
                Messagebox column(CStr(cnt))
            End If
            cnt = cnt + 1
        End ForAll          
    End Sub
End Class

Class CSVData
    Private row List As RowData
    Private rowcnt As Long

    %REM
        Function New
        Description: Open the view and read view data 
        into a list of RowData objects.
    %END REM    
    Public Sub New(server As String, database As String, viewname As String)
        Dim db As NotesDatabase
        Dim view As NotesView
        Dim col As NotesViewEntryCollection
        Dim entry As NotesViewEntry
        Dim colcnt As Integer

        Set db = New NotesDatabase(server, database)
        If db Is Nothing Then
            MsgBox "Could not open " + database + " on " + server,16,"Error" 
            Exit Sub
        End If
        Set view = db.GetView(viewname)
        If view Is Nothing Then
            MsgBox "Could not access view " + viewname + ".",16,"Error" 
            Exit Sub
        End If
        Set col = view.AllEntries()
        rowcnt = 0
        Set entry = col.GetFirstEntry()
        Set row("Header") = New RowData()
        Call row("Header").SetColumnHeader(view)
        Do Until entry Is Nothing
            rowcnt = rowcnt + 1
            Set row(CStr(rowcnt)) = New RowData()
            Call row(CStr(rowcnt)).SetColumnValues(entry.ColumnValues)
            Set entry = col.GetNextEntry(entry) 
        Loop
    End Sub

    %REM
        Function CSVArray
        Description: Returns a string array of CSV data by row
    %END REM
    Public Function CSVArray() As Variant
        Dim rowarray() As String 
        Dim textrow As String
        Dim cnt As Long
        ReDim rowarray(rowcnt) As String

        ForAll r In row
            textrow = ""            
            ForAll h In r.column                
                Messagebox h
            '   textrow = textrow + |"| + Replace(h,Chr$(13),"\n") + |",|
            '   textrow = textrow + |"| + Replace(h,Chr$(13),"|")
               textrow = textrow + "|" + Replace(h,Chr$(13),"|") 
                Messagebox textrow
            End ForAll
            Messagebox textrow
            rowarray(cnt) = Left$(textrow,Len(textrow)-1)
            Messagebox rowarray(cnt)
            cnt = cnt + 1
        End ForAll  
        CSVArray = rowarray
    End Function

    %REM
        Function HTMLArray
        Description: Returns a string array of HTML data by row
    %END REM
    Public Function HTMLArray() As Variant
        Dim rowarray() As String 
        Dim textrow As String
        Dim cnt As Long
        ReDim rowarray(rowcnt) As String

        ForAll r In row
            textrow = ""
            ForAll h In r.column 
                textrow = textrow + |<td>| + Replace(h,Chr$(13),"<br>") + |</td>|
            End ForAll
            rowarray(cnt) = "<tr>" + textrow + "</tr>"
            cnt = cnt + 1
        End ForAll  
        HTMLArray = rowarray
    End Function

End Class


%REM 
     ******************************** 
     Example of how to call the class
     ********************************
%END REM
Sub Initialize
    Dim csv As CSVData
    Dim outfile As String

    Set csv = New CSVData("CrownNotes2/CrownNotes", "Purchasing\purreqdyn.nsf", "(ExportDetail)")
    outfile = "c:\Data\ReqdetailSecond.txt"
    Open outfile For Output As #1
    ForAll row In csv.CSVArray()
        Print #1, row
    End ForAll
    Close #1

    outfile = "c:\Data\ExcelExportTest.xls"
    Open outfile For Output As #2
    Print #2, "<table>"
    ForAll row In csv.HTMLArray()
        Print #2, row
    End ForAll
    Print #2, "</table>"
    Close #2
End Sub

1 个答案:

答案 0 :(得分:0)

我会再次尝试列出详细信息 以下是重复该行所列行数的部分。在我看来,它正在拾取第一个项目,而不是通过多值字段。

ForAll r In row

        textrow = ""            
        ForAll h In r.column                
            Messagebox h
            textrow = textrow + "|" + Replace(h,Chr$(13),"|") 
            Messagebox textrow
        End ForAll
        Messagebox textrow
        rowarray(cnt) = Left$(textrow,Len(textrow)-1)
        Messagebox rowarray(cnt)
        cnt = cnt + 1

    End ForAll  
    CSVArray = rowarray

我还提出了另一种方法,但是在尝试摆脱回车时遇到了问题。将很快发布此问题。