# 对表格内容进行赋值 for x,y in [(x,y) for x in range(0,9) for y in range (0, 9)]: table.cell(x,y).text = str(x * y) table.cell(x,y).paragraphs[0].paragraph_format.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER # 设置 cell 的宽度 table.cell(x,y).width = 25600 * 30
# 获取表格的数据 [0, rows] x [0, cols] defget_table_data(excel_name, sheet_name, rows, cols): result = []
book = xlrd.open_workbook(excel_name) sheet = book.sheet_by_name(sheet_name) for row in range (0, rows): line = [] for col in range (0, cols): line.append(sheet.cell_value(row, col)) result.append(line)