医药CRM系统开发

自已做医药CRM系统有四年了,终于可以算个产品了,努力市场化,今年重种将医药营销的理念加入CRM

导航

pb导入excel文件

Posted on 2013-05-11 19:02  hhq80  阅读(3190)  评论(1编辑  收藏  举报

// Description:两种方法进行
//1、通过数组一行一行读入(定义数据有点麻烦)
//2、通过剪贴板直接

//====================================================================
String ls_path,ls_name
ls_path = "C:\Documents and Settings\Administrator.FLYSTONE\桌面\新建文件夹 (3)\test.xls"
dw_1.Reset() //clean DW
String a[1000,1000]
Integer i,j,li_ret

//li_ret = GetFileopenName('选择XLS',ls_path,ls_name,"XLS","EXCEL (*.XLS),*.XLS")
li_ret =GetFileopenName('请选择EXCEL文件',ls_path,ls_name,"XLS","EXCEL (*.XLS;*.XLSX),*.XLS;*.XLSX")
if li_ret <> 1 then return

OLEObject ExcelServer
Int li_ConnectErr
ExcelServer = Create OLEObject
li_ConnectErr = ExcelServer.ConnectToNewObject( "excel.application" )
If li_ConnectErr < 0 Then
Choose Case li_ConnectErr
       Case -1
         MessageBox('错误提示','无效的调用')
       Case -2
         MessageBox('错误提示','类名没发现')
       Case -3
         MessageBox('错误提示','对象不能创建')
       Case -4
         MessageBox('错误提示','文件不能连接')
       Case -5
         MessageBox('错误提示','不能连接现在的对象')
       Case -6
         MessageBox('错误提示','文件无效')
       Case -7
         MessageBox("错误提示","文件不存在或已经打开")
       Case -8
         MessageBox("错误提示","服务器不能装载选择的文件")
       Case -9
         MessageBox("错误提示","其他错误")
End Choose
Return
End If

ExcelServer.Workbooks.Open(ls_path,0,False)
//对XLS文件进行了改动以后,在关闭该文件时是否需要向用户提出警告:剪贴板提示信息。
ExcelServer.Application.DisplayAlerts = False
//选择sheets表
//ExcelServer.activeworkbook.worksheets("sheet2").Select() 
//方法一:
Int li_rows,li_columns
li_rows = ExcelServer.ActiveSheet.UsedRange.Rows.Count //取得总行数
li_columns= ExcelServer.ActiveSheet.UsedRange.columns.Count //取得总行数
// # of columns in excel
//sle_2.Text = TRIM(STRING(li_rows))
// # of rows in excel
//sle_1.Text = STRING(li_columns)
//lole_sheet = ole_1.Application.ActiveWorkbook.WorkSheets[1] //得到第当前work的第一个sheet
datetime ld_rq
string ls_jybz,ls_dkr,ls_dkbz,ls_billType
dec ld_je
long li_row

for i = 2 to li_rows  
  ld_rq= datetime(date(ExcelServer.ActiveSheet.Cells(i,1).value),time('00:00:00'))
  ls_jybz =  string(ExcelServer.ActiveSheet.Cells(i,2).value)
  ld_je = dec(ExcelServer.ActiveSheet.Cells(i,3).value)
  ls_dkr = string(ExcelServer.ActiveSheet.Cells(i,4).value)
  ls_billType =  string(ExcelServer.ActiveSheet.Cells(i,5).value)
  
  li_row = dw_1.insertrow(0)
  
  dw_1.setitem(li_row, 'rq',ld_rq)
  dw_1.setitem(li_row, 'jybz',ls_jybz)
  dw_1.setitem(li_row, 'je',ld_je)
  dw_1.setitem(li_row, 'dkr',ls_dkr)
  dw_1.setitem(li_row, 'dkbz',ls_dkbz)
  dw_1.setitem(li_row, 'BillType',ls_billType)
next