96 lines
2.4 KiB
Python
96 lines
2.4 KiB
Python
#!/usr/bin/python3
|
|
# -*- coding: UTF-8 -*-
|
|
from pickle import UNICODE
|
|
import platform
|
|
import json
|
|
import os
|
|
import re
|
|
from threading import local
|
|
from turtle import color
|
|
|
|
if platform.system() == "Windows":
|
|
LINE_END = "\r\n"
|
|
SPLIT_STR = "\\"
|
|
else:
|
|
SPLIT_STR = "/"
|
|
LINE_END = "\n"
|
|
|
|
def read_json_file(path_name):
|
|
f = open(path_name, 'r')
|
|
data = f.read().replace('\xef\xbb\xbf', '')
|
|
f.close()
|
|
try:
|
|
json_data = json.loads(data)
|
|
except Exception as e:
|
|
print ("config.json 格式错误")
|
|
raise e
|
|
return json_data
|
|
|
|
#检测是否是excel文件
|
|
def is_excel_file(name):
|
|
if name[0] == "." or name[0] == "~":
|
|
return False
|
|
if name.endswith('xls') or name.endswith('xlsx'):
|
|
return True
|
|
return False
|
|
|
|
def ignore(folder, root, name, config):
|
|
if not config or not config.get('ignore'):
|
|
return False
|
|
rules = config.get('ignore')
|
|
for i in range(len(rules)-1, -1, -1):
|
|
rule = rules[i]
|
|
ig_flag = True
|
|
if rule.startswith('!'):
|
|
ig_flag = False
|
|
rule = rule[1:]
|
|
if match(folder, root, name, rule):
|
|
return ig_flag
|
|
return False
|
|
|
|
def match(folder, root, name, rule):
|
|
path = os.path.relpath(root, folder)
|
|
file_path = os.path.join(path, name)
|
|
result = re.match(rule, file_path)
|
|
|
|
if result:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def forbid(name, config):
|
|
if config and config.get('forbid_xls', False) and name.endswith('xls'):
|
|
return "禁止XLS文件 %s" % name
|
|
return ""
|
|
|
|
def xlsx_get_function(sheet):
|
|
def gmr():
|
|
return sheet.max_row
|
|
|
|
def gmc():
|
|
return sheet.max_column
|
|
|
|
def access(i, j):
|
|
value = sheet.cell(i+1, j+1).value
|
|
return value
|
|
|
|
def access_color(i, j):
|
|
fill = sheet.cell(i+1, j+1).fill
|
|
# if not fill:
|
|
# return 255, 255, 255
|
|
# x = fill.start_color.index
|
|
# if isinstance(x, (int, long)):
|
|
# return index_to_rgb(x)
|
|
# else:
|
|
# color_int = int(x, 16) & 0x00FFFFFF
|
|
# r, g, b = color_int >> 16, (color_int >> 8) & 0xff, color_int & 0xff
|
|
# return r, g, b
|
|
|
|
def get_rows():
|
|
return sheet.rows
|
|
return gmr, gmc, access, access_color, get_rows
|
|
|
|
def int_to_aa(x):
|
|
if x > 25:
|
|
return int_to_aa(x // 26 - 1) + chr(65 + x % 26)
|
|
return chr(65 + x) |