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.