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.