Project for Adding Data to DOCX
About
This project is designed to add information to an existing .docx document. The data is provided in the form of a dictionary and is then inserted into the document using the sbi_special_docx_master module along with the python-docx library. A predefined data structure is used during the process.
Features
DOCX Processing: Automates the editing and formatting of DOCX documents.
Flexible Configuration: Easily customize processing parameters to suit your specific needs.
Seamless Integration: Integrates smoothly with other services and workflows thanks to its open architecture.
Extensibility: A clear and modular code structure allows you to add new features or modify existing ones with ease.
Table of Contents
Installation
The project is available on the Python Package Index (PyPI), making installation simple and straightforward. To install, run:
pip install sbi-special-docx-master
Main Components
sbi_special_docx_masterThis module contains the
AddDocxclass, which allows you to add textual information, images, and headers to a .docx document.
Usage
Imports:
from sbi_special_docx_master import AddDocx
from docx import Document
Loading an existing .docx document:
add_file = "Your_file.docx"
doc = Document(add_file)
Creating a dictionary with information:
info_dict = {
'separate_information_relations': [
{
'content': 'str',
'images': [
{
'file': '<Base64>'
}
],
'title': 'str'
},
{
'content': 'str',
'images': [
{
'file': int
}
],
'title': 'str'
}
]
}
Adding data to the document:
spec = AddDocx(doc, info_dict)
Generating a bytes stream of the document:
io_doc = spec.save_io()
Generating and saving the .docx document:
spec.save('my_file.docx')
Retrieving the document object:
doc = spec.document
Generating a bytes stream of the document:
io_doc = spec.save_io()
Check whether the addition operation was successful:
doc_suc = spec.has_succeeded