Python reads the number of lines in Excel

Source: Internet
Author: User

Based on the python3.x

Need a Package

From OPENPYXL import Load_workbook

The code is as follows:

1 From OPENPYXL import Load_workbook2 wb = Load_workbook (filename=r ' c:\\users\\administrator\\desktop\\ Inventory big Table 0803.xlsx ') # #读取路径3 ws = Wb.get_sheet_by_name ("Sheet1") # #读取名字为Sheet1的sheet表4 num = 15 6 While 1:7 cell = Ws.cell (Row=num, column=1). Value8 If cell:9 num = num +1Ten Else: One print (num) AExit ()

Where a dead loop is set

While 1:

The contents of the cell are always read:

Cell = Ws.cell (Row=num, column=1). Value

If the cell is not empty

If cell:    num = num +1

Continue reading the next line

If it appears empty, then print the value of NUM, which is the number of lines, and then jump out of the program

else:    print (num)    exit ()

Python reads the number of lines in Excel

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.