1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| import xlrd from xlutils.copy import copy import os
file_path = r'./path/to/excel.xlsx'
file_path = file_path.decode('utf-8')
data = xlrd.open_workbook(file_path)
table = data.sheet_by_index(0)
nrows = table.nrows print("row num: ", nrows)
ncols = table.ncols print("col num: ",ncols)
print(table.row_values(1))
print(table.col_values(1)) print(table.col_values(0))
cell_value = table.cell(1,1).value print(cell_value)
book = xlrd.open_workbook(file_path)
new_book = copy(book)
sheet = new_book.get_sheet(0)
sheet.write(6, 0, 'Dandan Sun')
new_book.save('stu_new.xls')
os.remove('stu.xls') os.rename('stu_new.xls','stu.xls')
|