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.