""" coding=uft-8 解.xlsx文件 单元格ctype的五种类型 ctype : 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error """ from loguru import logger from docs.config import error_number import pandas as pd def read_xlsx(file_path: str): """ 返回拼接好的字符串 :param file_path: :return: """ try: excel_data = pd.read_excel(file_path, keep_default_na=False, sheet_name=None) tables = [] for sheet_name, table_2d in excel_data.items(): string = '' for row in table_2d.values: string += '' for clown in row: clown = str(clown) string += '' string += '' string_end = string + '
' + clown.strip('\n').strip('\t') + '
' tables.append(string_end) content = "\n".join(tables) return content, error_number["成功"] except Exception as e: logger.error('xlsx文件解析出错') logger.error(e) return '', error_number["解析错误"] if __name__ == '__main__': file_path = "0.xls" string = read_xlsx(file_path) print(string)