-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdebug_rels.py
More file actions
55 lines (41 loc) · 1.52 KB
/
debug_rels.py
File metadata and controls
55 lines (41 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import traceback
from docx import Document
def debug_relationships(docx_path):
print(f"Loading: {docx_path}")
try:
doc = Document(docx_path)
except Exception as e:
print(f"CRITICAL: Failed to load document: {e}")
traceback.print_exc()
return
print("\n--- Document Relationships ---")
rels = doc.part.rels
# Standard Comments RelType
COMMENTS_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
found_comments = False
for rel_id, rel in rels.items():
print(f"ID: {rel_id}")
print(f" Type: {rel.reltype}")
try:
# Attempt to access the target part.
# This triggers the actual loading/parsing of the XML part.
part = rel.target_part
print(f" Target Part: {part}")
if hasattr(part, "partname"):
print(f" Partname: {part.partname}")
if rel.reltype == COMMENTS_TYPE:
found_comments = True
print(" [!] FOUND COMMENTS PART")
except Exception as e:
print(f" [X] ERROR loading target part: {e}")
traceback.print_exc()
if not found_comments:
print("\n[!] WARNING: No relationship matching COMMENTS_TYPE found.")
else:
print("\n[OK] Comments relationship found.")
if __name__ == "__main__":
target = r"C:\Users\mikko\workspace\docx-md-docx\test.docx"
if len(sys.argv) > 1:
target = sys.argv[1]
debug_relationships(target)