python复制粘贴整个excel表到新表里

# 导入包
import xlrd
import xlwt
# 载入需要读取的表
wb = xlrd.open_workbook('D:\业务\副本管家婆凭证源文件.xlsx')
# 设置要读取的sheet
sheet = wb.sheet_by_index(0)
# 新建一个需要写入的表
execl_copy = xlwt.Workbook()
# 给新建的表增加一个sheet(注意这里的sheet名字,不要用中文)
sheet1 = execl_copy.add_sheet('sheet1', cell_overwrite_ok=True)
# 得到原表的总行数
num = sheet.nrows
# 循坏读取原表每一行,并插入到新建的表中
tem = 0
while tem < num:
    row = sheet.row_values(tem)
    for i, content in enumerate(row):
        sheet1.write(tem, i, content)    # 行数,列数,值
    tem = tem + 1
# 保存新建的表
execl_copy.save('sheet.xlsx')

你可能感兴趣的:(python,excel,前端)