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);
                                   }
                     }
 
       }
 
}
 
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Lotus Domino_Notes R6应用技术

  • 2011-09-09 00:15
  • 21.03MB
  • 下载

LOTUS DOMINO R5 安全技术

  • 2008-08-02 18:57
  • 6.91MB
  • 下载

IBM Lotus 产品 单点登录(SSO) 总结

作者:soldierxue@163.com 单点登录(SSO)在企业内部业务系统之间是一个非常常见的需求,本文收录了网上关于这方面的精彩介绍,并加入作者自己的实践经验,期望可以给大家一些帮助

LOTUS DOMINO R5 安全技术

  • 2013-02-15 21:25
  • 9.35MB
  • 下载

IBM / Lotus Domino 与 WebSphere Portal: 单点登录(转)

摘要 IBM WebSphere Portal 为 IT 公司带来了巨大的价值,使他们能够创建强大的 Web应用,这些 Web 应用允许用户集中地访问,并提供个性化信息。公司可以从门户中获益,比如简...

Lotus web 开发技术

  • 2010-11-16 12:10
  • 905KB
  • 下载

UBUNTU 10.10装LOTUS8.01

安装:用emule下的,下载地址 引用页: http://www.verycd.com/topics/200085/ed2k://|file|[IBM.电子商务].TLF-SOFT-IBM.Lotus...

Lotus Domino R5 安全技术

  • 2008-11-20 10:38
  • 6.91MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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