今天是公元: 20250606日 星期   农历: 乙巳十一 2加入收藏 | 设为首页 | 会员中心
您当前的位置:首页 > 科文与生活 > PB数据编程

PowerBuilder 读取 Excel文件

日期:2025-06-03   来源:本站整理   点击:8

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

上一篇: pb全面控制excel命令含义及使用方法
下一篇: pb 通过ole操作excel常用函数
相关文章
热门文章
  1. 好正好软件-成绩管理分析 使用手册 简介
  2. 成绩管理分析-使用手册 成绩录入与汇总处
  3. 好正好软件-课程表管理 使用手册 简介
  4. PowerBuilder中操作Excel的技巧集
  5. 成绩管理分析-使用手册 成绩动态对比分析
  6. 成绩管理分析-使用手册 排考试号
  7. 成绩管理分析-使用手册 基本设置
  8. 成绩管理分析-使用手册 成绩综合分析
  9. PowerBuilder 编程技巧一
  10. PowerBuilder操作Excel技巧摘要
   关于我们
服务联系
新闻公告
好正好教育
好正好软件(教育管理)
Copyright (c) 2024 好正好教育