2013-03-27 3 views
0

Мне нужно экспортировать представление примечаний лотоса, чтобы преуспеть. Проблема в том, что у меня есть два столбца в представлении, которое отображает несколько значений с помощью «Новая строка» в качестве разделителя. Я попробовал встроенную функцию экспорта, а также новую функцию экспорта скриптов Lotus с небольшим форматированием. В обоих случаях несколько значений не могут отображаться в одной ячейке. В каждой строке отображается только первое значение. Остальные значения игнорируются. Наш пользователь хочет, чтобы отчет Excel был только с несколькими значениями в новой строке, а не с каким-либо другим разделителем.Lotus Notes View с многострочными данными Экспорт в Excel

Просьба помочь мне с вашими предложениями. Я использую Lotus Notes 6.5 и Microsoft office 2010.

Спасибо.

ответ

4

Написать экспорт в Lotusscript. Не сложно, и вы полностью контролируете экспорт. Если поля представляют собой многозначные поля, просто прочитайте значения как вариант, а затем напишите их в выходной файл с новой строкой между каждым элементом.

Вот одна идея, как решить эту проблему:

%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 

Option Public 
Option Declare 

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) 
       End ForAll 
       column(CStr(cnt)) = Left$(tmp,Len(tmp)-1) 
      Else 
       column(CStr(cnt)) = v 
      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 
       textrow = textrow + |"| + Replace(h,Chr$(13),"\n") + |",| 
      End ForAll 
      rowarray(cnt) = Left$(textrow,Len(textrow)-1) 
      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("DominoServer/YourDomain", "names.nsf", "People\By Last Name") 
    outfile = "c:\ExcelExportTest.csv" 
    Open outfile For Output As #1 
    ForAll row In csv.CSVArray() 
     Print #1, row 
    End ForAll 
    Close #1 

    outfile = "c:\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 
+0

Обратите внимание, что я заменю с \ разрыв строки п в CSV, так как перевод строки не действует там. Либо замените его в Excel, либо замените его любым разделителем. –

+0

Большое вам спасибо :) – Priya

Смежные вопросы