import osimport xlrdfrom xlutils.copy import copydef base_dir(filename=None): return os.path.join(os.path.dirname(__file__),filename)"""對excel進行操做"""work = xlrd.open_workbook(base_dir("excel.xls"))# 索引到第X個工做表sheet = work.sheet_by_index(0)#查看有多少行print(sheet.nrows)#查看有多少列print(sheet.ncols)#獲取單元格內容print(sheet.cell_value(5,2))"""對excel進行修改/添加內容"""# 找到須要更該的xlswork = xlrd.open_workbook(base_dir("excel.xls"))print(work)# 對數據表格進行復制old_content = copy(work)# 定位到Sheet1表ws = old_content.get_sheet(0)#在sheet1表中寫入內容ws.write(7,2,"Tao")#對修改後的內容進行保存old_content.save(base_dir("data.xls"))