论坛中的用vfp控制word表,导入到dbf表中

作者在 2023-01-09 22:36:17 发布以下内容
****  要再能自动造表,不如吹版的简单(仅参考)
 close all
  cwj=ADDBS(SYS(5)+SYS(2003))+"文档.docx"
  ow=CREATEOBJECT("word.application")
  ot=ow.Application.Documents.Open(cwj)   
  nrow=ot.tables(1).rows.count
  ncol=ot.Tables(1).Columns.Count
  create cursor b1 (zd1 c(20),zd2 n(10))
  
  csq="select " && 先造一个表
  for nn=1 to ncol
      zd=ot.Tables.item(1).cell(1,nn).range.text
      do case
         case nn<3
              csq=csq+"zd1 as "+zd+","
         case nn>2 and nn<7
              csq=csq+"zd2 as "+zd+","
         case nn=7
              csq=csq+"zd2 as "+zd+" from b1 into cursor b2 readwrite"
       endcase      
   endfor                    
    csq=CHRTRAN(csq,CHR(7)+CHR(13),'')
    ExecScript(csq)
  ********** 造表完毕

  select b2 &&给表填数据
  for i=2 to nrow
      append blank
      for j=1 to ncol
          zd=ot.Tables.item(1).cell(i,j).range.text
          zd=CHRTRAN(zd,CHR(7)+CHR(13),'')
          czd=FIELD(j)
          if j>2
             zd=VAL(zd)
          endif   
          replace &czd with zd
      endfor
  endfor
     
   ow.ActiveDocument.Close
   ow.Quit
   browse
  close all
  
默认分类 | 阅读 214 次
文章评论,共0条
游客请输入验证码
浏览3210次
文章分类
最新评论