rename_testfile.py
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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()