Python read Excel file

Source: Internet
Author: User

1 #-*-coding:utf-8-*-2 """3 Created on Thu 13:53:10 20184 5 @author: Frank6 """7 8 Importxlrd #XLRD is a library for reading data and formatting information from Excel files, whether they is. xls or. xlsx files. 9 Tendata = Xlrd.open_workbook ('Address Book. xlsx') #打开 Excel file One Print(Type (data)) ATable =data.sheets () [0] - Print(Type (table)) -nrows = Table.nrows#Number of rows the Print("number of rows: {}". Format (nrows)) -Ncols = Table.ncols#Number of columns - Print("Number of columns: {}". Format (ncols)) -  forIinchRange (0,nrows): +Rowvalues = Table.row_values (i)#a row of data -     #print (Type (rowvalues)) +     #print (rowvalues) A     Print("name:{}<--> phone: {}". Format (Rowvalues[0], rowvalues[1]))

xlrd.open_workbook(filename=none, logfile=<_io. Textiowrapper name= ' <stdout> ' mode= ' W ' encoding= ' UTF-8 ' >, verbosity=0, use_mmap=1, file_contents=none, encoding_override=none, formatting_info=false, on_demand= False, ragged_rows=false)

Open an Excel file.

Here is a simple introduction to the basic parameters, later useful to add.

Parameters:

  filename , haven path to the spreadsheet file to is opened.

Specify the path to open the file

  logfile –an Open file to which messages and diagnostics is written

Returns:

An instance of the Book class.

Book.sheets ()

RETURN:A List of all sheets in the book. Returns all the tables in Excel and saves them in the list.

All sheets not already loaded would be loaded.

xlrd.sheet. class Sheet (book, position, name, number)

Contains the data for one worksheet.

In the cell access functions, was rowx a row index, counting from zero, and was colx a column index, counting from zero. N Egative values for Row/column indexes and slice positions is supported in the expected fashion.

Note:you don ' t instantiate this class yourself. You access Sheet objects via the object that is returned when you Book called xlrd.open_workbook() .

nrows= 0

Number of rows in sheet. A row index is in range(thesheet.nrows) .

ncols= 0

Nominal number of columns in sheet. It's one more than the Maximum column index found, ignoring trailing empty cells. See also the ragged_rows parameter to open_workbook() and row_len() .

row_values(rowx, start_colx=0, end_colx=none)

Returns a slice of the values of the cells in the given row. The function returns a list that contains all the contents of cells in this row by default.

Python read Excel file

Related Article

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.