advanced-office-tool 1.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,139 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is a Work based on the Work, and to which the licensee
41
+ may add copyright notice, and any translation or adaptation of
42
+ such Derivative Works.
43
+
44
+ "Contribution" shall mean any Work of authorship, including
45
+ the original version of the Work and any modifications or additions
46
+ to that Work or Derivative Works thereof, that is intentionally
47
+ submitted to the Licensor for inclusion in the Work.
48
+
49
+ "Contributor" shall mean Licensor and any individual or Legal Entity
50
+ on behalf of whom a Contribution has been received by Licensor and
51
+ subsequently incorporated within the Work.
52
+
53
+ 2. Grant of Copyright License. Subject to the terms and conditions of
54
+ this License, each Contributor hereby grants to You a perpetual,
55
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
56
+ copyright license to reproduce, prepare Derivative Works of,
57
+ publicly display, publicly perform, sublicense, and distribute the
58
+ Work and such Derivative Works in Source or Object form.
59
+
60
+ 3. Grant of Patent License. Subject to the terms and conditions of
61
+ this License, each Contributor hereby grants to You a perpetual,
62
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
63
+ (except as stated in this section) patent license to make, have made,
64
+ use, offer to sell, sell, import, and otherwise transfer the Work,
65
+ where such license applies only to those patent claims licensable
66
+ by such Contributor that are necessarily infringed by their
67
+ Contribution(s) alone or by combination of their Contribution(s)
68
+ with the Work to which such Contribution(s) was submitted.
69
+
70
+ 4. Redistribution. You may reproduce and distribute copies of the
71
+ Work or Derivative Works thereof in any medium, with or without
72
+ modifications, and in Source or Object form, provided that You
73
+ meet the following conditions:
74
+
75
+ (a) You must give any other recipients of the Work or
76
+ Derivative Works a copy of this License; and
77
+
78
+ (b) You must cause any modified files to carry prominent notices
79
+ stating that You changed the files; and
80
+
81
+ (c) You must retain, in the Source form of any Derivative Works
82
+ that You distribute, all copyright, patent, trademark, and
83
+ attribution notices from the Source form of the Work,
84
+ excluding those notices that do not pertain to any part of
85
+ the Derivative Works; and
86
+
87
+ (d) If the Work includes a "NOTICE" text file as part of its
88
+ distribution, then any Derivative Works that You distribute must
89
+ include a readable copy of the attribution notices contained
90
+ within such NOTICE file, excluding any notices that do not
91
+ pertain to any part of the Derivative Works, in at least one
92
+ of the following places: within a NOTICE text file distributed
93
+ as part of the Derivative Works; within the Source form or
94
+ documentation, if provided along with the Derivative Works; or,
95
+ within a display generated by the Derivative Works, if and
96
+ wherever such third-party notices normally appear.
97
+
98
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
99
+ any Contribution intentionally submitted for inclusion in the Work
100
+ by You to the Licensor shall be under the terms and conditions of
101
+ this License, without any additional terms or conditions.
102
+
103
+ 6. Trademarks. This License does not grant permission to use the trade
104
+ names, trademarks, service marks, or product names of the Licensor,
105
+ except as required for reasonable and customary use in describing the
106
+ origin of the Work and reproducing the content of the NOTICE file.
107
+
108
+ 7. Disclaimer of Warranty. Unless required by applicable law or
109
+ agreed to in writing, Licensor provides the Work (and each
110
+ Contributor provides its Contributions) on an "AS IS" BASIS,
111
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
112
+ implied, including, without limitation, any warranties or conditions
113
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
114
+ PARTICULAR PURPOSE.
115
+
116
+ 8. Limitation of Liability. In no event and under no legal theory,
117
+ whether in contract, tort (including negligence), or otherwise,
118
+ unless required by applicable law (such as deliberate and grossly
119
+ negligent acts) or agreed to in writing, shall any Contributor be
120
+ liable to You for damages, including any direct, indirect, special,
121
+ incidental, or consequential damages of any character arising as a
122
+ result of this License or out of the use or inability to use the
123
+ Work (including but not limited to damages for loss of goodwill,
124
+ work stoppage, computer failure or malfunction, or any and all
125
+ other commercial damages or losses), even if such Contributor
126
+ has been advised of the possibility of such damages.
127
+
128
+ 9. Accepting Warranty or Additional Liability. While redistributing
129
+ the Work or Derivative Works thereof, You may choose to offer,
130
+ and charge a fee for, acceptance of support, warranty, indemnity,
131
+ or other liability obligations and/or rights consistent with this
132
+ License. However, in accepting such obligations, You may act only
133
+ on Your own behalf and on Your sole responsibility, not on behalf
134
+ of any other Contributor, and only if You agree to indemnify,
135
+ defend, and hold each Contributor harmless for any liability incurred
136
+ by, or claims asserted against, such Contributor by reason of your
137
+ accepting any such warranty or additional liability.
138
+
139
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: advanced-office-tool
3
+ Version: 1.1.1
4
+ Summary: Advanced office document processing toolkit — Word (DOCX), Excel (XLSX), and other formats
5
+ Author-email: Eric <meantech6@163.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/user/advanced-office-tool
8
+ Project-URL: Repository, https://github.com/user/advanced-office-tool
9
+ Project-URL: Bug Tracker, https://github.com/user/advanced-office-tool/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Topic :: Office/Business
19
+ Classifier: Topic :: Text Processing :: General
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: python-docx>=1.1.0
24
+ Requires-Dist: openpyxl>=3.1.0
25
+ Requires-Dist: pygtrans>=1.2.0
26
+ Requires-Dist: lxml>=4.0
27
+ Requires-Dist: docxtpl>=0.16.0
28
+ Requires-Dist: docxcompose>=1.3.0
29
+ Requires-Dist: jinja2>=3.0
30
+ Requires-Dist: PyMuPDF>=1.23.0
31
+ Requires-Dist: pdf2docx>=0.5.0
32
+ Requires-Dist: pdfplumber>=0.9.0
33
+ Requires-Dist: reportlab>=4.0
34
+ Requires-Dist: pandas>=2.0
35
+ Requires-Dist: Pillow>=10.0
36
+ Requires-Dist: yt-dlp>=2023.0
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=8.0; extra == "dev"
39
+ Requires-Dist: black>=24.0; extra == "dev"
40
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
41
+ Provides-Extra: pdf
42
+ Requires-Dist: reportlab>=4.0; extra == "pdf"
43
+ Dynamic: license-file
44
+
45
+ # Advanced Office Tool
46
+
47
+ Advanced office document processing toolkit — Word (DOCX), Excel (XLSX), and other formats.
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install advanced-office-tool
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ Use `ServerAgent` for all document operations. Import once, call methods on any file path.
58
+
59
+ ```python
60
+ from advanced_office_tool import ServerAgent
61
+
62
+ agent = ServerAgent()
63
+ ```
64
+
65
+ ### DOCX Translation
66
+
67
+ ```python
68
+ result = agent.translate_file(
69
+ "manual.docx",
70
+ target_language="en", # "en", "zh", "auto", etc.
71
+ target_format="{translated}" # or "{original}" or "{original}{translated}"
72
+ )
73
+ print(result["output_file_path"])
74
+ # → /home/ovos/.hermes/skills/office-tool/uploads/manual_en.docx
75
+ ```
76
+
77
+ ### DOCX Merge (with auto CRC-32 repair)
78
+
79
+ ```python
80
+ from advanced_office_tool import DocxAgent, SafeDocument
81
+
82
+ # Merge with auto repair for corrupted files
83
+ agent = DocxAgent()
84
+ agent.load_document("chapter1.docx")
85
+ agent.merge_docx(["chapter2.docx", "chapter3.docx"], "merged.docx")
86
+ ```
87
+
88
+ `SafeDocument` transparently repairs bad CRC-32 ZIP checksums:
89
+
90
+ ```python
91
+ from advanced_office_tool import SafeDocument
92
+ from docx import Document
93
+
94
+ # Broken DOCX auto-repairs on first access
95
+ doc = SafeDocument("corrupted.docx")
96
+ for p in doc.paragraphs:
97
+ print(p.text)
98
+ ```
99
+
100
+ ### PDF Conversion
101
+
102
+ ```python
103
+ # PDF → DOCX
104
+ result = agent.pdf_to_docx("scan.pdf")
105
+ print(result["content"])
106
+
107
+ # DOCX → PDF
108
+ result = agent.docx_to_pdf("report.docx")
109
+ print(result["content"])
110
+
111
+ # XLSX → PDF
112
+ result = agent.xlsx_to_pdf("data.xlsx")
113
+ print(result["content"])
114
+
115
+ # Images → PDF
116
+ result = agent.pngs_to_pdf(["img1.png", "img2.png"])
117
+ print(result["output_pdf_path"])
118
+
119
+ # PDF → PNG images
120
+ images = agent.pdf_to_png("document.pdf", dpi=300)
121
+ print(images) # ["/path/to/page0.png", ...]
122
+ ```
123
+
124
+ ### PDF Stamp
125
+
126
+ ```python
127
+ result = agent.add_stamp_to_pdf(
128
+ "contract.pdf",
129
+ position="80,80", # top-right corner
130
+ scale="1.5", # stamp size multiplier
131
+ stamp_image="./stamp.png" # stamp image path
132
+ )
133
+ print(result["output_pdf_after_stamp"])
134
+ ```
135
+
136
+ ### Excel Price Adjustment
137
+
138
+ ```python
139
+ result = agent.adjust_price_in_excel(
140
+ "quote.xlsx",
141
+ price_multiplier="1.3/6.9", # unit_price * multiplier / divisor
142
+ decimal_places="0" # round to 0 decimals
143
+ )
144
+ print(result["output_file_path"])
145
+ ```
146
+
147
+ ### Template Rendering
148
+
149
+ ```python
150
+ result = agent.render_docx_template(
151
+ "template.docx",
152
+ obj={"name": "Company A", "amount": 50000},
153
+ output_path="output.docx"
154
+ )
155
+ ```
156
+
157
+ ### PDF Merge to DOCX (N images per page)
158
+
159
+ ```python
160
+ result = agent.merge_pdfs_folder_to_docx_vertical(
161
+ pdf_folder="./invoices", # folder with PDF files
162
+ number_in_page=2 # 2 PDF pages per DOCX page
163
+ )
164
+ print(result["output_file_path"])
165
+ ```
166
+
167
+ ### Unzip
168
+
169
+ ```python
170
+ result = agent.uncompress_zip("archive.zip", "mt123456")
171
+ print(result["message"])
172
+ ```
173
+
174
+ ### Available Classes
175
+
176
+ | Class | Description |
177
+ |-------|-------------|
178
+ | `ServerAgent` | Main orchestrator — PDF, Excel, DOCX, translation, templates |
179
+ | `DocxAgent` | DOCX paragraph/table translation and manipulation |
180
+ | `ExcelOperator` | XLSX merge, formula, style, image manipulation |
181
+ | `TranslateAgent` | pygtrans batch translate with terminology protection |
182
+ | `SafeDocument` | Auto-repair DOCX files with bad CRC-32 checksums |
183
+ | `OdooAgent` | Odoo ERP integration |
184
+
185
+ ## License
186
+
187
+ Apache-2.0
@@ -0,0 +1,143 @@
1
+ # Advanced Office Tool
2
+
3
+ Advanced office document processing toolkit — Word (DOCX), Excel (XLSX), and other formats.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install advanced-office-tool
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Use `ServerAgent` for all document operations. Import once, call methods on any file path.
14
+
15
+ ```python
16
+ from advanced_office_tool import ServerAgent
17
+
18
+ agent = ServerAgent()
19
+ ```
20
+
21
+ ### DOCX Translation
22
+
23
+ ```python
24
+ result = agent.translate_file(
25
+ "manual.docx",
26
+ target_language="en", # "en", "zh", "auto", etc.
27
+ target_format="{translated}" # or "{original}" or "{original}{translated}"
28
+ )
29
+ print(result["output_file_path"])
30
+ # → /home/ovos/.hermes/skills/office-tool/uploads/manual_en.docx
31
+ ```
32
+
33
+ ### DOCX Merge (with auto CRC-32 repair)
34
+
35
+ ```python
36
+ from advanced_office_tool import DocxAgent, SafeDocument
37
+
38
+ # Merge with auto repair for corrupted files
39
+ agent = DocxAgent()
40
+ agent.load_document("chapter1.docx")
41
+ agent.merge_docx(["chapter2.docx", "chapter3.docx"], "merged.docx")
42
+ ```
43
+
44
+ `SafeDocument` transparently repairs bad CRC-32 ZIP checksums:
45
+
46
+ ```python
47
+ from advanced_office_tool import SafeDocument
48
+ from docx import Document
49
+
50
+ # Broken DOCX auto-repairs on first access
51
+ doc = SafeDocument("corrupted.docx")
52
+ for p in doc.paragraphs:
53
+ print(p.text)
54
+ ```
55
+
56
+ ### PDF Conversion
57
+
58
+ ```python
59
+ # PDF → DOCX
60
+ result = agent.pdf_to_docx("scan.pdf")
61
+ print(result["content"])
62
+
63
+ # DOCX → PDF
64
+ result = agent.docx_to_pdf("report.docx")
65
+ print(result["content"])
66
+
67
+ # XLSX → PDF
68
+ result = agent.xlsx_to_pdf("data.xlsx")
69
+ print(result["content"])
70
+
71
+ # Images → PDF
72
+ result = agent.pngs_to_pdf(["img1.png", "img2.png"])
73
+ print(result["output_pdf_path"])
74
+
75
+ # PDF → PNG images
76
+ images = agent.pdf_to_png("document.pdf", dpi=300)
77
+ print(images) # ["/path/to/page0.png", ...]
78
+ ```
79
+
80
+ ### PDF Stamp
81
+
82
+ ```python
83
+ result = agent.add_stamp_to_pdf(
84
+ "contract.pdf",
85
+ position="80,80", # top-right corner
86
+ scale="1.5", # stamp size multiplier
87
+ stamp_image="./stamp.png" # stamp image path
88
+ )
89
+ print(result["output_pdf_after_stamp"])
90
+ ```
91
+
92
+ ### Excel Price Adjustment
93
+
94
+ ```python
95
+ result = agent.adjust_price_in_excel(
96
+ "quote.xlsx",
97
+ price_multiplier="1.3/6.9", # unit_price * multiplier / divisor
98
+ decimal_places="0" # round to 0 decimals
99
+ )
100
+ print(result["output_file_path"])
101
+ ```
102
+
103
+ ### Template Rendering
104
+
105
+ ```python
106
+ result = agent.render_docx_template(
107
+ "template.docx",
108
+ obj={"name": "Company A", "amount": 50000},
109
+ output_path="output.docx"
110
+ )
111
+ ```
112
+
113
+ ### PDF Merge to DOCX (N images per page)
114
+
115
+ ```python
116
+ result = agent.merge_pdfs_folder_to_docx_vertical(
117
+ pdf_folder="./invoices", # folder with PDF files
118
+ number_in_page=2 # 2 PDF pages per DOCX page
119
+ )
120
+ print(result["output_file_path"])
121
+ ```
122
+
123
+ ### Unzip
124
+
125
+ ```python
126
+ result = agent.uncompress_zip("archive.zip", "mt123456")
127
+ print(result["message"])
128
+ ```
129
+
130
+ ### Available Classes
131
+
132
+ | Class | Description |
133
+ |-------|-------------|
134
+ | `ServerAgent` | Main orchestrator — PDF, Excel, DOCX, translation, templates |
135
+ | `DocxAgent` | DOCX paragraph/table translation and manipulation |
136
+ | `ExcelOperator` | XLSX merge, formula, style, image manipulation |
137
+ | `TranslateAgent` | pygtrans batch translate with terminology protection |
138
+ | `SafeDocument` | Auto-repair DOCX files with bad CRC-32 checksums |
139
+ | `OdooAgent` | Odoo ERP integration |
140
+
141
+ ## License
142
+
143
+ Apache-2.0
@@ -0,0 +1,36 @@
1
+ """Advanced Office Tool — complete package.
2
+
3
+ Exports the main classes used throughout the skill:
4
+ - AdvancedOfficeTool (core skeleton)
5
+ - ServerAgent (PDF/Excel/DOCX/translation orchestrator)
6
+ - DocxAgent (DOCX paragraph/table translation)
7
+ - ExcelOperator (XLSX merge, formula, style, image)
8
+ - TranslateAgent (pygtrans batch translate + terminology protection)
9
+ - SafeDocument / repair_docx (DOCX CRC-32 auto-repair)
10
+ - OdooAgent (Odoo ERP integration)
11
+ """
12
+ __version__ = "1.1.1"
13
+
14
+ from advanced_office_tool.core import AdvancedOfficeTool
15
+ from advanced_office_tool.serveragent import ServerAgent
16
+ from advanced_office_tool.docxagent import DocxAgent, MyFilter, get_function_names
17
+ from advanced_office_tool.excelOperator import ExcelOperator
18
+ from advanced_office_tool.translateagent import TranslateAgent
19
+ from advanced_office_tool.dotdict import DotDict
20
+ from advanced_office_tool.docx_crc_repair import SafeDocument, repair_docx, DOCX_REPAIR_CACHE
21
+ from advanced_office_tool.odoolib import OdooAgent
22
+
23
+ __all__ = [
24
+ "AdvancedOfficeTool",
25
+ "ServerAgent",
26
+ "DocxAgent",
27
+ "MyFilter",
28
+ "get_function_names",
29
+ "ExcelOperator",
30
+ "TranslateAgent",
31
+ "DotDict",
32
+ "SafeDocument",
33
+ "repair_docx",
34
+ "DOCX_REPAIR_CACHE",
35
+ "OdooAgent",
36
+ ]
@@ -0,0 +1,73 @@
1
+ """Advanced office document processing toolkit.
2
+
3
+ Supports DOCX, XLSX, and other office document formats.
4
+ """
5
+
6
+
7
+ class AdvancedOfficeTool:
8
+ """Main class for office document processing.
9
+
10
+ Supports reading, writing, and transforming
11
+ Word (DOCX) and Excel (XLSX) documents.
12
+ """
13
+
14
+ def __init__(self, config: dict | None = None):
15
+ """Initialize the office tool.
16
+
17
+ Args:
18
+ config: Optional configuration dictionary.
19
+ """
20
+ self.config = config or {}
21
+
22
+ def translate_docx(self, input_path: str, output_path: str,
23
+ source_lang: str = "zh", target_lang: str = "en") -> str:
24
+ """Translate a DOCX document from source to target language.
25
+
26
+ Args:
27
+ input_path: Path to the input DOCX file.
28
+ output_path: Path for the output DOCX file.
29
+ source_lang: Source language code (e.g., 'zh', 'en').
30
+ target_lang: Target language code (e.g., 'en', 'zh').
31
+
32
+ Returns:
33
+ Path to the translated output file.
34
+ """
35
+ raise NotImplementedError("Document translation requires a translation backend")
36
+
37
+ def neutralize_docx(self, input_path: str, output_path: str) -> str:
38
+ """Neutralize a DOCX document — remove supplier/brand information.
39
+
40
+ Args:
41
+ input_path: Path to the input DOCX file.
42
+ output_path: Path for the output DOCX file.
43
+
44
+ Returns:
45
+ Path to the neutralized output file.
46
+ """
47
+ raise NotImplementedError("Document neutralization requires brand removal logic")
48
+
49
+ def generate_quote(self, template_path: str, data: dict,
50
+ output_path: str) -> str:
51
+ """Generate a quote/pricing document from template and data.
52
+
53
+ Args:
54
+ template_path: Path to the template file.
55
+ data: Dictionary of data to fill into the template.
56
+ output_path: Path for the output file.
57
+
58
+ Returns:
59
+ Path to the generated output file.
60
+ """
61
+ raise NotImplementedError("Quote generation requires template rendering")
62
+
63
+ def process_xlsx(self, input_path: str, operations: list) -> str:
64
+ """Process an XLSX workbook with specified operations.
65
+
66
+ Args:
67
+ input_path: Path to the input XLSX file.
68
+ operations: List of operations (merge, transform, etc.).
69
+
70
+ Returns:
71
+ Path to the processed output file.
72
+ """
73
+ raise NotImplementedError("XLSX processing requires operation definitions")