CLOSE DATABASES
CREATE CURSOR tmp(姓名 C(10),除草 N(10),栽树 N(10),施肥 N(10),修路 N(10),粉刷 N(10),其他 N(10),合计 N(10))
WorkPath=GETDIR("","","请选择待导入文件夹:")
IF !EMPTY(WorkPath)
nFiles_doc=Adir(docArray,WorkPath+'*.doc')
IF nFiles_doc>0
FOR i=1 TO nFiles_doc
cWaitmesg="正在提取数据 ,请稍候......"+ALLTRIM(STR(i))+"/"+ALLTRIM(STR(nFiles_doc))+"----DOC"
Wait Window cWaitmesg
Nowait At srow()/2,(scol()-len(cWaitmesg))/2
docfile=WorkPath+docArray(i,1)
dole=CREATEOBJECT("Word.Application")
doc=dole.Documents.Open(docfile)
FOR EACH tab IN doc.tables
nRow=tab.rows.count
&&总行数
nCol=tab.columns.count
&&总列数
cstr = 'CREATE Table xxx ('+STRTRAN(STRTRAN(tab.Cell(1,1).Range.Text,CHR(7),'') ,CHR(13),'') + ' C(20)'
FOR j=2 TO nCol
cstr=cstr+','+STRTRAN(STRTRAN(tab.Cell(1,j).Range.Text,CHR(7),'') ,CHR(13),'') + ' N(10)'
ENDFOR
cstr = cstr+')'
&cstr
FOR k=2 TO nRow
&&逐行读入临时表
cStr='INSERT INTO xxx VALUES (STRTRAN(STRTRAN(tab.Cell('+ALLTRIM(STR(k))+',1).Range.Text,CHR(7),""),CHR(13),"")'
FOR l=2 TO nCol
cStr=cStr+','+ALLTRIM(STR(VAL(tab.cell(k,l).Range.Text)))
ENDFOR
cstr = cstr+')'
&cstr
ENDFOR
USE IN xxx
SELECT tmp
APPEND FROM xxx
ERASE xxx.dbf
ENDFOR
doc.Close
dole.Quit
ENDFOR
ENDIF
nFiles_xls=Adir(xlsArray,WorkPath+'*.xls')
IF nFiles_xls>0
FOR i=1 TO nFiles_xls
xlsfile=WorkPath+xlsArray(i,1)
eole=CREATEOBJECT("Excel.application")
eole.Workbooks.Open(xlsfile)
cWaitmesg="正在提取数据 ,请稍候......"+ALLTRIM(STR(i))+"/"+ALLTRIM(STR(nFiles_xls))+"----XLS"
Wait Window cWaitmesg
Nowait At srow()/2,(scol()-len(cWaitmesg))/2
nRow=eole.SHEETS(1).UsedRange.Rows.Count
&&有数据的总行数
nCol=eole.SHEETS(1).UsedRange.Columns.Count
&&有数据的总列数
cstr = 'CREATE Table xxx ('+eole.Cells(2,1).text + ' C(20),'
FOR j=2 TO nCol
cstr = cstr+eole.Cells(2,j).text + ' N(10),'
ENDFOR
cstr = left(cstr,LEN(cstr)-1)+")"
&cstr
arr = eole.cells(3,1).resize(nRow-2,nCol).value
&&将数据读入数组
INSERT INTO xxx FROM ARRAY arr
&&& 将数组中的数据,追加到DBF表中
USE IN xxx
SELECT tmp
APPEND FROM xxx
ERASE xxx.dbf
eole.ActiveWorkbook.Close
eole.quit
ENDFOR
ENDIF
ENDIF
WAIT CLEAR
之后再做统计汇总