Skip to main content

Пакет для работы с .docx файлами

Project description

DocxP

DocxP — это мой небольшой Python-проект для создания и форматирования Word-документов с использованием библиотеки python-docx. Вы можете дополнять и расширять ее при необходимости. Я постарался построить гибкую основу для последующего расширения.

Возможности

  • Абстрактные классы для описания стилей документа, абзацев и текста.
  • Реализация базовых стилей и логики генерации Word-документов.
  • Гибкая настройка шрифтов, отступов, выравнивания и др.

Структура проекта

  • core/ — модуль с основными и абстрактными классами:
    • AbstractClasses.py — абстрактные интерфейсы
    • CoreClasses.py — реализация базовых стилей
    • CustomClasses.py — расширение с пользовательскими стилями

Установка

pip install python-docx py_docx_creator

Пример использования

from py_docx_creator.CoreClasses import CoreDocumentCreator, CoreStyleManager
from py_docx_creator.CustomClasses import MainPageStyle, MainDocumentWriter, MainTextStyle, HeaderParagraphStyle, \
    MainParagraphStyle, HeaderTextStyle


class DocumentAPI(CoreDocumentCreator):

    def __init__(self, file_name: str):
        super().__init__()
        self.file_name = file_name
        self.style_manager = CoreStyleManager

    def run(self):
        self.create_document(self.file_name)
        self.style_manager.PAGE_STYLE_MANAGER.apply_style(self.document, MainPageStyle)

        paragraph = MainDocumentWriter.add_paragraph_to_document(self.document)
        self.style_manager.PARAGRAPH_STYLE_MANAGER.apply_style(paragraph, HeaderParagraphStyle)
        run = MainDocumentWriter.add_run_to_paragraph(paragraph=paragraph, text="Заголовок документа")
        self.style_manager.TEXT_STYLE_MANAGER.apply_style(run, HeaderTextStyle)

        paragraph = MainDocumentWriter.add_paragraph_to_document(self.document)
        self.style_manager.PARAGRAPH_STYLE_MANAGER.apply_style(paragraph, MainParagraphStyle)
        run = MainDocumentWriter.add_run_to_paragraph(paragraph=paragraph, text="Заголовок документа")
        self.style_manager.TEXT_STYLE_MANAGER.apply_style(run, MainTextStyle)

        self.save_document()


if __name__ == '__main__':
    DocumentAPI("Документ.docx").run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_docx_creator-0.1.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_docx_creator-0.1.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file py_docx_creator-0.1.2.tar.gz.

File metadata

  • Download URL: py_docx_creator-0.1.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for py_docx_creator-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e6d873cfd7d89cb049a585d0a20895805e60ff4808e3ea3b618fe7a4de8dc329
MD5 956c73c38271cbe826472d491fe3fb10
BLAKE2b-256 a38a54b88d4f703dd111396f16ebdf086483c5654fe738a3eee18359a6a812f1

See more details on using hashes here.

File details

Details for the file py_docx_creator-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for py_docx_creator-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2d96d8224195bf4e72c46ebb84c38f8b7efd15b343494400c39970dfa14423a9
MD5 8f6d162191e86fa2d40430d95e6941c9
BLAKE2b-256 aab6facebbf694f4218a5443e07f58ec8e4a28383c120d0ab0470301ade39a05

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page