How to import Excel data using the xlrd module in Python

Source: Internet
Author: User

How to import Excel data using the xlrd module in Python

This document describes how to use the xlrd module to import Excel Data in Python. Share it with you for your reference. The specific analysis is as follows:

Xlrd is a python-based product that can read excel files. Compared with pyExcelerator, xlrd has powerful reading functions and provides detailed information that cannot be provided by pyExcelrator, such as the number of rows, number of columns, and cell data type, this allows developers to analyze and convert the data in the form without having to understand the specific structure of 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 reading 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 worksheet name and obtain 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. query cell data:

The Code is as follows:

Sh. cel (row_num, col_num). value

I hope this article will help you with Python programming.

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.