1. 程式人生 > 實用技巧 >Python Excel 批量付款匯入明細資料分析整理 核銷下載表匯入資料轉換

Python Excel 批量付款匯入明細資料分析整理 核銷下載表匯入資料轉換

批量付款匯入明細資料分析整理 核銷下載表匯入資料轉換


    # 批量付款匯入明細整理
    def payTransform():
        if os.path.exists(".\\1.xls"):
            replace_excel(".", "1.xls")
            os.unlink("1.xls")
        file_path = ".\\1.xlsx"
        total_list = readFromExcel(file_path)
        os.unlink(file_path)
        print("成功讀取{}條資料".format(len(total_list)))

        print("--------批量付款明細格式轉換--------\n")
        # new_list = plProcessDo(total_list)

        print("輸入:1   ----(1.xls)\n     2   ----(1.xlsx)\n")
        type = input("請輸入要轉換的原始表:")
        if type == "1":
            new_list = payTransDo(total_list)
        if type == "2":
            new_list = payTransDo(total_list, 1)

        writeToExcel(".\\payTransOk.xlsx", new_list)

    # 核銷下載表匯入資料轉換
    def jWOTransDo(t, type=0):
        new_list = []
        n = 0
        # 序號    編號  下載憑證號   運單號 發貨人 收貨人 操作時間    核銷單位    核銷專案    來源  類別  方向  交易日期    核銷上級科目  核銷科目    摘要  收入  支出  結餘  分公司 網點  經辦人 收據號碼    支票號碼    發票號碼    手工憑證號   反核銷金額   反核銷經辦人  反核銷日期

        new_list.append(
            ["主鍵", "序號", "編號", "下載憑證號", "運單號", "發貨人", "收貨人", "操作時間", "核銷單位", "核銷專案", "來源", "類別", "方向", "交易日期", "核銷上級科目",
             "核銷科目", "摘要", "收入", "支出", "結餘", "分公司", "網點", "經辦人", "收據號碼", "支票號碼", "發票號碼", "手工憑證號", "反核銷金額", "反核銷經辦人",
             "反核銷日期"])

        if type == 0 and t[0][1] != "稽核人":
            print("表格格式不正確!請查證!只能使用系統匯出的格式!")
            return

        # 去掉表頭
        # t = t[1:]

        # 0 代表
        if type == 0:

            site, companyName = "W-北京興州通", ""

            for i in range(len(t)):
                if not (t[i][3]): continue
                nt = []
                n = n + 1
                # 主鍵 "{20200720}{W-北京興州通}{}核銷下載匯入".format()
                cellDate = t[i][24].strftime('%Y%m%d')
                if t[i][24]:
                    nt.append("{}{}{}核銷下載匯入".format(cellDate, site, companyName))

                # nt.append("") # 主鍵
                nt.append(n)  # 序號
                nt.append(t[i][3])  # 編號
                nt.append(t[i][4])  # 下載憑證號
                nt.append(t[i][29])  # 運單號
                nt.append(t[i][35])  # 發貨人
                nt.append(t[i][36])  # 收貨人
                nt.append(t[i][24])  # 操作時間
                # 收入存在時 核銷單位=發貨人
                if t[i][14]:
                    nt.append(t[i][35])  # 核銷單位
                else:
                    nt.append("")
                nt.append(t[i][30])  # 核銷專案
                nt.append(t[i][5])  # 來源
                nt.append(t[i][6])  # 類別
                nt.append(t[i][7])  # 方向
                nt.append(t[i][8])  # 交易日期
                nt.append(t[i][9])  # 核銷上級科目
                nt.append(t[i][10])  # 核銷科目
                nt.append(t[i][13])  # 摘要
                nt.append(t[i][14])  # 收入
                nt.append(t[i][15])  # 支出
                nt.append(t[i][16])  # 結餘
                nt.append(t[i][17])  # 分公司
                nt.append(t[i][18])  # 網點
                nt.append(t[i][19])  # 經辦人
                nt.append(t[i][20])  # 收據號碼
                nt.append(t[i][21])  # 支票號碼
                nt.append(t[i][22])  # 發票號碼
                nt.append(t[i][23])  # 手工憑證號
                nt.append(t[i][31])  # 反核銷金額
                nt.append(t[i][32])  # 反核銷經辦人
                nt.append(t[i][33])  # 反核銷日期
                new_list.append(nt)

        # 1 代表
        if type == 1:
            for i in range(len(t)):
                if not (t[i][1]): continue
            nt = []
            n = n + 1
            nt.append("")  # 單號
            nt.append(n)  # 序號
            nt.append(t[i][3])  # 運單號
            nt.append(t[i][9])  # 賬款單位
            nt.append("")  # 對賬專案
            nt.append("")  # 客戶專案
            nt.append("")  # 對方單號
            nt.append("收入送貨費")  # 計費專案
            nt.append("")  # 計費單位
            nt.append("")  # 計費單價
            nt.append("")  # 計費數量
            nt.append("")  # 最低收費
            nt.append("")  # 備註
            nt.append("")  # 借方金額
            nt.append(t[i][93])  # 貸方金額 收入
            nt.append("")  # 金額驗證
            nt.append("")  # 對應表金額
            if t[i][8]:
                nt.append(t[i][8])  # 到站
            else:
                nt.append(t[i][7])
            nt.append(t[i][5])  # 日期
            new_list.append(nt)

        return new_list

    # 核銷下載表匯入明細整理
    def journalWriteOff():
        if os.path.exists(".\\1.xls"):
            replace_excel(".", "1.xls")
            os.unlink("1.xls")
        file_path = ".\\1.xlsx"
        total_list = readFromExcel(file_path)
        os.unlink(file_path)
        print("成功讀取{}條資料".format(len(total_list)))

        print("--------核銷下載表明細格式轉換--------\n")

        print("輸入:1   ----(1.xls)\n     2   ----(1.xlsx)\n")
        type = input("請輸入要轉換的原始表:")
        if type == "1":
            new_list = jWOTransDo(total_list)
        if type == "2":
            new_list = jWOTransDo(total_list, 1)

        writeToExcel(".\\jWOTransOk.xlsx", new_list)