Album orient by using templ. doc

This commit is contained in:
Кокос Артем Николаевич
2026-01-21 09:55:55 +07:00
committed by Артём Кокос
parent bca24189c7
commit 9a2f753480
2 changed files with 28 additions and 26 deletions

View File

@@ -1,40 +1,42 @@
from typing import List, Tuple
from redminelib.resources import Issue
from odf.opendocument import OpenDocumentText
from odf.style import Style, TableProperties, TableCellProperties, ParagraphProperties
from odf.opendocument import load
from odf.text import P
from odf.table import Table, TableColumn, TableRow, TableCell
from .formatter import get_version, hours_to_human, STATUS_TRANSLATION
import os
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> OpenDocumentText:
doc = OpenDocumentText()
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
# Загружаем шаблон с альбомной ориентацией
template_path = "template.odt"
# template_path = os.path.join(os.path.dirname(__file__), "..", "template.odt")
if not os.path.exists(template_path):
raise FileNotFoundError("Шаблон template.odt не найден. Создайте его вручную в LibreOffice (альбомная ориентация) и сохраните в корень проекта.")
# Стили
table_style = Style(name="Table", family="table")
table_style.addElement(TableProperties(width="17cm", align="center"))
doc.styles.addElement(table_style)
doc = load(template_path)
cell_style = Style(name="Cell", family="table-cell")
cell_style.addElement(TableCellProperties(border="0.5pt solid #000000"))
doc.styles.addElement(cell_style)
# Стили уже есть в шаблоне — просто используем их по имени
para_style_name = "Standard" # или другое имя, если вы задали стиль в шаблоне
table_style_name = "Table1" # LibreOffice обычно даёт такое имя
para_style = Style(name="Para", family="paragraph")
para_style.addElement(ParagraphProperties(textalign="left"))
doc.styles.addElement(para_style)
# Заголовок отчёта
header_text = "Кокос Артём Николаевич. Отчет за месяц Июль."
header_paragraph = P(stylename=para_style_name, text=header_text)
doc.text.addElement(header_paragraph)
# Таблица
table = Table(name="Report", stylename=table_style)
for _ in range(5): # 5 колонок
table = Table(name="Report", stylename=table_style_name)
for _ in range(5):
table.addElement(TableColumn())
# Заголовок
# Заголовки
header_row = TableRow()
headers = ["Проект", "Версия", "Задача", "Статус", "Затрачено"]
headers = ["Наименование Проекта", "Номер версии*", "Задача", "Статус Готовность*", "Затрачено за отчетный период"]
for text in headers:
cell = TableCell(stylename=cell_style)
p = P(stylename=para_style, text=text)
cell = TableCell()
p = P(stylename=para_style_name, text=text)
cell.addElement(p)
header_row.addElement(cell)
table.addElement(header_row)
@@ -52,19 +54,19 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> OpenDocumentText:
display_version = version if (project != prev_project or version != prev_version) else ""
row = TableRow()
for col_text in [
cells_content = [
display_project,
display_version,
f"{issue.id}. {issue.subject}",
status_ru,
hours_to_human(hours)
]:
cell = TableCell(stylename=cell_style)
p = P(stylename=para_style, text=col_text)
"" # как в скриншоте
]
for col_text in cells_content:
cell = TableCell()
p = P(stylename=para_style_name, text=col_text)
cell.addElement(p)
row.addElement(cell)
table.addElement(row)
prev_project = project
prev_version = version

BIN
template.odt Normal file

Binary file not shown.