/*-----------------------------------------------------------------*/
函数名称:of_importdata(datawindow adw,long al_start,long al_columns)
===参数: value DATAWINDOW adw [装导入的数据]
value Long al_Start [起始行]
ref Long al_Columns [Excel表的可用列]
===返回值: Long ll_Row
-10 ~ 0 从TEXT导入到adw的出错信息
-200 OLE初始化失败
1及以上 成功导入到数据窗口的行数
===功能: 将EXCEL的数据导入到adw中.
/*--------------BY HDC ---20070412----------------------------------*/
Long ll_Row
Long ll_Start
Long ll_Columns
String ls_Error
String ls_FilePath
String ls_TxtFile
String ls_FileName
String ls_Filter
oleobject lole_ole
SetPointer(HourGlass!)
ls_Filter = "Microsoft Excel Files (*.xls),*.xls,逗号分隔的Microsoft Excel Files (*.csv),*.csv,"
ls_Filter += "制表符分隔的text文本(*.txt),*.txt,dBaseII或dBaseIII文件(*.dbf),*.dbf"
If GetFileOpenName("请选择文件",ls_FilePath,ls_FileName,"txt",ls_Filter) = 1 Then
Else
This.of_Set_ErrorDesc("用户取消操作")
Return -100
End If
SetPointer(HourGlass!)
ll_Start = al_Start
If IsNull(ll_Start) Or ll_Start = 0 Then
ll_Start = 1
End If
//adw.Reset()
Choose Case lower(right(ls_FilePath,3))
Case 'xls','csv'
lole_OLE = Create OLEObject
ll_Row = lole_OLE.ConnectToNewObject("Excel.Application") //ls_FilePath)
If ll_Row = 0 Then
ls_TxtFile = left(ls_FilePath,len(ls_FilePath) - 4) + '.txt'
lole_OLE.application.WorkBooks.Open(ls_FilePath)
lole_OLE.application.workbooks(1).saveas(ls_TxtFile,3)
lole_OLE.application.workbooks(1).Saved = True
ll_Columns = lole_OLE.application.workbooks(1).worksheets[1].UsedRange.columns.Count
MESSAGEBOX('',String(ll_Columns))
lole_OLE.application.WorkBooks.close//关闭文件和应用
lole_OLE.DisconnectObject()//断开连接
ll_Row = adw.importfile(ls_TxtFile,ll_Start)
ELSE
ll_Row = -200
End If
If IsValid(lole_OLE) Then Destroy lole_OLE
of_Delete_File(ls_TxtFile) '删除.TXT文件
Case 'txt'
ll_Row = adw.ImportFile(ls_FilePath,ll_Start)
Case 'dbf'
ll_Row = adw.ImportFile(ls_FilePath)
End Choose
is_TempFileName = ls_TxtFile
Choose Case ll_Row
Case 0
ls_Error = 'End of file; too many rows'
Case -1
ls_Error = 'No rows'
Case -2
ls_Error = 'Empty file'
Case -3
ls_Error = 'Invalid argument'
Case -4
ls_Error = 'Invalid input'
Case -5
ls_Error = 'Could not open the file'
Case -6
ls_Error = 'Could not close the file'
Case -7
ls_Error = 'Error reading the text'
Case -8
ls_Error = 'Not a TXT file'
Case -9
ls_Error = 'The user canceled the import'
Case -10
ls_Error = 'Unsupported dBase file format (not version 2 or 3)'
CASE -200
ls_Error = '连接EXCEL失败,请检查计算机中是否安装了EXCEL!'
End Choose
If ll_Row <= 0 Then
This.of_Set_ErrorDesc(ls_Error) '保留信息
Else
This.of_Set_ErrorDesc("成功导入数据" + String(ll_Row) + "条!")
End If
al_Columns = ll_Columns
Return ll_Row