Python inside the Xlrd module detailed (a)

Source: Internet
Author: User

Then I'll take a look at the area. Learn about the XLRD module:

1. What is the XLRD module?

2. Why use the XLRD module?

3. How do I use the XLRD module?

1. What is the XLRD module?

The Python operation Excel mainly uses the XLRD and XLWT the two libraries, namely XLRD is the read EXCEL,XLWT is writes the Excel library.

Let's start today. XLRD module:

First, install the XLRD module

? Download the HTTP://PYPI.PYTHON.ORG/PYPI/XLRD module installation to the Python website, provided the Python environment is already installed.

? or in the CMD window pip install xlrd

Second, the use of the introduction

1. Data types in commonly used cells

? 0. Empty (empty), 1 string (text), 2 number, 3 date, 4 Boolean, 5 error, 6 blank (blank table)

2. Import Module

Import xlrd

3. Open Excel file to read data

data = Xlrd.open_workbook (filename)# file name and path, if the path or file name has Chinese to the front plus an R apprentice native character. 

 4. Commonly used functions

? The most important method in Excel is the operation of book and sheet

1) Get a worksheet in book

Table = data.sheets () [0]          # get  # by index order get  = Data.sheet _by_name (sheet_name  )# obtained by name = Data.sheet_names ()    #  Returns the name  of all worksheets in book or indx)   #  Check if a sheet is finished importing

Such as:

2) operation of the line

 nrows = table.nrows #   Gets the number of valid rows in the sheet  table.row (ROWX)  Span style= "COLOR: #008000" >#   table.row_slice (ROWX)  #      table.row_types (rowx, Start_colx  =0, End_colx=none) #     table.row_values (rowx, Start_colx  =0, End_colx=none) #   table.row_len (ROWX)  #    

3) operation of the column (Colnum)

Ncols = Table.ncols   # Gets the number of valid columns for the list table.col (Colx, start_rowx=0, end_rowx=none)   # Returns a list of all the cell objects in the column table.col_slice (Colx, start_rowx=0, End_rowx=none)  # returns a list of all the cell objects in the column table.col_types (Colx, start_rowx=0, End_rowx=none)    # returns a list of data types for all cells in the column table.col_values (Colx, start_rowx=0, End_rowx=none)   # returns a list of the data that is made up of all the cells in the column

Such as:

4) operation of the cell

Table.cell (ROWX,COLX)   # Returns the Cell object table.cell_type (ROWX,COLX)    #  Returns the data type in the cell table.cell_value (ROWX,COLX)   # Returns the data in the cell Table.cell_ Xf_index (ROWX, Colx)   #  I don't know for a moment

Cell: A cell is a cross-section of a row and column in a table, which is the smallest unit that makes up a table and can be split or merged. The input and modification of a single data is done in a cell

Such as:

Note: Note the scope issue, after obtaining the sheet, after getting to this sheet value, in the row and column as well as the operation of the cell.

2. Why use the XLRD module?

? Data maintenance is a core in UI Automation or interface automation, so this module is very useful.

3. How do I use the XLRD module?

I'll tidy up the second buchbinderei alone.

 

Python inside the Xlrd module detailed (a)

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.