Lotus通过OLE方式操作Word实例

这个实例是现有可用的例子中拷贝出来。

首先在表单中必须有ole的关键系统域集合(OLE Controlfields)三个,它们分别是

      “$OLEObjRichTextField”的默认值:"OLEBody";

      “$OLEObjField”的默认值:"Oleobject";

      “$OLEObjProgID”的默认值:"Word.Document";

另外有个RTF域“Oleobject”,用来展示word界面。

再在表单的全局声明(Declarations)中

Dim ObjhandleV As Variant

postopen事件中写入如下代码

 Dim w As New notesuiworkspace
 Dim s As New notessession
 Dim uid As notesuidocument
 Dim doc As notesdocument
 
 Set doc=Source.document
 Call doc.replaceitemvalue("saveoptions","0")
 Call Source.gotofield("Oleobject")
 
 Set ObjhandleV=Source.CreateObject("WordOBJ","Word.Document")
 ObjhandleV.PageSetup.Orientation = 1

在应用功能按钮中写入的代码

On Error Goto ErrorHandle
 
 Dim ss As New NotesSession
 Dim uws As New NotesUIWorkspace
 Dim db As NotesDatabase
 Dim vw As NotesView
 Dim dcc As NotesDocumentCollection
 Dim docstatic As NotesDocument
 Dim docParent As NotesDocument
 Dim rtitem As NotesRichTextItem
 
 Dim strkey(1) As String
 Dim rHandle As Variant '范围句柄
 Dim tHandle As Variant '表格句柄
 Dim count As Integer
 Dim strtemp As String
 
 Set db = ss.CurrentDatabase
 Set vw = db.GetView("Search_AppsheetByYear_View")
 
 flag = uws.DialogBox("(Statboard_Year)",True,True,False,False,False,False,"蔡奇市长批示反馈情况统计")
 If Not flag Then Exit Sub
 
 strkey(0)= uws.CurrentDocument.Document.strYear(0)
 strkey(1) = "蔡奇市长"
 Set dcc = vw.GetAllDocumentsByKey(strkey,True)
 If dcc.Count = 0 Then
  Msgbox "没有"
  Exit Sub
 End If
 
 Set selection=ObjhandleV.ActiveWindow.selection
 Selection.Font.Bold = wdToggle
 selection.typetext("蔡奇市长批示反馈情况统计表")
 Selection.Font.Bold = wdToggle
 Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
 Selection.Font.Bold = wdToggle
 
 Set rHandle=selection.Range
 Selection.Font.Bold = False
 Set tHandle=ObjhandleV.Tables.add(rHandle,1,8)
 
 thandle.rows(1).select
 selection.rows(1).cells(1).range.insertafter("序号")
 selection.rows(1).cells(2).range.insertafter("标题")
 selection.rows(1).cells(3).range.insertafter("批示日期")
 selection.rows(1).cells(4).range.insertafter("批示内容")
 selection.rows(1).cells(5).range.insertafter("承办单位")
 selection.rows(1).cells(6).range.insertafter("要求反馈日间")
 selection.rows(1).cells(7).range.insertafter("实际反馈时间")
 selection.rows(1).cells(8).range.insertafter("备注")
 count = 1
 
 Set docstatic = dcc.GetFirstDocument()
 While Not docstatic Is Nothing
  selection.InsertRowsBelow
  
  With selection.rows(1).cells(1).range
   .ParagraphFormat.Alignment=0
   .insertafter(Cstr(count))
   .font.name="宋体"
   .font.size=10
  End With
  
  strtemp = docstatic.odt_subject(0)
  With selection.rows(1).cells(2).range
   .ParagraphFormat.Alignment=0
   .insertafter(strtemp)
   .font.name="楷体_GB2312"
   .font.size=10
  End With
  
  
  strtemp = Format(Cstr(docstatic.jb_readTm(0)),"m.d")  
  With selection.rows(1).cells(3).range
   .ParagraphFormat.Alignment=0
   .insertafter(Cstr(strtemp))
   .font.name="楷体_GB2312"
   .font.size=10
  End With
  
  Set rtitem = docstatic.GetFirstItem("odt_content")
  If rtitem Is Nothing Then
   strtemp = ""
  Else
   strtemp = rtitem.Text
  End If
  
  With selection.rows(1).cells(4).range
   .ParagraphFormat.Alignment=0
   .insertafter(strtemp)
   .font.name="楷体_GB2312"
   .font.size=10
  End With
  
  strtemp = docstatic.sendto(0)
  With selection.rows(1).cells(5).range
   .ParagraphFormat.Alignment=0
   .insertafter(strtemp)
   .font.name="楷体_GB2312"
   .font.size=10
  End With
  
  strtemp = Format(Cstr(docstatic.Expired(0)),"m.d")
  With selection.rows(1).cells(6).range
   .ParagraphFormat.Alignment=0
   .insertafter(strtemp)
   .font.name="楷体_GB2312"
   .font.size=10
  End With
  
  If docstatic.IsResponse Then
   Set docParent = db.GetDocumentByUNID( docstatic.ParentDocumentUNID)
   If (Not docParent Is Nothing) And ( docParent.IsValid  ) Then
    strtemp = docParent.fileno(0)
    With selection.rows(1).cells(7).range
     .ParagraphFormat.Alignment=0
     .insertafter(strtemp)
     .font.name="楷体_GB2312"
     .font.size=10
    End With
   End If
  End If
  count = count+1
  
  Set docstatic = dcc.GetNextDocument(docstatic)
 Wend
 
 tHandle.AutoFitBehavior(wdAutoFitWindow)
 Messagebox "统计完毕。"
 
 Exit Sub
ErrorHandle:
 Call RecordErrorLog("市长批示反馈统计","办理反馈",Erl,Err,Error)
在关闭按钮表单事件中加入

@Command([ToolsRunMacro]:"(ClosetheObject)");
@PostedCommand([FileCloseWindow])

ClosetheObject代理中的是lotus代码,属性触发按事件,代理列表选择,目标无;在Initialize中为

ObjhandleV.quit

结束,更改下可看到效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值