spitdoc/create_test_doc.py

36 lines
1.1 KiB
Python

import docx
from docx.shared import Pt
from docx.enum.style import WD_STYLE_TYPE
import os
def create_chinese_test_document():
"""Create a test document with Chinese heading styles"""
# Create a new document
doc = docx.Document()
# Add title
title = doc.add_paragraph('文档标题', style='Title')
# Add some regular text
doc.add_paragraph('这是文档中的一些常规文本。')
# Try to use Chinese heading styles
# For this test, we'll use the default heading styles but with Chinese text
heading1 = doc.add_paragraph('第一章 简介', style='Heading 1')
doc.add_paragraph('这是第一章的内容。')
heading2 = doc.add_paragraph('1.1 背景', style='Heading 2')
doc.add_paragraph('这是1.1节的内容。')
heading2_2 = doc.add_paragraph('1.2 目标', style='Heading 2')
doc.add_paragraph('这是1.2节的内容。')
# Save the document
doc.save('test_chinese.docx')
print("Test document 'test_chinese.docx' created successfully.")
if __name__ == "__main__":
create_chinese_test_document()