PB reading Excel

Source: Internet
Author: User
Tags rows count
PB reading Excel

String ls_filename
Ls_filename = " C: \ x1.xls "

Oleobject ole_excel
Ole_excel = create oleobject
IfOle_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. countli_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. countli_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)
IfIsnull (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: I don't know how many people use petabytes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.