python + Excel read data (updated)

data.xlsx data are as follows:

 

 


to xlrd Import

. # Excel. 1 reads data
# = Table xlrd.open_workbook ( "data.xlsx", "R & lt")
# Print ( "Get all tags excel:", table.sheets ())
# for Sheet in Table. sheets ():
# Print (Sheet)

. # 2 reads the first tag the second tag ....
# = Table xlrd.open_workbook ( "data.xlsx", "R & lt")
# = sheetname table.sheet_by_name ( "Sheet1")
# Print ( "sheetname:", sheetname)
# = sheetname1 table.sheet_by_index (0)
# Print ( "sheetname1:", sheetname1)

. #. 3 reads the number of rows and columns of data designated nrows rows excel ncols columns
# = Table xlrd.open_workbook ( "data.xlsx", "R & lt")
# = Sheet1 table.sheet_by_index (0)
# Print ( "Sheet1 below the line data {}" .format (sheet1.nrows))
# print ( "Sheet1 below {} .format (sheet1.ncols)) column data "

# 4. Acquire the specified number of rows and number of columns row_values rows columns col_values
Table xlrd.open_workbook = # ( "data.xlsx", "R & lt")
# = Sheet1 table.sheet_by_index (0)
# = onesheetrow sheet1.row_values (0)
# Print ( "first line of data:", onesheetrow) # first line of data: [ 'username', 'password', 'expected results']
# = onesheetcol sheet1.col_values (0)
# Print ( "first column data:", onesheetcol)
data of the first column # : [ 'username', 18,797,813,131.0, 18,797,813,121.0, 18,797,813,122.0, 18,797,813,123.0, 18,797,813,124.0]

. # 5 acquires data cell specified row and a specified column
# = Table xlrd.open_workbook ( "data.xlsx", "R & lt")
# = Table Sheet1 .sheet_by_index (0)
# row_col sheet1.cell = (0,0)
# Print ( "the first row and first column of data:", row_col)
# row_col1 sheet1.cell = (2,1)
# Print ( "first the first two rows and columns of data: ", row_col1)

#. 6.Get excel username and password
# table = xlrd.open_workbook ( "data.xlsx" , "r")
Table.sheet_by_index Sheet1 = # (0)
# = sheet1.nrows rows
# for I in Range (. 1, rows): 1,2,3,4,5 #
# Print ( "Current user name:", sheet1. row_values (i) [0],
# "password:", sheet1.row_values (i) [1],
# "to obtain the login information is:", sheet1.row_values (i) [2])


. write a # 7 method, the number of input lines, the line returns all data
# DEF read_user (nrow = 0):
# "" "reads the user name" ""
# = Table xlrd.open_workbook ( "data.xlsx", "R & lt")
# = table.sheet_by_index Sheet1 (0)
# return sheet1.row_values (nrow) [0]
#
# DEF read_passwd (nrow):
# "" "reads the password" ""
# = Table xlrd.open_workbook ( "data.xlsx", "R & lt")
# = Sheet1 Table.sheet_by_index(0)
# return sheet1.row_values(nrow)[1]
#
# # Print (read_user (. 1), read_passwd (. 1))
#
# ROW_NUMBER = int (INPUT ( "Please enter the number of rows"))
# Print ( "first {} data row is: {}". Format (row_number , read_user (ROW_NUMBER)))

#. 8 read data stored in the List.
DEF readExcels ():
Tables xlrd.open_workbook = ( "data.xlsx", "R & lt")
Sheet = tables.sheet_by_index (0)
nrow = [ ] # empty list is defined
for Row in Range (. 1, sheet.nrows):
nrow.append (sheet.row_values (Row, start_colx = 0, = end_colx sheet.ncols))
return nrow
Print (readExcels ())


Guess you like

Origin www.cnblogs.com/Teachertao/p/11707565.html