Lotus 技术点之导入

原创 2007年09月12日 10:24:00
 
a)           从文本导入
Sub Initialize
       On Error Goto UnknowError
       Msgbox "开始导入"
       Dim session As New NotesSession
       Dim db As NotesDatabase
       Dim view As NotesView
       Dim doc As NotesDocument
       Dim docPerson As NotesDocument
       Dim docTemp As NotesDocument
       Dim vFile As Variant
       Dim strMyname As String
       Dim strDeptNO As String
       Dim strDeptName As String
       Dim strFile As String
       Dim V1 As String
       Dim NO,myname,sex,deptNo,deptName,duty,office,phone,mobile,fax,mail,IP,postalcode,address,remark As String
      
       Set db=session.CurrentDatabase
       Set doc=session.DocumentContext
       vFile =Evaluate({@AttachmentNames},doc)
       strFile =Cstr(vFile(0))
       Msgbox strFile
       Dim ebd As NotesEmbeddedObject
       Set ebd=doc.GetAttachment(strFile)
       Msgbox ebd Is Nothing
       Call ebd.extractFile(strFile )
       Open strFile For Input As 10
       Dim i As Integer
       i=1
       If Not Eof(10) Then
              Input #10,V1
       End If
continue: Do While Not Eof(10)
              Input #10,V1
              If V1="" Then
                     Goto continue
              Else
                     myname=Strtoken(V1," ",1)
                     sex=Strtoken(V1," ",2)
                     deptName=Strtoken(V1,"      ",3)
                     duty=Strtoken(V1,"       ",4)
                     office=Strtoken(V1,"     ",5)
                     phone=Strtoken(V1,"     ",6)
                     mobile=Strtoken(V1,"    ",7)
                     fax=Strtoken(V1," ",8)
                     mail=Strtoken(V1," ",9)
                     IP=Strtoken(V1,"   ",10)
                     postalcode=Strtoken(V1,"      ",11)
                     address=Strtoken(V1,"   ",12)
                     remark=Strtoken(V1,"    ",13)
              End If
              If myname="" Then
                     Print {<script>alert("第} & i & {条记录姓名为空,未导入");history.go(-1);</script>}
                     Goto continue
              End If
              If deptName="" Then
                     Print {<script>alert("第} & i & {条记录部门名称为空,未导入");history.go(-1);</script>}
                     Goto continue
              End If
              If phone="" Then
                     Print {<script>alert("第} & i & {条记录固定电话为空,未导入");history.go(-1);</script>}
                    
                     Goto continue
              End If
              If mobile="" Then
                     Print {<script>alert("第} & i & {条记录手机号码为空,未导入");history.go(-1);</script>}
                     Goto continue
              End If
              Set docPerson=db.CreateDocument
              docPerson.form="PersonInfo"
              docPerson.myName=myname
              docPerson.sex=sex
              docPerson.dept=deptName
              docPerson.duty=duty
              docPerson.office=office
              docPerson.phone=phone
              docPerson.mobile=mobile
              docPerson.fax=fax
              docPerson.mail=mail
              docPerson.IP=IP
              docPerson.postalcode=postalcode
              docPerson.address=address
              Dim ritem As NotesRichTextItem
              Set ritem=New NotesRichTextItem(docPerson,"remark")
              ritem.text=remark
              Call docPerson.Save(True,False)
       Loop
       Close #10
       Kill strFile
       Print {<script>alert("导入成功")</script>}
       Exit Sub
UnknowError:
       Msgbox "错误行:" & Erl & "错误信息:" & Error
       Exit Sub
End Sub
 
b)          Excel导入到notes中
Dim session     As New notessession
       Dim db          As notesdatabase
       Dim view        As notesview
       Dim doc         As notesdocument
       Dim tempdoc     As notesdocument
       Dim w           As New notesuiworkspace
       Dim authorsItem As NotesItem
       Dim collection As NotesDocumentCollection
       Dim v(0)        As String
       Dim r           As Integer
       Dim xlapp       As Variant
       Dim xlbook      As Variant
       Dim xlsheet     As Variant
      
       Set db = session.CurrentDatabase
       Set collection = db.UnprocessedDocuments
       Set doc = collection.GetFirstDocument()
      
       Eval = Evaluate(|@IsNotMember("[Administrator]";@UserRoles)|,doc) '用户执行操作时的判断权限
       If Eval(0) = 1 Then
              Msgbox "对不起,您无权使用此权限!请与管理员联系",0+16,"提示"
              Exit Sub
       End If
      
REM 导入数据时,不采用绝对的路径和文档名称 
       Dim files As Variant
       files = w.OpenFileDialog(True, "打开Excel文档","", "D:")
       Set db = session.currentdatabase
       If Isempty(files(0)) Then
              Exit Sub
       Else
              Set xlApp = CreateObject("Excel.Application")         '创建Excel应用类
              xlApp.Visible = False                                 '设置Excel为不可见
              Set xlBook = xlApp.Workbooks.Open(files(0))           '打开Excel工作薄
             
             
REM 设置打开Excel的第几个工作表
              num =Cstr(Inputbox$("请问您想导入的工作表为第几个?"))
              If num = "" Then
                     Exit Sub
              End If    
              a = Cint(num)
              Set XlSheet = xlBook.Worksheets(a)                     '打开Excel工作表
       End If
      
       r = 4
       While Not Cstr(xlsheet.cells(r,1).value) = ""
              Set doc = New NotesDocument(db)
             
              doc.Form       = "shenqing"
              doc.date_1     = xlsheet.cells(r,1).value              '申请日期
              doc.Deft       = xlsheet.cells(r,2).value              '申请部门
              doc.Text_5     = xlsheet.cells(r,3).value              '申请工作区域
              doc.Text_1     = xlsheet.cells(r,4).value              '来访人员姓名
              doc.CheckBox_2 = xlsheet.cells(r,5).value              '来访人员有效证件名称
              doc.Text_2     = xlsheet.cells(r,6).value              '来访人员有效证件号码
              doc.Text_3     = xlsheet.cells(r,7).value              '来访人员公司名称
              doc.sdate      = xlsheet.cells(r,8).value              '工作有效期限
              doc.Text_9     = xlsheet.cells(r,9).value              '发放证件编号
             
              r = r+1
              Print r
             
REM "编号的生成"
              DateKey1 = Cstr(Format(doc.date_1(0),"yyyy"))          '取原始数据中的年
              DateKey2 = Cstr(Format(doc.date_1(0),"mm"))            '取原始数据中的月
              DateKey3 = Cstr(Cint(DateKey1))+"-"+Cstr(Cint(DateKey2))
             
              DateKey = DateKey1+DateKey2
             
              Dim Numview As NotesView
              Dim Numdoc As NotesDocument
              Dim vc As NotesViewEntryCollection
              Dim entry As NotesViewEntry
             
              Set Numview = db.GetView( "AllByNumber" )
              Call Numview.refresh
              Set vc = Numview.GetAllEntriesByKey(DateKey3,True)
             
              doc.import = 1                                                          '设置表单数据倒入时的参数
              doc.date = ""                                           '使数据导入后,打开表单时不显示表单创建的时间
             
              If vc.count =0 Then
                     doc.Number = DateKey+"001"
              Else
                     Set entry = vc.GetFirstEntry()
                     Set Numdoc = entry.Document
                     K = Cint(Right(Numdoc.Number(0),3))+1
                     If K <10 Then
                            Key1 = "00"+Cstr(K)
                     Elseif K<100 Then
                            Key1 = "0"+Cstr(K)
                     Else
                            Key1 = Cstr(K)
                     End If
                     doc.Number = DateKey+Key1
              End If                 
              doc.SaveOptions = "1"
              Call doc.save(False,True)
             
              If doc.Text_9(0) <> "" Then                               '流程参数设置
                     doc.lei = "已完成"        
                     doc.actionnumber = "-1"
                     doc.statu = 2                      
                     doc.saveoptions = "1"
                     Call doc.save(False,True)
              End If
       Wend
      
       Call xlbook.close(True)
       Call xlapp.quit
       Msgbox"导入完毕",0+32,"提示"
 
c)           Excel导入notes之java版本
import lotus.domino.*;
import java.io.*;
import java.util.Vector;
import jxl.*;
import java.io.PrintWriter;
                       
public class JavaAgent extends AgentBase {
 
       public void NotesMain() {
              System.out.println("11111111");
              Session ss = getSession();
          String srcFile = null;
              String s=null;
              Workbook rwb = null;
          Document doc = null;
          //'Cell ck0 = null;
              InputStream inps = null;
              Sheet rs=null;
              int totalnum=0;
              System.out.println("2222222222");
              PrintWriter pw = getAgentOutput();
              EmbeddedObject ebd = null;
              File f=null;                   
              try {
                     System.out.println("33333333333333");
                     AgentContext agt = ss.getAgentContext();
                     Document cdoc = agt.getDocumentContext();
                     Database cdb = agt.getCurrentDatabase();
                     DocumentCollection dc = null;
                     Agent ag=null;
                     String strdata = null;
                     String strContent = null;
                     Double dob=null;
                     StringBuffer tmpstr=new StringBuffer("1");
                    
                     Vector vtr = ss.evaluate("@AttachmentNames",cdoc);
               srcFile =new String(""+vtr.get(0).toString());
               ebd = cdoc.getAttachment(srcFile);
                       System.out.println(srcFile);
                            ebd.extractFile(srcFile);
                          System.out.println("44444444asdfasdf");
                           
                            //ebd.recycle();
                            //创建文件流,然后输出excel表格
                            inps = new FileInputStream(srcFile);
                            rwb = Workbook.getWorkbook(inps);
                    if (ebd==null)
                               {
                                    rwb.close();
                                 rwb = null;
                           return;
                       }
                            if (ebd.getType()!=EmbeddedObject.EMBED_ATTACHMENT)
                      {
                             rwb.close();
                                   rwb = null;
                             return;
                      }
                            //读取第一张sheet
 
                            rs = rwb.getSheet(0);
                                       
                            Vector errRecord = new Vector();
 
                    for (int k=1;k<rs.getRows();k++)
                     {
                         System.out.println("44444444444444444444");
                    
                           Cell ck0 = rs.getCell(0,k);
                           Cell ck1 = rs.getCell(1,k);
                           Cell ck2 = rs.getCell(2,k);
                           Cell ck3 = rs.getCell(3,k);
                           Cell ck4 = rs.getCell(4,k);
                           Cell ck5 = rs.getCell(5,k);
                           Cell ck6 = rs.getCell(6,k);
                           Cell ck7 = rs.getCell(7,k);
                           Cell ck8 = rs.getCell(8,k);
                           Cell ck9 = rs.getCell(9,k);
                           Cell ck10 = rs.getCell(10,k);
                           Cell ck11 = rs.getCell(11,k);
                           Cell ck12 = rs.getCell(12,k);
                           Cell ck13 = rs.getCell(13,k);                     
                          
                           if(!ck0.getContents().equals(""))
                           {  
                               System.out.println("55555555");
                               doc=cdb.createDocument();
                               doc.appendItemValue("Form", "PersonInfo");
                                if(!ck0.getContents().equals(""))
                                {
                                  doc.appendItemValue("NO", ck0.getContents());
                                 }
                              if(!ck1.getContents().equals(""))
                                {
                                  doc.appendItemValue("myname",ck1.getContents());
                                 }
                                  if(!ck2.getContents().equals(""))
                                {
                                  doc.appendItemValue("sex", ck2.getContents());
                                 }
                                  if(!ck3.getContents().equals(""))
                                {
                                 doc.appendItemValue("dept", ck3.getContents());
                             
                                 }
                                  if(!ck4.getContents().equals(""))
                                {
                                  doc.appendItemValue("duty", ck4.getContents());
                              
                                 }
                                  if(!ck5.getContents().equals(""))
                                {
                                 doc.appendItemValue("office", ck5.getContents());
                              
                                 }
                                  if(!ck6.getContents().equals(""))
                                {
                                 doc.appendItemValue("phone", ck6.getContents());
                             
                                 }
                                  if(!ck7.getContents().equals(""))
                                {
                                  doc.appendItemValue("mobile", ck7.getContents());
                             
                                 }
                                  if(!ck8.getContents().equals(""))
                                {
                                  doc.appendItemValue("fax", ck8.getContents());
                              
                                 }
                                
                                  if(!ck9.getContents().equals(""))
                                {
                                 doc.appendItemValue("mail", ck9.getContents());
                              
                                 }
                                  if(!ck10.getContents().equals(""))
                                {
                                 doc.appendItemValue("IP", ck10.getContents());
                              
                                 }
                                  if(!ck11.getContents().equals(""))
                                {
                                 doc.appendItemValue("postalcode", ck11.getContents());
                             
                                 }
                                  if(!ck12.getContents().equals(""))
                                {
                                  doc.appendItemValue("address", ck12.getContents());
                             
                                 }
                                  if(!ck13.getContents().equals(""))
                                {
                                  RichTextItem rtitem = doc.createRichTextItem("remark");
                                  doc.appendItemValue("remark", ck13.getContents());
                                 }
                               if (doc.save())
                                   System.out.println("Document has been saved");
                                else
                                  System.out.println("Unable to save document");
                                    }
                            }
                           
              } catch(Exception e)
              {
                     System.out.println("error>>>>>"+e);
                    
                  }
      finally {  
                                   rwb.close();
                                   try
                                   {
                                          inps.close();
                                          boolean success = (new File(srcFile)).delete();
                                   }
                                   catch(Exception ex)
                                   {
                                          System.out.println(ex);
                                   }
                     }
 
       }
 
}
 

35. 面向对象的LotusScript(七)之导入Excel

Microsoft Office是应用最广泛的办公软件,绝大多数公司的必备软件。其中的Excel操作直观方便,很多公司都有大量数据以Excel文件的格式保存。一个LotusNotes应用在很多情况下都...
  • starrow
  • starrow
  • 2013年07月04日 22:43
  • 4216

Lotus Notes 公式函数集

A @Abs 返回一个数字的绝对值(无符号值)。 @Abstract 英文缩写,中文无效 @Accessed 指出最后一次访问(即读取或编辑)该文档的时间和日期。   @Acos 使用角度的余...
  • wodemingzisiweiwei
  • wodemingzisiweiwei
  • 2013年07月30日 11:25
  • 1216

使用Lotus Domino实用程序(Updall, Compact, Fixup) 进行正常和异常维护

目录    I.实用程序: Updall, Compact, Fixup   A. Updall   B. Compact   C. Fixup  II.用于每周维护的实用程序  III...
  • qin_zhimou
  • qin_zhimou
  • 2014年11月26日 16:58
  • 1086

lotus 简要表表单介绍

简要表表单对于收集特定用户或特定数据库的值很有用。这些值存储在“简要表”文档中。将这些文档分离为简要表文档的是这些文档的显示方式和返回的域值。 对于数据库的每个用户,每 个表单只能有一个简要表文档;...
  • qin_zhimou
  • qin_zhimou
  • 2013年01月23日 13:16
  • 2065

46. Lotus Notes中编程发送邮件(一)

邮件是Lotus Notes体系的核心和基本功能,以至于Send()是NotesDocument的一个方法,任何一个文档都可以被发送出去,Notes里的一封邮件也只是一个有一些特殊字段的文档。在程序开...
  • starrow
  • starrow
  • 2013年08月14日 17:24
  • 9131

IBM Lotus Domino 邮件服务器配置攻略

转自: http://tech.sina.com.cn/h/2008-09-04/0600792843.shtml
  • duanbeibei
  • duanbeibei
  • 2014年10月20日 11:42
  • 3386

Lotus 迁移到Exchange 2010 之准备使用Transport 同步Lotus 相关信息!

这里我们先来分析下Lotus迁移到Exchange2010 的一些原理,由于存在一定周期的共存时间,因此在共存期间必须来实现相应的同步计划,整个同步计划包含了如下的同步计划:那么我们先来讲下目录同步,...
  • fogyisland2000
  • fogyisland2000
  • 2013年10月29日 21:03
  • 3402

IBM Lotus Domino 8.5 服务器管理入门手册

下载试用版:IBM Lotus Notes 和 Domino Administrator 客户端软件  |   Lotus Domino 和 Lotus iNotes 服务器软件 1 简介 ...
  • zhpengfei0915
  • zhpengfei0915
  • 2015年04月25日 11:46
  • 1115

Exchange & Lotus Notes邮件系统在线批量迁移账号及邮件

Exchange & Lotus Notes邮件系统在线批量迁移账号及邮件
  • aliasman
  • aliasman
  • 2016年07月19日 14:29
  • 1124

邮件服务器配置(notes篇):lotus notes 9.0.1安装及配置

1.安装 环境:windows server  2008 64 1)lotus notes  9.0.1下载: https://www-01.ibm.com/marketing/iwm/iwm/we...
  • zs15yy
  • zs15yy
  • 2017年07月11日 14:47
  • 905
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Lotus 技术点之导入
举报原因:
原因补充:

(最多只允许输入30个字)