f_xls_to_dwcol100.srf 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. $PBExportHeader$f_xls_to_dwcol100.srf
  2. global type f_xls_to_dwcol100 from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_xls_to_dwcol100 (string arg_filepath, datastore ds_col100, ref string arg_msg)
  6. end prototypes
  7. global function integer f_xls_to_dwcol100 (string arg_filepath, datastore ds_col100, ref string arg_msg);Int rslt = 1
  8. Long excelok
  9. oleobject excelserver
  10. excelserver = Create oleobject
  11. IF Not FileExists(arg_filepath) THEN
  12. rslt = 0
  13. arg_msg = '文件' + arg_filepath + '不存在'
  14. GOTO ext
  15. END IF
  16. excelok = excelserver.ConnectToNewObject("excel.application")
  17. IF excelok <> 0 THEN
  18. rslt = 0
  19. arg_msg = "连接EXCEL失败,请检查计算机中是否安装了EXCEL!"
  20. GOTO ext
  21. END IF
  22. if ds_col100.DataObject <> 'dw_col100' then
  23. ds_col100.DataObject = 'dw_col100'
  24. end if
  25. /////////////复制//////////////////// //
  26. excelserver.workbooks.Open(arg_filepath)
  27. //excelserver.activesheet.cells.Copy
  28. //ds_col100.ImportClipboard(1)
  29. //Clipboard("")
  30. Long row = 1, col, ds_row
  31. String strs[]
  32. Boolean emptyrow
  33. DO WHILE True
  34. emptyrow = True
  35. FOR col = 1 To 100
  36. strs[col] = Trim(String(excelserver.activesheet.Cells(row, col).Value),True)
  37. IF IsNull(strs[col]) THEN strs[col] = ''
  38. IF emptyrow And strs[col] <> '' THEN
  39. emptyrow = False
  40. END IF
  41. NEXT
  42. IF emptyrow THEN
  43. EXIT
  44. ELSE
  45. ds_row = ds_col100.InsertRow(0)
  46. FOR col = 1 To 100
  47. rslt = ds_col100.SetItem(ds_row, 'col'+String(col), strs[col])
  48. NEXT
  49. END IF
  50. row++
  51. LOOP
  52. //MessageBox(string(ds_col100.Object.col4[1]), string(ds_col100.Object.col4[2]))
  53. excelserver.quit()
  54. excelserver.DisconnectObject()
  55. ext:
  56. Destroy excelserver
  57. RETURN rslt
  58. end function