视图内的文档数据写入word表格的代码,首先有word文件的模板,模板中有一个设置好的表格,然后在表格中写入对应的数据。
Dim wdapp,mytable As Variant
Dim work As New Notesuiworkspace
Dim doc As notesdocument
Dim session As New notessession
Dim db As notesdatabase
Dim vw As NotesView
Dim item As NotesItem
Dim strUser As String
Dim pp(6) As String '字段名
Dim strDep As String
Dim intRow As Integer
Dim BeforeRow As Variant
Dim currow As Integer
Dim i As Integer
Dim strCreatedFile As String
Dim strReport As String
Dim strarrUsers(0 To 1) As String
Set db = session.currentdatabase
Set vw = db.GetView("视图名")
Set doc = vw.GetFirstDocument
’设置字段名
pp(1)=""
pp(2)=""
...
If doc Is Nothing Then
Messagebox "数据为空!",64,"信息提示"
Exit Sub
End If
Print "正在生成标准表格..."
'
Set wdapp = createobject("Word.Application") '调用Microsoft Word
wdapp.visible=False '使WORD不可见
'模版见附件,以下程序用LotusScript调用Word VBA将notes数据传到WORD模版中
'VBA帮助在完全安装的Office97目录中的VBAWRD8.HLP文件中
wdapp.documents.open("word文件路径和文件名")
Set mytable=wdapp.activedocument.tables(1)
intRow=1
intCol=1
While Not doc Is Nothing
intRow = intRow + 1
Set BeforeRow = myTable.Rows(intRow)
myTable.Rows.Add BeforeRow
For i=1 To 3
Set item = doc.GetFirstItem(pp(i))
If Not item Is Nothing Then
mytable.cell(intRow,i+1).range.insertafter(Cstr(item.Values(0)))
End If
Next
Set doc = vw.GetNextDocument(doc)
Wend
If intRow > 1 Then
myTable.Rows(intRow+1).Delete
End If
'wdapp.activedocument.printout '打印
Call wdapp.activedocument.saveas("文件路径和文件名")
wdapp.activedocument.close(0) '不保存退出
wdapp.quit
Messagebox "报表已生成。",64,"信息提示"
为什么我照着你的代码做视图的内容没导出?这一段代码还有什么要改的地方?
Set doc=dc.getfirstdocument
Dim fieldname As String
Dim fitem As notesitem
rows=2
cols=1
Do While Not(doc Is Nothing)
For x=0 To Ubound(view.columns)
xlapp.statusbar="正在从Notes中引入数据,请稍等......"
If view.columns(x).IsHidden=False Then
If view.columns(x).title<>"" Then
fieldname = view.columns(x).itemname
Set fitem = doc.getfirstitem("number")
xlsheet.cells(rows, cols).value = fitem.text
cols = cols +1
End If
End If
Next
rows = rows+1
cols = 1
Set doc= dc.getnextdocument(doc)
Loop
Dim wdapp,mytable As Variant
Dim work As New Notesuiworkspace
Dim doc As notesdocument
Dim session As New notessession
Dim db As notesdatabase
Dim vw As NotesView
Dim item As NotesItem
Dim strUser As String
Dim pp(6) As String '字段名
Dim strDep As String
Dim intRow As Integer
Dim BeforeRow As Variant
Dim currow As Integer
Dim i As Integer
Dim strCreatedFile As String
Dim strReport As String
Dim strarrUsers(0 To 1) As String
Set db = session.currentdatabase
Set vw = db.GetView("视图名")
Set doc = vw.GetFirstDocument
’设置字段名
pp(1)=""
pp(2)=""
...
If doc Is Nothing Then
Messagebox "数据为空!",64,"信息提示"
Exit Sub
End If
Print "正在生成标准表格..."
'
Set wdapp = createobject("Word.Application") '调用Microsoft Word
wdapp.visible=False '使WORD不可见
'模版见附件,以下程序用LotusScript调用Word VBA将notes数据传到WORD模版中
'VBA帮助在完全安装的Office97目录中的VBAWRD8.HLP文件中
wdapp.documents.open("word文件路径和文件名")
Set mytable=wdapp.activedocument.tables(1)
intRow=1
intCol=1
While Not doc Is Nothing
intRow = intRow + 1
Set BeforeRow = myTable.Rows(intRow)
myTable.Rows.Add BeforeRow
For i=1 To 3
Set item = doc.GetFirstItem(pp(i))
If Not item Is Nothing Then
mytable.cell(intRow,i+1).range.insertafter(Cstr(item.Values(0)))
End If
Next
Set doc = vw.GetNextDocument(doc)
Wend
If intRow > 1 Then
myTable.Rows(intRow+1).Delete
End If
'wdapp.activedocument.printout '打印
Call wdapp.activedocument.saveas("文件路径和文件名")
wdapp.activedocument.close(0) '不保存退出
wdapp.quit
Messagebox "报表已生成。",64,"信息提示"
为什么我照着你的代码做视图的内容没导出?这一段代码还有什么要改的地方?
Set doc=dc.getfirstdocument
Dim fieldname As String
Dim fitem As notesitem
rows=2
cols=1
Do While Not(doc Is Nothing)
For x=0 To Ubound(view.columns)
xlapp.statusbar="正在从Notes中引入数据,请稍等......"
If view.columns(x).IsHidden=False Then
If view.columns(x).title<>"" Then
fieldname = view.columns(x).itemname
Set fitem = doc.getfirstitem("number")
xlsheet.cells(rows, cols).value = fitem.text
cols = cols +1
End If
End If
Next
rows = rows+1
cols = 1
Set doc= dc.getnextdocument(doc)
Loop