docconvert-local 2.0.0__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.
- docconvert_local-2.0.0/LICENSE +21 -0
- docconvert_local-2.0.0/PKG-INFO +253 -0
- docconvert_local-2.0.0/README.md +212 -0
- docconvert_local-2.0.0/docconvert/__init__.py +15 -0
- docconvert_local-2.0.0/docconvert/chunkers/__init__.py +5 -0
- docconvert_local-2.0.0/docconvert/chunkers/table_chunker.py +10 -0
- docconvert_local-2.0.0/docconvert/cleaners/__init__.py +7 -0
- docconvert_local-2.0.0/docconvert/cleaners/base.py +10 -0
- docconvert_local-2.0.0/docconvert/cleaners/word_md.py +250 -0
- docconvert_local-2.0.0/docconvert/cli.py +133 -0
- docconvert_local-2.0.0/docconvert/config.py +23 -0
- docconvert_local-2.0.0/docconvert/controller/__init__.py +5 -0
- docconvert_local-2.0.0/docconvert/controller/conversion_controller.py +369 -0
- docconvert_local-2.0.0/docconvert/converters/__init__.py +11 -0
- docconvert_local-2.0.0/docconvert/converters/base.py +31 -0
- docconvert_local-2.0.0/docconvert/converters/doc.py +84 -0
- docconvert_local-2.0.0/docconvert/converters/excel.py +634 -0
- docconvert_local-2.0.0/docconvert/converters/word.py +129 -0
- docconvert_local-2.0.0/docconvert/exporters/__init__.py +22 -0
- docconvert_local-2.0.0/docconvert/exporters/base.py +16 -0
- docconvert_local-2.0.0/docconvert/exporters/html.py +15 -0
- docconvert_local-2.0.0/docconvert/exporters/json_exporter.py +16 -0
- docconvert_local-2.0.0/docconvert/exporters/markdown.py +15 -0
- docconvert_local-2.0.0/docconvert/gui/__init__.py +5 -0
- docconvert_local-2.0.0/docconvert/gui/app.py +997 -0
- docconvert_local-2.0.0/docconvert/logger.py +36 -0
- docconvert_local-2.0.0/docconvert/models/__init__.py +9 -0
- docconvert_local-2.0.0/docconvert/models/models.py +24 -0
- docconvert_local-2.0.0/docconvert/parsers/__init__.py +5 -0
- docconvert_local-2.0.0/docconvert/parsers/semantic.py +10 -0
- docconvert_local-2.0.0/docconvert/py.typed +0 -0
- docconvert_local-2.0.0/docconvert/utils/__init__.py +21 -0
- docconvert_local-2.0.0/docconvert/utils/utils.py +128 -0
- docconvert_local-2.0.0/docconvert_local.egg-info/PKG-INFO +253 -0
- docconvert_local-2.0.0/docconvert_local.egg-info/SOURCES.txt +47 -0
- docconvert_local-2.0.0/docconvert_local.egg-info/dependency_links.txt +1 -0
- docconvert_local-2.0.0/docconvert_local.egg-info/entry_points.txt +2 -0
- docconvert_local-2.0.0/docconvert_local.egg-info/requires.txt +22 -0
- docconvert_local-2.0.0/docconvert_local.egg-info/top_level.txt +1 -0
- docconvert_local-2.0.0/pyproject.toml +56 -0
- docconvert_local-2.0.0/setup.cfg +4 -0
- docconvert_local-2.0.0/tests/test_cleaners.py +453 -0
- docconvert_local-2.0.0/tests/test_controller.py +701 -0
- docconvert_local-2.0.0/tests/test_excel_converter.py +874 -0
- docconvert_local-2.0.0/tests/test_exporters.py +95 -0
- docconvert_local-2.0.0/tests/test_logger.py +55 -0
- docconvert_local-2.0.0/tests/test_models.py +44 -0
- docconvert_local-2.0.0/tests/test_utils.py +238 -0
- docconvert_local-2.0.0/tests/test_word_doc_sheets.py +225 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DocConvert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docconvert-local
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Clean Excel & Word → Markdown for RAG pipelines. Works 100% offline — no API keys, no cloud upload.
|
|
5
|
+
Author: DocConvert Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/leop017/DocConvert
|
|
8
|
+
Project-URL: BugTracker, https://github.com/leop017/DocConvert/issues
|
|
9
|
+
Keywords: document,conversion,excel,word,markdown
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Office/Business :: Office Suites
|
|
19
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
20
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: python-docx>=1.1.0
|
|
25
|
+
Requires-Dist: openpyxl>=3.1.0
|
|
26
|
+
Requires-Dist: pandas>=2.0.0
|
|
27
|
+
Requires-Dist: mammoth>=1.6.0
|
|
28
|
+
Requires-Dist: beautifulsoup4>=4.12.0
|
|
29
|
+
Requires-Dist: markdownify>=0.11.0
|
|
30
|
+
Requires-Dist: xlrd>=2.0.0
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: mypy>=1.0; extra == "test"
|
|
33
|
+
Requires-Dist: xlwt; extra == "test"
|
|
34
|
+
Provides-Extra: doc
|
|
35
|
+
Requires-Dist: textract>=1.6.0; platform_system != "Windows" and extra == "doc"
|
|
36
|
+
Provides-Extra: build
|
|
37
|
+
Requires-Dist: pyinstaller>=6.0; extra == "build"
|
|
38
|
+
Provides-Extra: all
|
|
39
|
+
Requires-Dist: docconvert-local[build,doc,test]; extra == "all"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# DocConvert
|
|
43
|
+
|
|
44
|
+
> Clean Markdown & structured data from Excel & Word — built for RAG pipelines and LLM workflows.
|
|
45
|
+
> Works 100% offline. No API keys. No data leaves your machine.
|
|
46
|
+
|
|
47
|
+
[](https://pypi.org/project/docconvert-local/)
|
|
48
|
+
[](https://opensource.org/licenses/MIT)
|
|
49
|
+
[](https://www.python.org/)
|
|
50
|
+
[](https://github.com/leop017/DocConvert/actions)
|
|
51
|
+
[](https://pepy.tech/project/docconvert-local)
|
|
52
|
+
[](https://github.com/leop017/DocConvert/stargazers)
|
|
53
|
+
|
|
54
|
+
## Why DocConvert
|
|
55
|
+
|
|
56
|
+
Most document-to-Markdown tools convert the file — they don't **clean** it. Raw outputs are full of page numbers, duplicate headers, and whitespace noise that eats your context window and dilutes retrieval quality.
|
|
57
|
+
|
|
58
|
+
DocConvert was built for people who feed documents into LLMs and need every token to count.
|
|
59
|
+
|
|
60
|
+
| Feature | DocConvert | MarkItDown | Pandas + python-docx |
|
|
61
|
+
| ------------------------------------ | :-------------------: | :--------: | :------------------: |
|
|
62
|
+
| Legacy `.doc` support | ✅ | ❌ | ❌ |
|
|
63
|
+
| Excel merged cells (rowspan/colspan) | ✅ | ⚠️ | Manual |
|
|
64
|
+
| Configurable cleaning pipeline | ✅ 4 rules, toggle any | ❌ | ❌ |
|
|
65
|
+
| Batch + specific sheet selection | ✅ | ✅ | ❌ |
|
|
66
|
+
| Desktop GUI (no terminal needed) | ✅ | ❌ | ❌ |
|
|
67
|
+
| PDF / PPT / audio support | ❌ | ✅ | ❌ |
|
|
68
|
+
| MCP server / Claude integration | ❌ | ✅ | ❌ |
|
|
69
|
+
| 100% offline, no cloud dependency | ✅ | ✅ | ✅ |
|
|
70
|
+
|
|
71
|
+
**Choose DocConvert if:** you work with Excel/Word documents inside an organization, need legacy `.doc` support, or want a configurable cleaning pipeline before feeding docs into a RAG system.
|
|
72
|
+
|
|
73
|
+
**Choose MarkItDown if:** you need PDF, PPT, images, or audio conversion, or want MCP/Claude Desktop integration out of the box.
|
|
74
|
+
|
|
75
|
+
## Use Cases
|
|
76
|
+
|
|
77
|
+
* **RAG ingestion** — clean Excel financial reports and Word contracts into Markdown ready for embedding
|
|
78
|
+
|
|
79
|
+
* **LLM context prep** — strip page numbers, duplicates, and noise before chunking
|
|
80
|
+
|
|
81
|
+
* **Offline compliance** — convert sensitive documents without uploading to any cloud service
|
|
82
|
+
|
|
83
|
+
* **Batch automation** — convert entire folders of reports into a structured directory
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install docconvert-local
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Optional extras:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Legacy .doc support (Linux / macOS only)
|
|
95
|
+
pip install docconvert-local[doc]
|
|
96
|
+
|
|
97
|
+
# Full feature set including build tools
|
|
98
|
+
pip install docconvert-local[all]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Quick Start
|
|
102
|
+
|
|
103
|
+
### GUI (interactive)
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
python main.py
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### CLI (batch / scripting)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Single file → clean Markdown
|
|
113
|
+
python main.py convert input.xlsx --format md
|
|
114
|
+
|
|
115
|
+
# Batch convert with enhanced cleaning (recommended for RAG)
|
|
116
|
+
python main.py convert input.docx --format md --enhanced
|
|
117
|
+
|
|
118
|
+
# Multiple files → HTML into output/
|
|
119
|
+
python main.py convert file1.xlsx file2.docx --format html -o ./output
|
|
120
|
+
|
|
121
|
+
# Pick specific Excel sheets → JSON
|
|
122
|
+
python main.py convert input.xlsx --format json --sheet "Sheet1" --sheet "Sheet2"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Python API
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from docconvert.controller import ConversionController
|
|
129
|
+
|
|
130
|
+
controller = ConversionController()
|
|
131
|
+
results = controller.convert_files(
|
|
132
|
+
files=["input.xlsx", "report.docx"],
|
|
133
|
+
output_fmt="md",
|
|
134
|
+
enhanced_md=True,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
for name, path, error in results:
|
|
138
|
+
if error:
|
|
139
|
+
print(f"Failed: {name} – {error}")
|
|
140
|
+
else:
|
|
141
|
+
print(f"OK: {name} → {path}")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### RAG Pipeline Integration
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from docconvert.controller import ConversionController
|
|
148
|
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
149
|
+
|
|
150
|
+
# Convert and clean
|
|
151
|
+
controller = ConversionController()
|
|
152
|
+
docs = []
|
|
153
|
+
for name, path, error in controller.convert_files(
|
|
154
|
+
files=["contracts/*.docx"],
|
|
155
|
+
output_fmt="md",
|
|
156
|
+
enhanced_md=True,
|
|
157
|
+
):
|
|
158
|
+
if not error:
|
|
159
|
+
with open(path) as f:
|
|
160
|
+
docs.append(f.read())
|
|
161
|
+
|
|
162
|
+
# Chunk and embed — noise already removed
|
|
163
|
+
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
|
|
164
|
+
chunks = splitter.split_text("\n".join(docs))
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Output Preview
|
|
168
|
+
|
|
169
|
+
**Input** — an Excel sheet with merged cells:
|
|
170
|
+
|
|
171
|
+
| Region | Q1 | Q2 |
|
|
172
|
+
| :-------: | :-: | :-: |
|
|
173
|
+
| **North** | 120 | 150 |
|
|
174
|
+
| **South** | 90 | 200 |
|
|
175
|
+
|
|
176
|
+
→ **Markdown output** (auto-cleaned):
|
|
177
|
+
|
|
178
|
+
```markdown
|
|
179
|
+
## Region Q1 Q2
|
|
180
|
+
North 120 150
|
|
181
|
+
South 90 200
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
→ **JSON output**:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"Region": ["North", "South"],
|
|
189
|
+
"Q1": [120, 90],
|
|
190
|
+
"Q2": [150, 200]
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Smart Cleaning Pipeline
|
|
195
|
+
|
|
196
|
+
The `--enhanced` flag runs a configurable cleaning pass that removes common document noise before output. Each rule is independently toggleable:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from docconvert.config import AppConfig
|
|
200
|
+
|
|
201
|
+
config = AppConfig(
|
|
202
|
+
cleaning_rules={
|
|
203
|
+
"remove_page_numbers": True, # strips 1, 2, 3… and "Page X of Y"
|
|
204
|
+
"remove_duplicate_headers": True, # deduplicates repeating section titles
|
|
205
|
+
"remove_empty_lines": True, # collapses excessive blank lines
|
|
206
|
+
"normalize_spaces": True, # single-spaces text, preserves tables
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
All four rules are enabled by default with `--enhanced`. Set any to `False` to keep the raw output.
|
|
212
|
+
|
|
213
|
+
## Features
|
|
214
|
+
|
|
215
|
+
* **Excel** — Sheet selection, merged cells (rowspan/colspan), HTML / Markdown / JSON
|
|
216
|
+
|
|
217
|
+
* **Word** — `.docx` via `python-docx` + `mammoth`, legacy `.doc` via `textract`
|
|
218
|
+
|
|
219
|
+
* **Smart Markdown** — Removes page numbers, duplicate headers, collapses blank lines; all rules configurable
|
|
220
|
+
|
|
221
|
+
* **GUI** — Tkinter desktop app with file list, preview, progress bar, overwrite protection
|
|
222
|
+
|
|
223
|
+
* **CLI** — One-line batch conversion via argparse
|
|
224
|
+
|
|
225
|
+
* **Python API** — Programmatic control with full type hints
|
|
226
|
+
|
|
227
|
+
* **Executable releases** — Download a standalone `.exe` for Windows / macOS / Linux, no Python install needed
|
|
228
|
+
|
|
229
|
+
## Releases (no Python needed)
|
|
230
|
+
|
|
231
|
+
Standalone executables for Windows, macOS, and Linux are built automatically on each tag push. Download them from [Releases](https://github.com/leop017/DocConvert/releases).
|
|
232
|
+
|
|
233
|
+
## Project Layout
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
docconvert/
|
|
237
|
+
converters/ # Excel / Word / .doc readers
|
|
238
|
+
cleaners/ # Markdown cleaning pipeline
|
|
239
|
+
exporters/ # HTML / Markdown / JSON output
|
|
240
|
+
controller/ # Orchestration, async, overwrite checks
|
|
241
|
+
gui/ # Tkinter desktop app
|
|
242
|
+
parsers/, chunkers/ # Extension points
|
|
243
|
+
tests/
|
|
244
|
+
main.py # GUI / CLI entry point
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Contributing
|
|
248
|
+
|
|
249
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
MIT
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# DocConvert
|
|
2
|
+
|
|
3
|
+
> Clean Markdown & structured data from Excel & Word — built for RAG pipelines and LLM workflows.
|
|
4
|
+
> Works 100% offline. No API keys. No data leaves your machine.
|
|
5
|
+
|
|
6
|
+
[](https://pypi.org/project/docconvert-local/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.python.org/)
|
|
9
|
+
[](https://github.com/leop017/DocConvert/actions)
|
|
10
|
+
[](https://pepy.tech/project/docconvert-local)
|
|
11
|
+
[](https://github.com/leop017/DocConvert/stargazers)
|
|
12
|
+
|
|
13
|
+
## Why DocConvert
|
|
14
|
+
|
|
15
|
+
Most document-to-Markdown tools convert the file — they don't **clean** it. Raw outputs are full of page numbers, duplicate headers, and whitespace noise that eats your context window and dilutes retrieval quality.
|
|
16
|
+
|
|
17
|
+
DocConvert was built for people who feed documents into LLMs and need every token to count.
|
|
18
|
+
|
|
19
|
+
| Feature | DocConvert | MarkItDown | Pandas + python-docx |
|
|
20
|
+
| ------------------------------------ | :-------------------: | :--------: | :------------------: |
|
|
21
|
+
| Legacy `.doc` support | ✅ | ❌ | ❌ |
|
|
22
|
+
| Excel merged cells (rowspan/colspan) | ✅ | ⚠️ | Manual |
|
|
23
|
+
| Configurable cleaning pipeline | ✅ 4 rules, toggle any | ❌ | ❌ |
|
|
24
|
+
| Batch + specific sheet selection | ✅ | ✅ | ❌ |
|
|
25
|
+
| Desktop GUI (no terminal needed) | ✅ | ❌ | ❌ |
|
|
26
|
+
| PDF / PPT / audio support | ❌ | ✅ | ❌ |
|
|
27
|
+
| MCP server / Claude integration | ❌ | ✅ | ❌ |
|
|
28
|
+
| 100% offline, no cloud dependency | ✅ | ✅ | ✅ |
|
|
29
|
+
|
|
30
|
+
**Choose DocConvert if:** you work with Excel/Word documents inside an organization, need legacy `.doc` support, or want a configurable cleaning pipeline before feeding docs into a RAG system.
|
|
31
|
+
|
|
32
|
+
**Choose MarkItDown if:** you need PDF, PPT, images, or audio conversion, or want MCP/Claude Desktop integration out of the box.
|
|
33
|
+
|
|
34
|
+
## Use Cases
|
|
35
|
+
|
|
36
|
+
* **RAG ingestion** — clean Excel financial reports and Word contracts into Markdown ready for embedding
|
|
37
|
+
|
|
38
|
+
* **LLM context prep** — strip page numbers, duplicates, and noise before chunking
|
|
39
|
+
|
|
40
|
+
* **Offline compliance** — convert sensitive documents without uploading to any cloud service
|
|
41
|
+
|
|
42
|
+
* **Batch automation** — convert entire folders of reports into a structured directory
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install docconvert-local
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Optional extras:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Legacy .doc support (Linux / macOS only)
|
|
54
|
+
pip install docconvert-local[doc]
|
|
55
|
+
|
|
56
|
+
# Full feature set including build tools
|
|
57
|
+
pip install docconvert-local[all]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quick Start
|
|
61
|
+
|
|
62
|
+
### GUI (interactive)
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python main.py
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### CLI (batch / scripting)
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Single file → clean Markdown
|
|
72
|
+
python main.py convert input.xlsx --format md
|
|
73
|
+
|
|
74
|
+
# Batch convert with enhanced cleaning (recommended for RAG)
|
|
75
|
+
python main.py convert input.docx --format md --enhanced
|
|
76
|
+
|
|
77
|
+
# Multiple files → HTML into output/
|
|
78
|
+
python main.py convert file1.xlsx file2.docx --format html -o ./output
|
|
79
|
+
|
|
80
|
+
# Pick specific Excel sheets → JSON
|
|
81
|
+
python main.py convert input.xlsx --format json --sheet "Sheet1" --sheet "Sheet2"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Python API
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from docconvert.controller import ConversionController
|
|
88
|
+
|
|
89
|
+
controller = ConversionController()
|
|
90
|
+
results = controller.convert_files(
|
|
91
|
+
files=["input.xlsx", "report.docx"],
|
|
92
|
+
output_fmt="md",
|
|
93
|
+
enhanced_md=True,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
for name, path, error in results:
|
|
97
|
+
if error:
|
|
98
|
+
print(f"Failed: {name} – {error}")
|
|
99
|
+
else:
|
|
100
|
+
print(f"OK: {name} → {path}")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### RAG Pipeline Integration
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from docconvert.controller import ConversionController
|
|
107
|
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
108
|
+
|
|
109
|
+
# Convert and clean
|
|
110
|
+
controller = ConversionController()
|
|
111
|
+
docs = []
|
|
112
|
+
for name, path, error in controller.convert_files(
|
|
113
|
+
files=["contracts/*.docx"],
|
|
114
|
+
output_fmt="md",
|
|
115
|
+
enhanced_md=True,
|
|
116
|
+
):
|
|
117
|
+
if not error:
|
|
118
|
+
with open(path) as f:
|
|
119
|
+
docs.append(f.read())
|
|
120
|
+
|
|
121
|
+
# Chunk and embed — noise already removed
|
|
122
|
+
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
|
|
123
|
+
chunks = splitter.split_text("\n".join(docs))
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Output Preview
|
|
127
|
+
|
|
128
|
+
**Input** — an Excel sheet with merged cells:
|
|
129
|
+
|
|
130
|
+
| Region | Q1 | Q2 |
|
|
131
|
+
| :-------: | :-: | :-: |
|
|
132
|
+
| **North** | 120 | 150 |
|
|
133
|
+
| **South** | 90 | 200 |
|
|
134
|
+
|
|
135
|
+
→ **Markdown output** (auto-cleaned):
|
|
136
|
+
|
|
137
|
+
```markdown
|
|
138
|
+
## Region Q1 Q2
|
|
139
|
+
North 120 150
|
|
140
|
+
South 90 200
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
→ **JSON output**:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"Region": ["North", "South"],
|
|
148
|
+
"Q1": [120, 90],
|
|
149
|
+
"Q2": [150, 200]
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Smart Cleaning Pipeline
|
|
154
|
+
|
|
155
|
+
The `--enhanced` flag runs a configurable cleaning pass that removes common document noise before output. Each rule is independently toggleable:
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from docconvert.config import AppConfig
|
|
159
|
+
|
|
160
|
+
config = AppConfig(
|
|
161
|
+
cleaning_rules={
|
|
162
|
+
"remove_page_numbers": True, # strips 1, 2, 3… and "Page X of Y"
|
|
163
|
+
"remove_duplicate_headers": True, # deduplicates repeating section titles
|
|
164
|
+
"remove_empty_lines": True, # collapses excessive blank lines
|
|
165
|
+
"normalize_spaces": True, # single-spaces text, preserves tables
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
All four rules are enabled by default with `--enhanced`. Set any to `False` to keep the raw output.
|
|
171
|
+
|
|
172
|
+
## Features
|
|
173
|
+
|
|
174
|
+
* **Excel** — Sheet selection, merged cells (rowspan/colspan), HTML / Markdown / JSON
|
|
175
|
+
|
|
176
|
+
* **Word** — `.docx` via `python-docx` + `mammoth`, legacy `.doc` via `textract`
|
|
177
|
+
|
|
178
|
+
* **Smart Markdown** — Removes page numbers, duplicate headers, collapses blank lines; all rules configurable
|
|
179
|
+
|
|
180
|
+
* **GUI** — Tkinter desktop app with file list, preview, progress bar, overwrite protection
|
|
181
|
+
|
|
182
|
+
* **CLI** — One-line batch conversion via argparse
|
|
183
|
+
|
|
184
|
+
* **Python API** — Programmatic control with full type hints
|
|
185
|
+
|
|
186
|
+
* **Executable releases** — Download a standalone `.exe` for Windows / macOS / Linux, no Python install needed
|
|
187
|
+
|
|
188
|
+
## Releases (no Python needed)
|
|
189
|
+
|
|
190
|
+
Standalone executables for Windows, macOS, and Linux are built automatically on each tag push. Download them from [Releases](https://github.com/leop017/DocConvert/releases).
|
|
191
|
+
|
|
192
|
+
## Project Layout
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
docconvert/
|
|
196
|
+
converters/ # Excel / Word / .doc readers
|
|
197
|
+
cleaners/ # Markdown cleaning pipeline
|
|
198
|
+
exporters/ # HTML / Markdown / JSON output
|
|
199
|
+
controller/ # Orchestration, async, overwrite checks
|
|
200
|
+
gui/ # Tkinter desktop app
|
|
201
|
+
parsers/, chunkers/ # Extension points
|
|
202
|
+
tests/
|
|
203
|
+
main.py # GUI / CLI entry point
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Contributing
|
|
207
|
+
|
|
208
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""DocConvert - 文档转换工具
|
|
2
|
+
|
|
3
|
+
The GUI is imported lazily so CLI / library use (``python main.py convert``
|
|
4
|
+
or ``from docconvert.controller import ConversionController``) does not
|
|
5
|
+
require the Tkinter package.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__all__ = ["DocConvertApp"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def __getattr__(name: str):
|
|
12
|
+
if name == "DocConvertApp":
|
|
13
|
+
from docconvert.gui.app import DocConvertApp
|
|
14
|
+
return DocConvertApp
|
|
15
|
+
raise AttributeError(f"module 'docconvert' has no attribute {name!r}")
|