LotusScript从NotesDocumentCollection

时间:2017-01-18 18:19:20

标签: excel lotusscript

我需要在视图的两个日期之间导出到Excel文档。 我基于NotesDateRange创建了NotesDocumentCollection。

我遇到了问题:

ForAll colval In doc.Columnvalues

当doc来自NotesView但是我需要两个日期之间的文档时,它工作正常,所以doc来自NotesDocumentCollecion,然后我得到“Type mismatch”错误。

来自NotesView的doc代码片段工作正常:

Set doc = view.Getfirstdocument()
row% = 0
While Not doc Is Nothing
    row% = row% + 1
    col% = 0 'Reset the columns
    ForAll  colval In doc.Columnvalues
        col% = col% + 1
        xlSheet.Cells(row%,col%).value = colval
    End ForAll
Set doc = view.Getnextdocument(doc)
Wend`

使用NotesDocumentCollection中的doc代码片段,我在ForAll行中出现“Type mismatch”错误:

Set doc = dc.Getfirstdocument()
row% = 0
While Not doc Is Nothing
    row% = row% + 1
    col% = 0 'Reset the columns
    ForAll  colval In doc.Columnvalues
        col% = col% + 1
        xlSheet.Cells(row%,col%).value = colval
    End ForAll
Set doc = dc.Getnextdocument(doc)
Wend`

有没有人知道如何从NotesDocumentCollection导出到Excel?

2 个答案:

答案 0 :(得分:0)

文档集没有列。它是一个文档集合,所以你的forall毫无意义。您无法像您尝试的那样访问文档字段。您需要知道每个列引用的字段的名称,或者如果列是公式,请自行计算。例如:

dim fieldnames(10) as string
fieldnames(0) = "firstname"
fieldnames(1) = "lastname"
' etc.

一个选项可能是设置字段名称数组。例如:

for I = 0 to ubound(fieldnames)
    xlSheet.Cells(row, I) = doc.getItemValue(fieldnames(I))
next I

这将允许你做类似的事情:

order

答案 1 :(得分:-1)

Columnvalues的帮助: “只读。一个值数组,其中每个元素对应于文档父视图中的列值。数组中的第一个值是文档的第一列中显示的值,第二个值是出现在第二列中的一个,依此类推。数组中每个元素的值是相应列的公式和当前文档中的项的结果。数组中的某些元素可能没有值。

如果您不通过视图访问文档,则此属性没有值。“

doc.Columnvalues IS 可用于notesdocumentcollection中的文档,但仅当该集合通过视图填充时,例如使用view.getalldocumentsbykey()。

所以在您的问题中没有足够的信息:您是如何获得文档集合的?如果它是FTSearch,则不会涉及视图,因此不存在列值