54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
import os
|
|
import time
|
|
|
|
import pandas as pd
|
|
"""
|
|
读取文件列表,
|
|
判断是否为数据表,
|
|
生成‘数据表清单***文件’
|
|
|
|
# (py3) zhc@mail:~/kboss_dev/models$ xls2ddl mysql . > mysql.ddl.sql
|
|
|
|
"""
|
|
|
|
|
|
def read_file_list(path):
|
|
file_list = []
|
|
for root, dirs, files in os.walk(path):
|
|
for file in files:
|
|
print(file)
|
|
suffix = os.path.splitext(file)[1]
|
|
if suffix != '.xlsx' or '数据表清单' in file:
|
|
continue
|
|
file_list.append(file)
|
|
return file_list
|
|
|
|
|
|
excel_data = []
|
|
|
|
|
|
def get_excel_data(path):
|
|
data = pd.read_excel(path)
|
|
try:
|
|
v = f'=HYPERLINK("models/{file}", "{data.values[0][1]}")'
|
|
except Exception as e:
|
|
print(data)
|
|
print(e)
|
|
v = f'=HYPERLINK("{path}", "{path}")'
|
|
excel_data.append(v)
|
|
|
|
|
|
def write_excel_data():
|
|
print(excel_data)
|
|
df = pd.DataFrame(excel_data, columns=['数据表清单'])
|
|
df.to_excel(f'../数据表清单{time.strftime("%Y-%m-%d")}.xlsx', index=False)
|
|
print("写入成功")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
path = "."
|
|
files = read_file_list(path)
|
|
for file in files:
|
|
get_excel_data(file)
|
|
write_excel_data()
|