First, a brief introduction to the difference between a workbook and a worksheet:
In EXECL, the English of the workbook is BOOK (WORKBOOK), and the English of the worksheet is SHEET (WORKSHEET).
- A workbook is a separate file
- A workbook can contain one or more worksheets
- A workbook is a collection of worksheets
1: To use python to read and write Excel files, you first need to install a special module (if you are a big cow, you can write it yourself) xlrd module
Use the xlrd module to simply read sheet, row, and column data in excel.
sheets()[i],row_values(i),col_values(i)
2: Read excel data
import xlrd #Open execl data = xlrd.open_workbook( ' E :/input.xlsx ' ) #Open xls file #Read the first sheet sheet = data.sheets()[0] #Get the first row of data rows = sheet .row_values(0) #Get the first column of data columns= sheet.col_values(0) print (rows) print (columns)
Note: sheet number, row number, column number all start from index 0