欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python读取excel多个sheet页并合并成一页

程序员文章站 2022-07-13 15:20:52
...

python读取excel多个sheet页并合并成一页

import xlrd
import xlwt

data = xlrd.open_workbook("database.xlsx")

workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('sheets2one')
'''sheet页'''

page0 = len(data.sheets())	#读取表格中的页数

print(f'该表格文件有 {page0} 页')
aim_hang = 0

for ye in range(page0):
    table0 = data.sheets()[ye]
    nrow0 = table0.nrows     #行
    nclow0 = table0.ncols    #列
    print(nclow0)
    print(nrow0)
    for hang in range(nrow0):
        for lie in range(nclow0):
            aim_data = int(table0.cell_value(hang, lie))
            worksheet.write(aim_hang , lie , str(aim_data))
            print(aim_data)
        aim_hang = aim_hang + 1

    aim_hang = aim_hang + 2

workbook.save('Excel_test.xls')