import re
import lxml
import xlrd
import xlrd # Import and stock in
import xlwt
path=r' route '
wb=xlrd.open_workbook(path) # Open the file and return a working object .open_workbook You can click in to see the meaning of the parameters in the function , Very detailed , Poor English can be translated by Baidu , The translation results are similar .
writrfile=xlwt.Workbook(encoding='utf-8',)
sheet_num=wb.nsheets # obtain excel Inside sheet The number of
table = wb.sheets()[0] # By index order
sheet_names=wb.sheet_names() # Get Excel Everything in it sheet List of names for , Even without sheet Can also be used .
sheet=wb.sheet_by_index(0) # Get a by index sheet, Now is the first to get sheet page , It can also be done through sheet Get the name of ,sheet_by_name('sheet name ')
rows=sheet.nrows # obtain sheet The number of rows on the page , There are a few lines
columns=sheet.ncols # obtain sheet Number of columns per page , There are several columns
# Get the data of the first row
row_data=sheet.row_values(0) # Returns the cell data of a given number of rows for slicing
# Get the data of the second column
col_data=sheet.col_values(1)
# Get cell data
# one_data=sheet.cell(row_index,col_index) # The same is done by indexing ,cell(0,1) Get the cell data of the first row and the second column
# cell_value=one_data.value # Get cell value
# cell_type=one_data.ctype # Gets the type of the cell , stay xlrd in , The data types of cells are 6 Kind of ,
# 0 -- empty (empty)
# 1 -- character string (string)
# 2 -- Numbers (number)
# 3 -- date( date )
# 4 -- boolean( Boolean value )
# 5 -- error( error )
print(sheet_num)
print(table)
print(sheet_names)
print(sheet)
print(rows)
print(columns)
print(row_data)
print(col_data)
print(sheet.cell(1,0))
tool=sheet.cell(1,0).value
tool=" Alipay "
sheet.cell(1,0).value=tool
print(tool)
sheet1=writrfile.add_sheet('sheet1',cell_overwrite_ok=True)