分享

使用 VFP 读取 excel 的信息采集表各项内容

 昵称38434767 2020-10-20
第一个按钮的代码
程序代码:
  CREATE TABLE wjmk( fname c(30))
  aa=ADIR(mm,'个人信息采集表*.xls')   
  FOR nn=1 to aa
    APPEND BLANK
    REPLACE fname with mm(nn,1)
  ENDFOR
  SELECT wjmk
  GO top
  thisform.grid2.RecordSource =''
  thisform.grid2.ColumnCount =-1
  thisform.grid2.RecordSourceType = 1
  thisform.grid2.RecordSource ='wjmk' 
  Thisform.Refresh  
  RETURN 
第二个按钮的代码
程序代码:
thisform.grid1.Visible = .F.
thisform.Refresh
*-----------------------------------------------------
SELECT wjmk
GO top
SCAN
  M_File=ALLTRIM(fname)   &&&GETFILE('xls','录用名单文件')
  IF USED('bmk')
    SELECT bmk
  ELSE 
    SELECT 0
    USE grxxk alia bmk
  ENDIF

 
  IF EMPTY(M_File)
    MESSAGEBOX("请选择待导入的EXCEL文档!",0+48,"提示")
    RETURN
  ELSE
   IF !JUSTEXT(M_FILE)$"XLS.xlsx"                             &&获得文件扩展名(JUSTEXT(M_FILE)#"XLS.xlsx")
     =MESSAGEBOX("您选择的不是EXCEL文档!",0+48,"提示")
     RETURN
   ENDIF
  ENDIF

  myexcel=createobject('excel.application')        && 创建一个对象
  IF !VARTYPE(myexcel)$"Oo"                        &&& 如果用户的电脑上未装EXCEL软件,则结束运行。
    MESSAGEBOX("建立EXCEL文件失败,请检查OFFICE是否正常!",48,"提醒:")
    RETURN
  ENDIF
  myexcel.visible=.F.                                && 对象不可见
  bookexcel=myexcel.workbooks.open(mypath+M_File)            && 打开指定文件
  *o_SheetName=myexcel.application.ActiveSheet.Name    && 获取当前激活工作表的名称
  *o_UsedRange =bookexcel.worksheets(o_SheetName).UsedRange     && 返回工作表中可使用的区域,UsedRange表的属性
  *o_rows=o_UsedRange.rows.count                        && 汇总行
  *o_cols=o_UsedRange.columns.count                     && 汇总列

 
  LOCAL m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15,m16,m17,m18,m19,m20
  LOCAL m21,m22,m23,m24,m25,m26,m27
       m1=myexcel.cells(1,2).text      &&身份证号  
       m2=myexcel.cells(2,2).text      &&姓名     
       m3=myexcel.cells(2,4).text      &&学校代码
       m4=myexcel.cells(2,6).text      &&学校名称全称 
       m5=myexcel.cells(2,8).text      &&年级
       m6=myexcel.cells(3,2).text      &&班级名称      
       m7=myexcel.cells(3,7).text      &&性别
       m8=myexcel.cells(4,2).text      &&民族
       m9=myexcel.cells(4,7).text       &&户籍镇街      
       m10=myexcel.cells(5,2).text      &&监护人      数值型的写法:m10=myexcel.cells(i,10).value
       m11=myexcel.cells(6,2).text      &&监护人手机
       m12=myexcel.cells(6,5).text      &&家庭住址      
       m13=myexcel.cells(7,2).text      &&学籍辅号
       m14=myexcel.cells(7,4).text      &&身份证号  
       m15=myexcel.cells(7,6).text      &&姓名     
       m16=myexcel.cells(8,3).text      &&学校代码
       m17=myexcel.cells(8,6).text      &&学校名称全称 
       m18=myexcel.cells(9,3).text      &&年级
       m19=myexcel.cells(9,6).text      &&班级名称      
       m20=myexcel.cells(10,2).text      &&性别        数值型的写法:m10=myexcel.cells(i,10).value
       m21=myexcel.cells(10,4).text      &&民族
       m22=myexcel.cells(10,9).text      &&户籍镇街      
       m23=myexcel.cells(12,2).text      &&监护人
       m24=myexcel.cells(13,2).text      &&监护人手机
       m25=myexcel.cells(11,2).text      &&家庭住址      
       m26=myexcel.cells(11,5).text      &&学籍辅号
       m27=myexcel.cells(11,9).text      &&身份证号 
       SELECT bmk
       APPEND BLANK
       REPLACE bh WITH m1,xm WITH m2,xb WITH m3,csrq WITH m4,mz WITH m5,jg WITH m6,csd WITH m7,jtzz WITH m8,post WITH m9
       REPLACE gzdw WITH m10,tel WITH m11,telm WITH m12,cjgzsj WITH m13,rdsj WITH m14,sfzh WITH m15,xl WITH m16,byxxzy WITH m17
       REPLACE zjxl WITH m18,zjbyxxzy WITH m19,xrzw WITH m20,jszw WITH m21,jszc WITH m22,jzqk WITH m23,ndkhqk WITH m24
       REPLACE hyzk WITH m25,jscs WITH m26,jslssj WITH m27
  
  myexcel.workbooks.close    && 关闭工作簿
  myexcel.quit               && 关闭excel
  RELEASE myexcel            && 释放对象变量,以完全结束EXCEL的进程
  SELECT wjmk
ENDSCAN
*-------------------------
SELECT bmk
GO top

thisform.grid1.ColumnCount =-1
thisform.grid1.RecordSource ='bmk'
thisform.grid1.RecordSourceType =1
thisform.grid1.Visible = .T.
thisform.Refresh
MESSAGEBOX('恭喜您,员工数据信息导入成功!',64,'提示:',1500)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多