当前位置:首页>python>[python]第18期-Python-docx 库使用教程:创建专业Word文档

[python]第18期-Python-docx 库使用教程:创建专业Word文档

  • 2026-01-16 12:27:40
[python]第18期-Python-docx 库使用教程:创建专业Word文档

Python-docx 是一个功能强大的 Python 库,用于创建和修改 Microsoft Word (.docx) 文件。本教程将详细介绍如何使用该库进行表格操作、图片添加、中文处理以及样式设置。

一、表格的创建与操作

1.1 创建表格

add_table() 方法是创建表格的核心方法,基本语法如下:

document.add_table(rows, cols, style=None)

参数说明

  • • rows:表格行数
  • • cols:表格列数
  • • style:表格样式(可选)

完整示例

from docx import Documentimport osimport random# 获取当前文件路径cur_path = os.path.dirname(__file__)savefilename = os.path.join(cur_path, 'docx_add_table.docx')# 创建文档对象document = Document()# 创建表格:1行3列,应用预定义样式table = document.add_table(rows=1, cols=3, style='Light List Accent 5')# 设置表头header = table.rows[0].cellsheader[0].text = 'ID'header[1].text = '姓名'header[2].text = '分数'# 准备数据list1 = ["张三", "李四", "王五", "赵六", "燕七"]# 添加数据行for i in range(5):  # 添加5行数据    row_cells = table.add_row().cells  # 注意:这里修正了变量名    row_cells[0].text = str(i + 1)  # ID从1开始    row_cells[1].text = random.choice(list1)    row_cells[2].text = str(random.randint(90, 100))# 保存文档document.save(savefilename)print(f"文档已保存至:{savefilename}")

1.2 常用表格样式

Python-docx 提供了多种预定义表格样式,以下是一些常用样式:

样式名称
描述
'Table Grid'
带网格线的简单表格
'Light Shading'
浅色底纹表格
'Light List'
浅色列表样式
'Light Grid'
浅色网格
'Medium Shading 1'
中等底纹1
'Medium Shading 2'
中等底纹2
'Medium List 1'
中等列表1
'Medium List 2'
中等列表2
'Dark List'
深色列表

1.3 读取表格内容

读取已存在的表格数据是文档处理中的常见需求:

from docx import Documentimport oscur_path = os.path.dirname(__file__)filename = os.path.join(cur_path, 'docx_add_table.docx')def get_all_table_data(document):    """提取文档中所有表格的数据"""    # 获取所有表格对象    tables = document.tables    all_data = []  # 存储所有表格数据    for table_index, table in enumerate(tables, 1):        print(f"\n=== 表格 {table_index} ===")        table_data = []  # 存储当前表格数据        # 遍历每一行        for row_index, row in enumerate(table.rows):            row_data = []  # 存储当前行数据            # 遍历每一单元格            for cell_index, cell in enumerate(row.cells):                # 获取单元格文本并去除首尾空白                cell_text = cell.text.strip()                row_data.append(cell_text)                # 打印单元格坐标和内容(调试用)                print(f"单元格[{row_index},{cell_index}]: {cell_text}")            # 将非空行添加到表格数据中            if any(row_data):  # 检查行是否有内容                table_data.append(row_data)        # 将当前表格数据添加到总数据中        all_data.append(table_data)        # 显示表格基本信息        print(f"表格大小: {len(table.rows)}行 × {len(table.columns)}列")    return all_data# 使用示例if __name__ == "__main__":    # 打开文档    my_document = Document(filename)    # 提取表格数据    tables_data = get_all_table_data(my_document)    # 处理提取的数据    print("\n=== 数据处理示例 ===")    for i, table_data in enumerate(tables_data, 1):        print(f"\n表格{i}的完整数据:")        for row in table_data:            print(row)    # 转换为DataFrame(可选,需要pandas)    try:        import pandas as pd        for i, table_data in enumerate(tables_data, 1):            if table_data:  # 确保表格有数据                df = pd.DataFrame(table_data[1:], columns=table_data[0])                print(f"\n表格{i}的DataFrame表示:")                print(df)    except ImportError:        print("\n提示:安装pandas库可以获得更好的表格数据处理能力")        print("安装命令: pip install pandas")

二、图片的添加与处理

2.1 基本图片添加

使用 add_picture() 方法添加图片:

from docx import Documentfrom docx.shared import Inchesfrom docx.enum.text import WD_ALIGN_PARAGRAPHimport oscur_path = os.path.dirname(__file__)savefilename = os.path.join(cur_path, 'docx_add_pic.docx')# 创建文档document = Document()# 添加标题document.add_heading('产品展示', level=1)# 添加图片描述document.add_paragraph('以下是我们公司的最新产品图片:')# 添加图片,设置宽高(单位:英寸)image_path = os.path.join(cur_path, 'office.png')# 检查文件是否存在if os.path.exists(image_path):    # 添加图片    document.add_picture(image_path, width=Inches(5), height=Inches(5))    # 获取包含图片的段落(最后一段)    last_paragraph = document.paragraphs[-1]    # 设置段落对齐方式(图片随之对齐)    last_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER    # 添加图片说明    document.add_paragraph('图1:公司产品示意图').alignment = WD_ALIGN_PARAGRAPH.CENTERelse:    print(f"警告:图片文件不存在 - {image_path}")    document.add_paragraph(f"[图片缺失: {os.path.basename(image_path)}]")# 保存文档document.save(savefilename)print(f"图片文档已保存至:{savefilename}")

2.2 图片处理的进阶技巧

from docx import Documentfrom docx.shared import Inches, Cm, Ptfrom docx.enum.text import WD_ALIGN_PARAGRAPHimport osdef add_images_with_formatting(document, image_folder):    """批量添加图片并格式化"""    # 支持的图片格式    image_extensions = ['.png', '.jpg', '.jpeg', '.gif', '.bmp']    # 获取文件夹中所有图片    images = []    for filename in os.listdir(image_folder):        if any(filename.lower().endswith(ext) for ext in image_extensions):            images.append(os.path.join(image_folder, filename))    if not images:        print("未找到图片文件")        return    # 添加图片标题    title = document.add_heading('产品图片集', level=1)    title.alignment = WD_ALIGN_PARAGRAPH.CENTER    # 设置图片排列方式    images_per_row = 2  # 每行图片数量    for i, image_path in enumerate(images):        # 每行开始前添加空段落(用于控制布局)        if i % images_per_row == 0:            document.add_paragraph()        # 获取图片名称(不含扩展名)        image_name = os.path.splitext(os.path.basename(image_path))[0]        # 添加图片标题        img_title = document.add_paragraph(image_name)        img_title.alignment = WD_ALIGN_PARAGRAPH.CENTER        # 添加图片(使用厘米单位)        try:            # 添加图片,限制最大宽度            run = document.add_paragraph().add_run()            run.add_picture(image_path, width=Cm(8))  # 8厘米宽            # 设置图片所在段落居中            run.paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER            # 添加图片边框(通过段落边框模拟)            run.paragraph.paragraph_format.space_after = Pt(5)        except Exception as e:            print(f"添加图片失败 {image_path}: {str(e)}")            document.add_paragraph(f"[图片加载失败: {image_name}]")        # 如果不是每行最后一个图片,添加制表符实现并排        if (i + 1) % images_per_row != 0 and i != len(images) - 1:            document.paragraphs[-1].add_run().add_tab()    return len(images)# 使用示例if __name__ == "__main__":    cur_path = os.path.dirname(__file__)    savefilename = os.path.join(cur_path, 'docx_multi_pics.docx')    image_folder = os.path.join(cur_path, 'images')  # 假设有images文件夹    # 创建文档    doc = Document()    # 添加图片    image_count = add_images_with_formatting(doc, image_folder)    # 添加统计信息    if image_count > 0:        doc.add_paragraph(f"\n共添加 {image_count} 张图片。")    # 保存    doc.save(savefilename)    print(f"多图文档已保存至:{savefilename}")

三、中文处理与字体设置

3.1 全局中文字体设置

正确设置中文字体是生成中文文档的关键:

from docx import Documentfrom docx.oxml.ns import qndef create_chinese_document():    """创建支持中文的文档"""    # 创建文档对象    document = Document()    # 方法1:全局设置中文字体(推荐)    document.styles['Normal'].font.name = '宋体'    document.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), '宋体')    # 添加标题(标题也会继承全局设置)    title = document.add_heading('中文文档示例', level=0)    # 添加正文    p1 = document.add_paragraph('这是一个使用python-docx创建的中文文档。')    p1.add_run('这段文字使用了加粗效果。').bold = True    # 方法2:针对特定段落设置字体    p2 = document.add_paragraph()    run = p2.add_run('这是单独设置字体的文本。')    # 设置run对象的字体    run.font.name = '微软雅黑'    run._element.rPr.rFonts.set(qn('w:eastAsia'), '微软雅黑')    run.font.size = Pt(14)  # 设置字体大小    # 添加列表    document.add_paragraph('文档特点:', style='List Bullet')    document.add_paragraph('支持中文显示', style='List Bullet 2')    document.add_paragraph('字体样式丰富', style='List Bullet 2')    document.add_paragraph('格式控制灵活', style='List Bullet 2')    return document# 常用中文字体对照表def chinese_font_settings():    """常用中文字体设置参考"""    font_mappings = [        ('宋体', 'SimSun'),        ('黑体', 'SimHei'),        ('微软雅黑', 'Microsoft YaHei'),        ('楷体', 'KaiTi'),        ('仿宋', 'FangSong'),        ('隶书', 'LiSu'),        ('幼圆', 'YouYuan'),    ]    print("常用中文字体设置:")    for ch_name, en_name in font_mappings:        print(f"  中文: {ch_name:<10} → 英文: {en_name}")    return font_mappings# 使用示例if __name__ == "__main__":    # 显示字体对照表    chinese_font_settings()    # 创建中文文档    doc = create_chinese_document()    # 保存文档    save_path = os.path.join(os.path.dirname(__file__), 'chinese_document.docx')    doc.save(save_path)    print(f"\n中文文档已创建:{save_path}")

3.2 完整的中文文档示例

from docx import Documentfrom docx.oxml.ns import qnfrom docx.shared import Pt, RGBColorfrom docx.enum.text import WD_ALIGN_PARAGRAPHdef create_professional_chinese_report():    """创建专业中文报告"""    document = Document()    # === 1. 全局字体设置 ===    normal_style = document.styles['Normal']    normal_style.font.name = '宋体'    normal_style._element.rPr.rFonts.set(qn('w:eastAsia'), '宋体')    normal_style.font.size = Pt(12)    # === 2. 创建标题 ===    title = document.add_heading('', level=0)    title_run = title.add_run('年度工作报告')    title_run.font.name = '黑体'    title_run._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')    title_run.font.size = Pt(22)    title_run.font.bold = True    title.alignment = WD_ALIGN_PARAGRAPH.CENTER    # 添加副标题    subtitle = document.add_paragraph()    subtitle.alignment = WD_ALIGN_PARAGRAPH.CENTER    subtitle_run = subtitle.add_run('(2024年度)')    subtitle_run.font.name = '楷体'    subtitle_run._element.rPr.rFonts.set(qn('w:eastAsia'), '楷体')    subtitle_run.font.size = Pt(14)    subtitle_run.font.color.rgb = RGBColor(128, 128, 128)  # 灰色    # === 3. 添加报告信息 ===    document.add_paragraph()  # 空行    info_table = document.add_table(rows=4, cols=2)    info_table.style = 'Light Grid'    info_data = [        ['报告部门', '技术研发部'],        ['报告人', '张三'],        ['报告日期', '2024年12月31日'],        ['联系方式', 'zhangsan@company.com']    ]    for i, (label, value) in enumerate(info_data):        row_cells = info_table.rows[i].cells        row_cells[0].text = label        row_cells[1].text = value        # 设置单元格字体        for cell in row_cells:            for paragraph in cell.paragraphs:                for run in paragraph.runs:                    run.font.name = '微软雅黑'                    run._element.rPr.rFonts.set(qn('w:eastAsia'), '微软雅黑')    # === 4. 添加报告正文 ===    document.add_heading('一、工作概述', level=1)    content = [        "本年度,技术研发部在公司领导的正确指导下,紧紧围绕年度工作目标,",        "积极开展各项研发工作,取得了显著成效。",        "全年共完成重点项目3个,申请专利5项,发表技术论文2篇。"    ]    for text in content:        p = document.add_paragraph(text)        p.paragraph_format.first_line_indent = Pt(28)  # 首行缩进        p.paragraph_format.line_spacing = 1.5  # 1.5倍行距    # === 5. 添加重点成果(列表) ===    document.add_heading('二、重点成果', level=1)    achievements = [        "项目A:完成了新一代智能系统开发,性能提升40%",        "项目B:实现了关键技术突破,获得行业创新奖",        "项目C:优化了生产流程,成本降低15%"    ]    for achievement in achievements:        p = document.add_paragraph(achievement, style='List Bullet')    # === 6. 添加总结 ===    document.add_heading('三、总结与展望', level=1)    summary = document.add_paragraph()    summary.paragraph_format.space_before = Pt(12)    summary_run1 = summary.add_run('总结:')    summary_run1.font.bold = True    summary_run1.font.name = '黑体'    summary_run1._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')    summary.add_run(' 过去一年我们取得了可喜的成绩,但也认识到存在的不足。')    # 添加展望    outlook = document.add_paragraph()    outlook_run1 = outlook.add_run('展望:')    outlook_run1.font.bold = True    outlook_run1.font.name = '黑体'    outlook_run1._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')    outlook.add_run(' 明年我们将继续加大研发投入,重点突破关键技术,为公司发展贡献力量。')    return document# 使用示例if __name__ == "__main__":    # 创建专业报告    report = create_professional_chinese_report()    # 保存文档    save_path = os.path.join(os.path.dirname(__file__), '年度工作报告.docx')    report.save(save_path)    print(f"专业中文报告已生成:{save_path}")

四、样式使用详解

4.1 段落样式设置

from docx import Documentfrom docx.enum.style import WD_STYLE_TYPEfrom docx.enum.text import WD_ALIGN_PARAGRAPHfrom docx.shared import Pt, Inchesdef demonstrate_paragraph_styles():    """展示段落样式设置"""    document = Document()    # === 1. 查看所有可用段落样式 ===    print("可用的段落样式:")    styles = document.styles    paragraph_styles = []    for style in styles:        if style.type == WD_STYLE_TYPE.PARAGRAPH:            paragraph_styles.append(style.name)            print(f"  - {style.name}")    print(f"\n共找到 {len(paragraph_styles)} 种段落样式\n")    # === 2. 添加段落时设置样式 ===    document.add_heading('段落样式示例', level=1)    # 使用不同预定义样式    document.add_paragraph('这是普通段落(Normal样式)', style='Normal')    document.add_paragraph('这是标题1样式', style='Heading 1')    document.add_paragraph('这是标题2样式', style='Heading 2')    document.add_paragraph('这是列表项目符号', style='List Bullet')    document.add_paragraph('这是列表编号', style='List Number')    document.add_paragraph('这是引用样式', style='Intense Quote')    # === 3. 添加后修改样式 ===    custom_para = document.add_paragraph('这是自定义样式的段落')    custom_para.style = 'List Bullet 2'  # 添加后修改样式    # === 4. 对齐方式设置 ===    document.add_heading('段落对齐方式', level=1)    alignments = [        ('左对齐', WD_ALIGN_PARAGRAPH.LEFT),        ('居中对齐', WD_ALIGN_PARAGRAPH.CENTER),        ('右对齐', WD_ALIGN_PARAGRAPH.RIGHT),        ('两端对齐', WD_ALIGN_PARAGRAPH.JUSTIFY)    ]    for name, alignment in alignments:        p = document.add_paragraph(f'这段文字是{name}的示例。')        p.alignment = alignment    # === 5. 高级格式设置 ===    document.add_heading('高级格式设置', level=1)    # 创建自定义格式段落    advanced_para = document.add_paragraph()    # 设置段落格式    para_format = advanced_para.paragraph_format    para_format.first_line_indent = Pt(28)  # 首行缩进    para_format.line_spacing = 1.5  # 1.5倍行距    para_format.space_before = Pt(12)  # 段前间距    para_format.space_after = Pt(12)   # 段后间距    para_format.left_indent = Inches(0.5)  # 左缩进    # 添加内容    run = advanced_para.add_run('这是一个具有高级格式设置的段落:')    run.bold = True    advanced_para.add_run(' 首行缩进、1.5倍行距、段前段后间距12磅、左缩进0.5英寸。')    return document# 使用示例if __name__ == "__main__":    # 演示段落样式    doc = demonstrate_paragraph_styles()    # 保存文档    save_path = os.path.join(os.path.dirname(__file__), 'paragraph_styles.docx')    doc.save(save_path)    print(f"\n段落样式示例文档已生成:{save_path}")

4.2 创建自定义样式

from docx import Documentfrom docx.enum.style import WD_STYLE_TYPEfrom docx.shared import Pt, RGBColordef create_custom_styles():    """创建自定义样式"""    document = Document()    # === 1. 添加自定义段落样式 ===    styles = document.styles    # 创建"重点提示"样式    if '重点提示' not in styles:        tip_style = styles.add_style('重点提示', WD_STYLE_TYPE.PARAGRAPH)        tip_style.font.name = '微软雅黑'        tip_style.font.size = Pt(11)        tip_style.font.bold = True        tip_style.font.color.rgb = RGBColor(220, 50, 50)  # 红色        # 设置段落格式        tip_style.paragraph_format.left_indent = Pt(20)        tip_style.paragraph_format.space_before = Pt(6)        tip_style.paragraph_format.space_after = Pt(6)    # 创建"代码块"样式    if '代码块' not in styles:        code_style = styles.add_style('代码块', WD_STYLE_TYPE.PARAGRAPH)        code_style.font.name = 'Consolas'        code_style.font.size = Pt(10)        code_style.font.color.rgb = RGBColor(30, 100, 200)  # 蓝色        # 设置背景色(通过段落底纹)        code_style.paragraph_format.left_indent = Pt(30)        code_style.paragraph_format.right_indent = Pt(30)    # === 2. 使用自定义样式 ===    document.add_heading('自定义样式示例', level=1)    # 使用默认样式    document.add_paragraph('这是普通文本。')    # 使用自定义"重点提示"样式    document.add_paragraph('这是重点提示内容,请注意查看!', style='重点提示')    # 使用自定义"代码块"样式    code_text = '''def example_function():    """示例函数"""    print("Hello, World!")    return True'''    document.add_paragraph(code_text, style='代码块')    # === 3. 修改现有样式 ===    document.add_heading('修改现有样式', level=1)    # 获取Normal样式并修改    normal_style = styles['Normal']    normal_style.font.name = '楷体'    normal_style.font.size = Pt(12)    # 使用修改后的Normal样式    document.add_paragraph('这段文字使用修改后的Normal样式。')    return document, styles# 使用示例if __name__ == "__main__":    # 创建自定义样式文档    doc, style_obj = create_custom_styles()    # 保存文档    save_path = os.path.join(os.path.dirname(__file__), 'custom_styles.docx')    doc.save(save_path)    # 显示所有样式    print("文档中所有样式:")    for style in style_obj:        if style.type == WD_STYLE_TYPE.PARAGRAPH:            print(f"  - {style.name}")    print(f"\n自定义样式文档已生成:{save_path}")

五、实战综合应用

5.1 创建完整的产品报告

from docx import Documentfrom docx.oxml.ns import qnfrom docx.shared import Pt, Inches, RGBColor, Cmfrom docx.enum.text import WD_ALIGN_PARAGRAPHimport osfrom datetime import datetimedef create_product_report(product_data, images_folder=None):    """    创建产品报告文档    参数:    product_data: 产品信息字典    images_folder: 产品图片文件夹路径    """    # 创建文档    document = Document()    # === 1. 全局设置 ===    normal_style = document.styles['Normal']    normal_style.font.name = '微软雅黑'    normal_style._element.rPr.rFonts.set(qn('w:eastAsia'), '微软雅黑')    normal_style.font.size = Pt(11)    # === 2. 封面页 ===    # 添加大标题    title = document.add_heading('', level=0)    title_run = title.add_run('产品技术报告')    title_run.font.name = '黑体'    title_run._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')    title_run.font.size = Pt(36)    title_run.font.bold = True    title.alignment = WD_ALIGN_PARAGRAPH.CENTER    # 添加产品名称    product_title = document.add_heading(product_data.get('name', '产品名称'), level=1)    product_title.alignment = WD_ALIGN_PARAGRAPH.CENTER    product_title.paragraph_format.space_before = Pt(72)    # 添加报告信息    info_table = document.add_table(rows=5, cols=2)    info_table.style = 'Light Grid Accent 1'    info_rows = [        ['报告编号', product_data.get('report_id', 'RP-2024-001')],        ['产品型号', product_data.get('model', 'N/A')],        ['生产日期', product_data.get('production_date', '2024-01-01')],        ['负责人', product_data.get('manager', '张三')],        ['生成日期', datetime.now().strftime('%Y年%m月%d日')]    ]    for i, (label, value) in enumerate(info_rows):        row_cells = info_table.rows[i].cells        row_cells[0].text = label        row_cells[1].text = value        # 设置单元格样式        for cell in row_cells:            for paragraph in cell.paragraphs:                paragraph.alignment = WD_ALIGN_PARAGRAPH.LEFT    # 添加分页符    document.add_page_break()    # === 3. 目录 ===    document.add_heading('目录', level=1)    # 模拟目录(实际项目中可以使用更高级的目录生成方法)    toc_items = [        '1. 产品概述',        '2. 技术规格',        '3. 性能参数',        '4. 使用说明',        '5. 维护保养',        '6. 注意事项'    ]    for item in toc_items:        p = document.add_paragraph(item, style='List Bullet')        p.paragraph_format.left_indent = Pt(20)    document.add_page_break()    # === 4. 产品概述 ===    document.add_heading('1. 产品概述', level=1)    overview = product_data.get('overview', '暂无产品概述信息。')    document.add_paragraph(overview)    # === 5. 技术规格表格 ===    document.add_heading('2. 技术规格', level=1)    specs = product_data.get('specifications', {})    if specs:        spec_table = document.add_table(rows=len(specs) + 1, cols=2)        spec_table.style = 'Medium Grid 1 Accent 1'        # 表头        header_cells = spec_table.rows[0].cells        header_cells[0].text = '项目'        header_cells[1].text = '规格'        # 数据行        for i, (key, value) in enumerate(specs.items(), 1):            row_cells = spec_table.rows[i].cells            row_cells[0].text = str(key)            row_cells[1].text = str(value)    # === 6. 添加产品图片 ===    if images_folder and os.path.exists(images_folder):        document.add_heading('3. 产品图片', level=1)        # 查找图片文件        image_extensions = ['.png', '.jpg', '.jpeg', '.gif']        images = []        for filename in os.listdir(images_folder):            if any(filename.lower().endswith(ext) for ext in image_extensions):                images.append(os.path.join(images_folder, filename))        # 添加图片        for i, image_path in enumerate(images[:3]):  # 最多添加3张            # 添加图片标题            img_name = os.path.splitext(os.path.basename(image_path))[0]            document.add_paragraph(f'图{i+1}: {img_name}').alignment = WD_ALIGN_PARAGRAPH.CENTER            # 添加图片            try:                document.add_picture(image_path, width=Cm(12))                # 设置图片居中                last_paragraph = document.paragraphs[-1]                last_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER                # 添加空行                document.add_paragraph()            except:                document.add_paragraph(f'[无法加载图片: {img_name}]')    # === 7. 注意事项(使用自定义样式) ===    document.add_heading('6. 注意事项', level=1)    # 创建警告样式    if '警告文本' not in document.styles:        warning_style = document.styles.add_style('警告文本', WD_STYLE_TYPE.PARAGRAPH)        warning_style.font.name = '黑体'        warning_style._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')        warning_style.font.size = Pt(11)        warning_style.font.color.rgb = RGBColor(200, 0, 0)    warnings = product_data.get('warnings', [        '请勿在潮湿环境下使用本产品',        '避免强烈震动和冲击',        '定期进行维护检查',        '使用原装配件进行更换'    ])    for warning in warnings:        document.add_paragraph(f'⚠ {warning}', style='警告文本')    return document# 使用示例if __name__ == "__main__":    # 模拟产品数据    sample_product = {        'name': '智能工业机器人X2000',        'report_id': 'RP-2024-ROBOT-001',        'model': 'X2000-Pro',        'production_date': '2024-06-15',        'manager': '李四',        'overview': 'X2000型智能工业机器人采用最新的人工智能技术,具备自主学习和适应能力。适用于多种工业场景,包括装配、焊接、搬运等作业。',        'specifications': {            '工作半径': '2000mm',            '最大负载': '20kg',            '重复定位精度': '±0.05mm',            '工作温度': '0-45°C',            '电源要求': '220V AC, 50Hz',            '防护等级': 'IP67',            '重量': '850kg',            '控制系统': 'AI自适应控制系统'        },        'warnings': [            '操作前请接受专业培训',            '确保工作区域安全防护',            '定期检查机械部件磨损情况',            '异常情况下立即按下急停按钮'        ]    }    # 创建报告    report_doc = create_product_report(        sample_product,        images_folder=os.path.join(os.path.dirname(__file__), 'product_images')    )    # 保存文档    save_path = os.path.join(os.path.dirname(__file__), '智能工业机器人X2000报告.docx')    report_doc.save(save_path)    print(f"产品报告已生成:{save_path}")    print(f"文档包含 {len(report_doc.paragraphs)} 个段落")    print(f"文档包含 {len(report_doc.tables)} 个表格")

六、最佳实践与注意事项

6.1 性能优化建议

  1. 1. 批量操作:尽量减少对文档的频繁读写操作
  2. 2. 样式重用:预定义样式并重复使用,避免逐个设置
  3. 3. 内存管理:处理大文档时注意内存使用

6.2 常见问题解决

  1. 1. 中文乱码问题:确保正确设置中文字体
  2. 2. 图片不显示:检查图片路径和格式
  3. 3. 表格格式错乱:使用预定义样式或仔细设置单元格格式

6.3 扩展建议

  1. 1. 与数据源集成:结合数据库或Excel读取数据
  2. 2. 模板化设计:创建文档模板,动态填充内容
  3. 3. 批量生成:实现多文档批量生成功能

总结

Python-docx 是一个功能全面的 Word 文档处理库,通过本教程的学习,您应该已经掌握了:

  1. 1. 表格操作:创建、填充、读取表格数据
  2. 2. 图片处理:添加图片、设置大小和对齐方式
  3. 3. 中文支持:正确设置中文字体,避免显示问题
  4. 4. 样式应用:使用预定义样式和创建自定义样式
  5. 5. 综合应用:创建专业、美观的完整文档

通过合理组合这些功能,您可以自动化生成各种复杂的 Word 文档,大大提高工作效率。在实际应用中,建议先规划好文档结构,然后逐步实现各个部分的功能。

 s

编辑 | SKYPIEA

官网 | skypiea.top
商务合作 | 2312890532@qq.com

SKYPIEA,连接世界、连接未来的秘密宝藏之地,通往无限可能,只要努力追寻,我们的征途是世间万物、星辰大海。

更多内容请关注SKYPIEA微信公众号

点击“在看”,让更多人发现SKYPIEA↓

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-08 17:55:59 HTTP/2.0 GET : https://f.mffb.com.cn/a/463526.html
  2. 运行时间 : 0.257420s [ 吞吐率:3.88req/s ] 内存消耗:4,439.33kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=dd05a5ff11770beaeadef4afb04120a9
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000809s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001344s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.024500s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000605s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.001335s ]
  6. SELECT * FROM `set` [ RunTime:0.000550s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.001344s ]
  8. SELECT * FROM `article` WHERE `id` = 463526 LIMIT 1 [ RunTime:0.018319s ]
  9. UPDATE `article` SET `lasttime` = 1770544559 WHERE `id` = 463526 [ RunTime:0.008611s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.009803s ]
  11. SELECT * FROM `article` WHERE `id` < 463526 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.002000s ]
  12. SELECT * FROM `article` WHERE `id` > 463526 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.008717s ]
  13. SELECT * FROM `article` WHERE `id` < 463526 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.002288s ]
  14. SELECT * FROM `article` WHERE `id` < 463526 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.003096s ]
  15. SELECT * FROM `article` WHERE `id` < 463526 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.001930s ]
0.261420s