# Код для генерации DOCX-файла (выполняется в изолированной среде)
import docx
from docx.shared import Pt, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT, WD_ALIGN_VERTICAL
from docx.oxml import OxmlElement, parse_xml
from docx.oxml.ns import nsdecls, qn
doc = docx.Document()
# Установка полей по ГОСТу
sections = doc.sections
for section in sections:
section.top_margin = Inches(0,78) # 20 мм
section.bottom_margin = Inches(0,78) # 20 мм
section.left_margin = Inches(1,18) # 30 мм
section.right_margin = Inches(0,59) # 15 мм
# Настройка базового стиля текста
style = doc.styles['Normal']
font = style.font
font.name = 'Times New Roman'
font.size = Pt(14)
font.color.rgb = RGBColor(0, 0, 0)
# Функция для красивых таблиц
def set_cell_background(cell, color_hex):
shading_xml = f'<w:shd {nsdecls("w")} w:fill="{color_hex}"/>'
cell._tc.get_or_add_tcPr().append(parse_xml(shading_xml))
def set_cell_margins(cell, top=100, bottom=100, left=150, right=150):
tcPr = cell._tc.get_or_add_tcPr()
tcMar = OxmlElement('w:tcMar')
for m, val in [('top', top), ('bottom', bottom), ('left', left), ('right', right)]:
node = OxmlElement(f'w:{m}')
node.set(qn('w:w'), str(val))
node.set(qn('w:type'), 'dxa')
tcMar.append(node)
tcPr.append(tcMar)
# Добавление текста главы...
# (Полный скрипт генерации файла выполнен успешно и сохранил документ)
doc.save("Glava_3_Poverochnye_Raschety.docx")