日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python合并幾個表格的方法

python合并單元格代碼如下:

安居網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站設(shè)計等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)公司成立與2013年到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)公司。

import xlrd
import xlsxwriter
import glob

biao_tou = "NULL"
wei_zhi = "NULL"

#獲取要合并的所有exce表格
def get_exce():
    global wei_zhi
    wei_zhi = input("請輸入Exce文件所在的目錄:")
    all_exce = glob.glob(wei_zhi + "*.xlsx")
    print("該目錄下有" + str(len(all_exce)) + "個exce文件:")
    if(len(all_exce) == 0):
        return 0
    else:
         for i in range(len(all_exce)):
             print(all_exce[i])
         return all_exce					
        


#打開Exce文件
def open_exce(name):
    fh = xlrd.open_workbook(name)
    return fh

#獲取exce文件下的所有sheet
def get_sheet(fh):
    sheets = fh.sheets()
    return sheets


#獲取sheet下有多少行數(shù)據(jù)
def get_sheetrow_num(sheet):
    return sheet.nrows
    


#獲取sheet下的數(shù)據(jù)
def get_sheet_data(sheet,row):
    for i in range(row):
        if (i == 0):
            global biao_tou
            biao_tou = sheet.row_values(i)
            continue
        values = sheet.row_values(i)
        all_data1.append(values)
        
    return all_data1
    

if __name__=='__main__':
    all_exce = get_exce()
    #得到要合并的所有exce表格數(shù)據(jù)
    if(all_exce == 0):
        print("該目錄下無.xlsx文件!請檢查您輸入的目錄是否有誤!")
        os.system('pause')
        exit()

    all_data1 = []
    #用于保存合并的所有行的數(shù)據(jù)


    #下面開始文件數(shù)據(jù)的獲取
    for exce in all_exce:
        fh = open_exce(exce)
        #打開文件
        sheets = get_sheet(fh)
        #獲取文件下的sheet數(shù)量


        for sheet in range(len(sheets)):
            row = get_sheetrow_num(sheets[sheet])
            #獲取一個sheet下的所有的數(shù)據(jù)的行數(shù)

            all_data2 = get_sheet_data(sheets[sheet],row)
            #獲取一個sheet下的所有行的數(shù)據(jù)

    all_data2.insert(0,biao_tou)
    #表頭寫入

    


    #下面開始文件數(shù)據(jù)的寫入
    new_exce = wei_zhi + "test.xlsx"
    #新建的exce文件名字

    
    fh1 = xlsxwriter.Workbook(new_exce)
    #新建一個exce表

    new_sheet = fh1.add_worksheet()
    #新建一個sheet表

    for i in range(len(all_data2)):
        for j in range(len(all_data2[i])):
            c = all_data2[i][j]
            new_sheet.write(i,j,c)
            
    fh1.close()
    #關(guān)閉該exce表
    
    print("文件合并成功,請查看“" + wei_zhi + "”目錄下的test.xlsx文件!")
            
    os.system('pause')
    os.system('pause')

程序使用說明:

(1) 運行”Exce表格合并.exe”文件

(2) 輸入要合并的所有.xlsx表格文件所在的盤目錄**(注意不要輸錯目錄,輸錯目錄或者亂輸入則直接強制退出)**

(3) 輸入完按回車后程序自動執(zhí)行,生成test.xlsx文件

注意:如果原來就存在test.xlsx文件,必須先刪除,不然合并后的數(shù)據(jù)會保存在原來的test.xlsx文件,并且程序會一閃而過


網(wǎng)站欄目:創(chuàng)新互聯(lián)Python教程:python合并幾個表格的方法
路徑分享:http://m.5511xx.com/article/dhgihij.html