Excel Lotus Notes:如何以.xls而不是.csv格式导出视图(列值)

Excel Lotus Notes:如何以.xls而不是.csv格式导出视图(列值),excel,csv,lotus-notes,notesview,Excel,Csv,Lotus Notes,Notesview,我想以.xls格式而不是.csv格式从列值导出基于CSVview的内容。现在它以.csv格式导出。我尝试将文件名替换为.xls,但该文件无法同时对MS Excel和open Office打开。你能帮忙吗 代码如下: 子初始化 将会话设置为新便笺会话 Dim db As NotesDatabase Dim CSV视图作为注释视图 昏暗的Lookup视图为NotesView Dim exportmaildoc As NOTES文档 Dim pathdoc As notes文档 将对象变暗为Notes

我想以.xls格式而不是.csv格式从列值导出基于CSVview的内容。现在它以.csv格式导出。我尝试将文件名替换为.xls,但该文件无法同时对MS Excel和open Office打开。你能帮忙吗

代码如下:

子初始化
将会话设置为新便笺会话
Dim db As NotesDatabase
Dim CSV视图作为注释视图
昏暗的Lookup视图为NotesView
Dim exportmaildoc As NOTES文档
Dim pathdoc As notes文档
将对象变暗为NotesEmbeddedObject
Dim exporttoid作为变体
将数据文件名设置为字符串
将文件路径设置为字符串
变暗文件名作为变量
Set db=session.CurrentDatabase
设置CSVview=db.GetView(“Top10DCV”)
datafileEnd$=“ESI\u Top\u 10\u Density\u Unders.csv”
设置lookupview=db.GetView(“lookupkeyword”)
设置pathdoc=lookupview.GetDocumentByKey(“UploadFilePath”)
如果不是,那么pathdoc什么都不是
filepath=pathdoc.Keyword(0)
datafileName=filepath&datafileEnd$
其他的
MsgBox“未找到文件路径。”
出口接头
如果结束
datafileNum=FreeFile()
打开datafileName以作为datafileNum输出
调用ViewCSVPrint(CSVview,数据文件名)
设置exportmaildoc=lookupview.GetDocumentByKey(“密度”)
如果不是exportmaildoc,那么它什么都不是
exporttoid=exportmaildoc.Keyword
如果结束
Dim maildoc As NOTES文档
设置maildoc=db.CreateDocument
Dim rItem As notes RichTextItem
maildoc.subject=“报告导出文件”
Set rtitem=New NotesRichTextItem(maildoc,“Body”)
调用rtitem.AppendText(“请查找下面的报告:”)
调用rtitem.AddNewLine(2)
Set object=rtitem.EmbedObject(嵌入附件“”,数据文件名)
Dim allofthem()作为字符串
ReDim将allofthem(UBound(exporttoid))保留为字符串
对于q=0到uBond(exporttoid)
allentries=allentries+1
allofthem(q)=导出ID(q)
下一个
maildoc.sendto=allofthem
如果maildoc.sendto(0)”,则
调用maildoc.send(False)
如果结束
出口接头
端接头
----------------------------------------------------------------------------
子视图CsvPrint(CSVview作为NotesView,文件名作为字符串)
作为整数的Dim x
Dim vc As NOTES VIEWENTRY集合
'CSV静态标题
打印#datafileNum%,(Format$(“DimWt/ActWt%”,“”)和“&Format$”(“DimWt/ActWt%”,“”)和“&Format$”(“MT/PN”、“”)和“&Format$”(“Model”、“”)和“&Format$”(“PkgVol/ProdVol”、“”)和“&Format$”(“PkgProdL(mm)”、“”)和“&Format$”(“PkgProdW(mm)”、“”)和“&Format$”(“PkgProdD(mm)”、“”)和“&Format$”、“&pkrodd$”、”和“&Format$”、”pkrodd格式(“、”pkrodd格式(“、”和“、”pkrodd格式(“”)$(“PkgProdDimWt”、“PkgProdDimWt”、“PkgProdDimWt”、“PkgProdDimWt”、“PkgProdDimWt”、“PkgProdDimWt”、“PkgProdDimWt”、“PkgProdDimWt”和“&Format$”、“&Format$”、“&Format$”、“&Format$”、”、“&Format$”、“ProdWt(kg)”、“&proddistence$”、“&Format$”、“pkgproddistence”、“Pkg/ProdVolRatio”和“)
Const NotesMacro$={@DBColumn(“:”;@dbname;“Top10DCV”;2)}
retval=Evaluate(NotesMacro$)
对于t=0到UBound(返回值)
设置vc=CSVview.GetAllEntriesByKey(retval(t),True)
设置v2entry=vc.GetFirstEntry
doccount1=0
doccount1<10时执行,而不是v2entry什么都不是
雷迪姆保留tmpArray3(tmpcount3)
雷迪姆保留tmpArray4(tmpcount4)
雷迪姆保留tmpArray5(tmpcount5)
雷迪姆保留tmpArray6(tmpcount6)
雷迪姆保留tmpArray7(tmpcount7)
雷迪姆保留tmpArray8(tmpcount8)
雷迪姆保留tmpArray9(tmpcount9)
雷迪姆保留tmpArray10(tmpcount10)
雷迪姆保留tmpArray11(tmpcount11)
雷迪姆保留tmpArray12(tmpcount12)
雷迪姆保留tmpArray13(tmpcount13)
雷迪姆保留tmpArray14(tmpcount14)
雷迪姆保留tmpArray15(tmpcount15)
ReDim保留tmpArray16(tmpcount16)
雷迪姆保留tmpArray17(tmpcount17)
雷迪姆保留tmpArray18(tmpcount18)
雷迪姆保留tmpArray19(tmpcount19)
雷迪姆保留tmpArray20(tmpcount20)
雷迪姆保留tmpArray21(tmpcount21)
tmpArray3(tmpcount3)=v2entry.ColumnValues(3)
tmpArray4(tmpcount4)=v2entry.ColumnValues(4)
tmpArray5(tmpcount5)=v2entry.ColumnValues(5)
tmpArray6(tmpcount6)=v2entry.ColumnValues(6)
tmpArray7(tmpcount7)=v2entry.ColumnValues(7)
tmpArray8(tmpcount8)=v2entry.ColumnValues(8)
tmpArray9(tmpcount9)=v2entry.ColumnValues(9)
tmpArray10(tmpcount10)=v2entry.ColumnValues(10)
tmpArray11(tmpcount11)=v2entry.ColumnValues(11)
tmpArray12(tmpcount12)=v2entry.ColumnValues(12)
tmpArray13(tmpcount13)=v2entry.ColumnValues(13)
tmpArray14(tmpcount14)=v2entry.ColumnValues(14)
tmpArray15(tmpcount15)=v2entry.ColumnValues(15)
tmpArray16(tmpcount16)=v2entry.ColumnValues(16)
tmpArray17(tmpcount17)=v2entry.ColumnValues(17)
tmpArray18(tmpcount18)=v2entry.ColumnValues(18)
tmpArray19(tmpcount19)=v2entry.ColumnValues(19)
tmpArray20(tmpcount20)=v2entry.ColumnValues(20)
tmpArray21(tmpcount21)=v2entry.ColumnValues(21)
doccount1=doccount1+1
打印#datafileNum%,(格式$(tmpArray3(tmpcount3),“0.00%”&“;”格式$(tmpArray4(tmpcount4),“0.00”)&“&tmpArray5(tmpcount5)&“&tmpArray6(tmpcount6)&”&“&Format$(tmpArray7(tmpcount7),“0.00”)&“&Format$(tmpArray8(tmpcount8),“0.0”)&“&Format$(tmpArray9(tmpcount9),“0.00”)&tmpArray7(tmpcount7),“0.00”)&”(tmpcount)格式)&“tmparay10.0”)&”(tmpcount11),“0.000”和“&Format$”(tmpArray12(tmpcount12),“0.00”)和“&Format$”(tmpArray13(tmpcount13),“0.00”)和“&Format$”(tmpArray14(tmpcount14
Dim csv As CSVData
Dim outfile As String

Set csv = New CSVData("DominoServer/YourDomain", "names.nsf", "People\By Last Name")
'*** Create HTML table and save as .xls to open in Excel
outfile = "c:\ExcelExportTest.xls"
Open outfile For Output As #1
Print #1, "<table>"
ForAll row In csv.HTMLArray()
    Print #1, row
End ForAll
Print #1, "</table>"
Close #1
%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 Apache Licence Version 2. 
    See http://www.apache.org/licenses/LICENSE-2.0.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