1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- $PBExportHeader$f_xls_to_dwcol100.srf
- global type f_xls_to_dwcol100 from function_object
- end type
- forward prototypes
- global function integer f_xls_to_dwcol100 (string arg_filepath, datastore ds_col100, ref string arg_msg)
- end prototypes
- global function integer f_xls_to_dwcol100 (string arg_filepath, datastore ds_col100, ref string arg_msg);Int rslt = 1
- Long excelok
- oleobject excelserver
- excelserver = Create oleobject
- IF Not FileExists(arg_filepath) THEN
- rslt = 0
- arg_msg = '文件' + arg_filepath + '不存在'
- GOTO ext
- END IF
- excelok = excelserver.ConnectToNewObject("excel.application")
- IF excelok <> 0 THEN
- rslt = 0
- arg_msg = "连接EXCEL失败,请检查计算机中是否安装了EXCEL!"
- GOTO ext
- END IF
- if ds_col100.DataObject <> 'dw_col100' then
- ds_col100.DataObject = 'dw_col100'
- end if
- /////////////复制//////////////////// //
- excelserver.workbooks.Open(arg_filepath)
- //excelserver.activesheet.cells.Copy
- //ds_col100.ImportClipboard(1)
- //Clipboard("")
- Long row = 1, col, ds_row
- String strs[]
- Boolean emptyrow
- DO WHILE True
- emptyrow = True
- FOR col = 1 To 100
- strs[col] = Trim(String(excelserver.activesheet.Cells(row, col).Value),True)
- IF IsNull(strs[col]) THEN strs[col] = ''
- IF emptyrow And strs[col] <> '' THEN
- emptyrow = False
- END IF
- NEXT
- IF emptyrow THEN
- EXIT
- ELSE
- ds_row = ds_col100.InsertRow(0)
- FOR col = 1 To 100
- rslt = ds_col100.SetItem(ds_row, 'col'+String(col), strs[col])
- NEXT
- END IF
- row++
- LOOP
- //MessageBox(string(ds_col100.Object.col4[1]), string(ds_col100.Object.col4[2]))
- excelserver.quit()
- excelserver.DisconnectObject()
- ext:
- Destroy excelserver
- RETURN rslt
- end function
|