rename_testfile.py 2.55 KB
import logging
import pandas as pdas
import os
import chardet

from djcardrenewal.common.dbase.MysqlHelper import MysqlHelper
from djcardrenewal.common.dbase import DbConect
from djcardrenewal.common.sqlcontent import DjSql
from djcardrenewal.common.sqlcontent import CurMonthYzl
from djcardrenewal.common.string.StringBuilder import StringBuilder

print("sys config " + __name__)
log_name = './log/cwrenewal/handlexcelmerge.log'
log_format = '[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]'
log_level = logging.DEBUG
log_mode = 'a'
logging.basicConfig(filename=log_name, format=log_format, level=log_level, filemode=log_mode)

class HandelCwExcelMergeMain:

    handleDescription = ''
    handleMonth = ''
    hmonth = ''

    db = None

    def __init__(self, handle_month):
        logging.info("init construct bean")
        self.handleDescription = "dj renewal match iccid and device location"
        self.handleMonth = handle_month
        self.hmonth = handle_month.replace('-', '')[2:6]
        self.db = MysqlHelper(DbConect.current_month_DB)

    def initCurrentMonthTable(self):
        logging.info("初始化:删除中间表")
        
    # 判断文件编码
    def detect_file_encoding(self, filename):
        with open(filename, 'rb') as f:
            content = f.read()
            result = chardet.detect(content)
            return result['encoding']

    def dealDeviceEndDateList(self):
        return True

    # 定义修改函数
    def modify_data(self, x):
        # 进行批量修改的逻辑
        if x is None:
            return x
        return x.replace("M{", "").replace("}", "")

    # 定义修改函数
    def modify_float_data(self, x):
        # 进行批量修改的逻辑
        if x is None:
            return 0
        current = str(x).replace("`", "").replace(' ', '')
        if current == '':
            return 0
        return current

    def exportDataToExcel(self):
        # 指定目录路径
        directory = 'D:\\work_doc\\003 - 商务脚本\\11111111111111.xlsx'
        df = pdas.read_excel(directory)
        print(df)
        df.iat[3,3] = '深圳广联赛讯'
        df.to_excel('D:\\work_doc\\003 - 商务脚本\\dev_test\\11111111111111.xlsx', index=False)
        


if __name__ == "__main__":
    handle_month = '2023-05'
    dedRes = False
    diRes = False
    urRes = False

    #启动初始化
    handleMain = HandelCwExcelMergeMain(handle_month)
    logging.info("start handle" + handleMain.handleDescription + ' the month:' + handleMain.handleMonth)

    #将结果输出到excel
    handleMain.exportDataToExcel()