import pandas as pd
from pathlib import Path
from . import write_log as log
def get_excel(file_name, sheet_name=0):
    """
    读取excel文件目录下.xlsx文件内容到DataFrame，并用空字符串填充缺失值
    :param file_name:
    :param sheet_name: 工作表名称或索引，默认读取第一个工作表
    :return: 填充缺失值后的DataFrame
    """


    project_root = Path(__file__).parent.parent
    # 拼接 demo/demo.xlsx 路径
    file_path = project_root / "excel" / (file_name+".xlsx")

    df = pd.read_excel(file_path, sheet_name=sheet_name)
    df = df.fillna("")  # 用空字符串填充缺失值
    df = df.to_dict(orient="records")
    # print(df)

    log.clear_log(file_name)
    log.write_log(file_name, df)
    return df

# print(file_path)