# to_excel **Repository Path**: beginning_of_spring/to_excel ## Basic Information - **Project Name**: to_excel - **Description**: 带有格式的excel 输出。可以结合 pandas DataFrame或者直接根据行或者列写入 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-10-28 - **Last Updated**: 2024-08-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Python TO Excel #### Version - 0.2 #### 介绍 - 带有格式的 Excel 输出(全局)) - 支持可扩展的函数自定义输出样式。目前支持合并行尾(PDFile)),支持自定义设置合并单元格样式 - 支持全局列宽或自定义每列行宽 #### 样式参照 - 官方样式参照[https://xlsxwriter.readthedocs.io/] #### 软件架构 - main.py ```python # 表头格式 { 'font': '仿宋', 'align': 'center', 'valign': 'center', 'bold': True, 'border': None, 'font_size': 12 } # 内容格式 { 'font': '仿宋', 'align': 'center', 'valign': 'center' } ``` #### 使用说明 - python3.12x **文件** ```python # pandas 结合 data = { 'Data1': [10, 20, 30, 20, 15, 30, 45], 'Data2': [10, 20, 30, 20, 15, 30, 45], 'Data3': [10, 20, 30, 20, 15, 30, 45], 'Data4': [10, 20, 30, 20, 15, 30, 45], 'Data5': [10, 20, 30, 20, 15, 30, 45], 'Data6': [10, 20, 30, 20, 15, 30, 45], 'Data7': [10, 20, 30, 20, 15, 30, 45], } df = pd.DataFrame(data) obj = PDFile(df=df, sheet_name='text', file_name='test.xlsx', path=p) obj.write() # 列表或者数组形式 # 每个元素是一列数据 data = (('a', 'b', 'c', 'd'), ('e', 'f', 'g', 'h'), ('j', 'k', 'l', 'm')) # 表头 columns = ('A', 'B', 'C') obj = DTFile(data=data, columns=columns, sheet_name='text', file_name='test.xlsx', path=p) obj.write() """ DTFile( columns: 必传, content_w_row: 预留表头位置 默认从第二行开始写入, column_width: 列宽,使用默认值 is_w_col: 默认列写入数据 data 根据列拼接。True时根据行写入数据,data根据行拼接数据 data:[tuple, list] 数据 根据行或者列 file_name: 生成的文件名称 path: 文件生成的路径 sheet_name: 默认 Sheet1可指定 ) """ ``` **文件流** 文件流形式, 可使用在web中。同时支持 嵌套数据和DataFrame,两种形式