PB 读取 Excel

PB 读取 Excel
string ls_fileName
ls_fileName = "c:\x1.xls"

OLEObject ole_excel 
ole_excel = CREATE OLEObject 
IF ole_excel.ConnectToNewObject( "Excel.Application") <> 0 Then 
   MessageBox( " ""Connect Excel error!"
    return
END IF

ole_excel.workbooks.open(ls_fileName,0,FALSE

int li_RowsCount,li_ColumnsCount
string ls_cell
// Get Rows Count
// li_RowsCount = ole_excel.Workbooks[1].Sheets[1].UsedRange.Rows.Count
li_RowsCount=0
DO WHILE TRUE
   ls_cell = string(ole_excel.Workbooks[1].Sheets[1].Cells(li_RowsCount + 1,1).Value)
   IF isnull(ls_cell) THEN
          EXIT
    ELSE
        li_RowsCount++
    END IF
LOOP
// Get Columns Count
// li_ColumnsCount = ole_excel.Workbooks[1].Sheets[1].UsedRange.Columns.Count
li_ColumnsCount=0
DO WHILE TRUE
   ls_cell = string(ole_excel.Workbooks[1].Sheets[1].Cells(1,li_ColumnsCount + 1).Value)
   IF isnull(ls_cell) THEN
          EXIT
    ELSE
        li_ColumnsCount++
    END IF
LOOP
string msg 
msg = "Rows count: " + string(li_RowsCount) + "~r~nColumns count: " + string(li_ColumnsCount)
messagebox("",msg)

// Get Cell Value
ls_cell = string(ole_excel.Workbooks[1].Sheets[1].Cells(2,1).Value)
if isnull(ls_cell) then
    messagebox("Cell Value","Cell is null")
else
    messagebox("Cell Value",ls_cell)
end if

ole_excel.Quit() 
ole_excel.DisConnectObject() 
Destroy ole_excel
PS: 不知道还有多人用PB 呵呵
标签: Powerbuilder

posted on 2011-09-21 11:51 大豆男生 阅读(86) 评论(0) 编辑 收藏

导航

公告


励志照亮人生,创业改变命运!

Blog 访问量,点击这里查看如何添加访问计数器。
昵称:大豆男生
园龄:6年
粉丝:20
关注:3
<2011年9月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

搜索

 

常用链接

最新随笔

我的标签

随笔分类(166)

随笔档案(182)

我的连接

积分与排名

最新评论

阅读排行榜

评论排行榜

推荐排行榜