This repository has been archived on 2025-12-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

39 lines
1.2 KiB
Python
Raw Permalink Normal View History

2021-12-15 21:21:39 +08:00
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2021/12/15
2021-12-15 21:47:55 +08:00
# @File Name: read_excel.py
import pandas
from core.logger import Logger
from core.language import Language
2022-01-14 18:22:06 +08:00
from lib.buildGUIClass import InsertLog
gui_log = InsertLog()
2021-12-15 21:47:55 +08:00
def read_excel(kw: str):
"""
2021-12-20 21:23:10 +08:00
读取china_city_list.xlsx并搜索匹配关键字的结果并输出到终端
2021-12-15 21:47:55 +08:00
:param kw: keyword
:return: city_list
"""
language = Language()
index_count = 0
city_list = []
Logger.info(f'[Search]{language["reading_the_file"]}')
2022-01-14 18:22:06 +08:00
gui_log.insert(f'[Search]{language["reading_the_file"]}')
2021-12-15 21:47:55 +08:00
df = pandas.read_excel(f'./res/china_city_list.xlsx')
pandas.set_option('max_rows', None) # 读取xlsx文件不折叠
data_records = df.to_dict(orient='split')
for i in data_records['data']:
if kw in str(i):
Logger.info(f' {index_count} | {i[2]}-{i[4]}-{i[6]}')
2022-01-14 18:22:06 +08:00
gui_log.insert(f' {index_count} | {i[2]}-{i[4]}-{i[6]}')
2021-12-15 21:47:55 +08:00
city = [index_count, i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7], i[8], i[9]]
index_count += 1
city_list.append(city)
return city_list