import openpyxl
import xlrd
file_path = 'a.xlsx'
def read_write(row_count):
work_book = openpyxl.load_workbook(file_path)
work_sheet = work_book['test']
for rows_index in range(row_count):
cell_obj = work_sheet.cell(row=rows_index+1, column=1)
if cell_obj.value.startswith("137"):
work_sheet.cell(row=rows_index+1, column=10).value = '移动'
else:
work_sheet.cell(row=rows_index+1, column=10).value = '其他'
work_book.save(file_path)
work_book.close()
print 'success'
def get_row_count():
work_book = xlrd.open_workbook(file_path)
work_sheet = work_book.sheets()[0]
row_count = work_sheet.nrows
return row_count
def get_column_count():
work_book = xlrd.open_workbook(file_path)
work_sheet = work_book.sheets()[0]
col_count = work_sheet.ncols
return col_count
if __name__ == "__main__":
row_count = get_row_count()
read_write(row_count)