簡單的合并,本例是橫向合并,縱向合并可以自行調整。
import xlrd import xlwtimport shutil from xlutils.copy import copy import datetime # 打開要使用的excel,獲取要需要寫入的行數 bk = xlrd.open_workbook('A.xlsx') #打開A文件nbk = copy(bk)newsh = nbk.add_sheet('totale') #新建total名字的sheetnsheet = bk.nsheetscur_col = 1#scan all sheet in bkprint(nsheet)for i in range(0, nsheet): sh = bk.sheet_by_index(i) print(sh.name) nrows = sh.nrows ncol = sh.ncols print(sh.nrows) print(sh.ncols) #scan all row in sh for j in range(0, ncol-1): for k in range(0, nrows-1): newsh.write(k,cur_col, label=sh.cell_value(k,j)) cur_col = cur_col + 1nbk.save('A-new.xls') #保存為A-new文件,其中包含了原始內容和新的total頁以上這篇python合并已經存在的sheet數據到新sheet的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答