Python uses the XLRD module to manipulate the way Excel data is imported

Source: Internet
Author: User

This example describes how Python uses the Xlrd module to manipulate Excel data imports. 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 function of reading is more powerful, and provides details that Pyexcelrator cannot provide, such as the number of rows, columns, cell data types, etc. This enables developers to correctly analyze the data in a form without having to understand the form's structure.

But XLRD only provides the ability to read Excel files, and cannot build Excel files like Pyexcelrator.

Python reads Office software excel in general using XLRD libraries:

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 worksheet name and 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, number of columns:

The code is as follows:

rows = Sh.rows

cols = Sh.cols

II. Query row data:

The code is as follows:

Sh.row_values (row_num)

Iii. Query 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

I hope this article will help you with your 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.