Python uses the XLRD module to manipulate Excel data import methods

Source: Internet
Author: User
This example describes how Python uses the Xlrd module to manipulate the import of Excel data. Share to everyone for your reference. The specific analysis is as follows:

XLRD is a python-based product that can read Excel files. Compared with Pyexcelerator, the main feature of XLRD is that the reading function is powerful, providing details such as the number of table lines, number of columns, type of cell data, etc. pyexcelrator cannot provide. This makes it possible for developers to understand the exact structure of the form and to perform proper analysis and conversion of the data in the form.

However, XLRD only provides the ability to read Excel files, and cannot generate Excel files like Pyexcelrator.

Python generally uses the XLRD library for the reading of Office software Excel:

1) Open the worksheet:

The code is as follows:

Import xlrd
WB = Xlrd.open_workbook (' Workbook_name ')
WB = Xlrd.open_workbook (file_contents = data)


2) Check the sheet name to get the worksheet:

The code is as follows:

Wb.sheet_names ()
SH = wb.sheet_by_index (0)
SH = wb.sheet_by_name (U ' Sheet1 ')


3) query data:

I. Get the number of rows, columns:

The code is as follows:

rows = Sh.rows
cols = Sh.cols


II. Querying row data:

The code is as follows:

Sh.row_values (row_num)


Iii. Querying column data:

The code is as follows:

Sh.row_values (Col_num)


Iv. Querying cell data:

The code is as follows:

Sh.cel (Row_num, col_num). Value

Hopefully this article will help you with Python programming.

  • Related Article

    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.