ole_in = Create oleobject
If ole_in.ConnectToNewObject("excel.application") <> 0 Then
Messagebox('连接出错','连接EXCEL出错')
Return
End If
If GetFileOpenName("请选择要导入的文件:",ls_path, ls_name, "XLS","EXCEL文档(*.xls),*.XLS") <> 1 THEN
Messagebox('打开文件','打开文件出错')
Return
End If
String m_id[], m_desc[],m_spec[],u_stock[]
String col_name, aa
any qty[]
Int ii,li_row
li_row = 1
ole_in.visible = False
ole_in.Workbooks.Open (ls_path)
dw_1.Reset()
dw_1.AcceptText()
Do While True
For ii = 1 To 5
col_name = char(64+ii)
ole_in.Range(col_name + string(li_row)).Select //选中当前单元格
Choose Case ii
Case 1
m_id[li_row] = ole_in.ActiveCell.FormulaR1C1
Case 2
m_desc[li_row] = ole_in.ActiveCell.FormulaR1C1
Case 3
m_spec[li_row] = ole_in.ActiveCell.FormulaR1C1
Case 4
u_stock[li_row] = ole_in.ActiveCell.FormulaR1C1
Case 5
qty[li_row] = ole_in.ActiveCell.FormulaR1C1
End Choose
Next
If Len(Trim(m_id[li_row])) = 0 Then
Exit
End If
dw_1.ScrollToRow(dw_1.insertrow(0))
dw_1.setitem(dw_1.GetRow(),'m_id',m_id[li_row])
dw_1.setitem(dw_1.GetRow(),'m_desc',m_desc[li_row])
dw_1.setitem(dw_1.GetRow(),'m_spec',m_spec[li_row])
//dw_1.setitem(dw_1.GetRow(),'u_stock',u_stock[li_row])
//dw_1.setitem(dw_1.GetRow(),'qty',qty[li_row])
li_row ++
Loop
Messagebox('提示','导入成功,请保存!')
//ole_in.Workbooks.close()
Ole_in.DisconnectObject()
Destroy ole_in
//检查返回值,以确保已成功地连接到了Excel
if excelok <> 0 then
messagebox("信息提示","连接EXCEL失败,请检查计算机中是否安装了EXCEL!")
return -1
end if
li_net = GetFileOpenName("选择文件", str_savename,named,"xls","Excel文件(*.xls),*.xls")
if li_net > 0 then
if str_savename = "" then return -1
dw.settransobject(sqlca)
dw.reset()
excelserver.workbooks.open(str_savename)
excelserver.activesheet.cells.copy
li_count = dw.importclipboard(2) //导入数据
clipboard("")
excelserver.quit()
excelserver.disconnectobject()
destroy excelserver
return 1
else
messagebox('信息提示','没有指定导入文件!')
return -1
end if