-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathodt_analyzer_cli.py
More file actions
75 lines (65 loc) · 2.56 KB
/
odt_analyzer_cli.py
File metadata and controls
75 lines (65 loc) · 2.56 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import tkinter as tk
from tkinter import filedialog
from pathlib import Path
from main import extract_tables_with_metadata, calculate_table_statistics, find_tables_with_keyword,copy_table_to_clipboard
import datetime
import webbrowser
def select_odt_file():
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(
title="Wähle eine ODT-Datei",
filetypes=[("ODT Files", "*.odt")]
)
return file_path
def generate_html_report(odt_path, output_html_path):
tables = extract_tables_with_metadata(odt_path)
stats = calculate_table_statistics(odt_path)
html_lines = [f"""
<html>
<head>
<meta charset="utf-8">
<title>ODT-Analyse: {Path(odt_path).name}</title>
<style>
body {{ font-family: Arial, sans-serif; margin: 2em; }}
table {{ border-collapse: collapse; width: 100%; margin-bottom: 2em; }}
th, td {{ border: 1px solid #ccc; padding: 8px; text-align: left; }}
th {{ background-color: #f2f2f2; }}
h2 {{ margin-top: 2em; }}
</style>
</head>
<body>
<h1>ODT-Analyse: {Path(odt_path).name}</h1>
<p>Erstellt am: {datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S')}</p>
<h2>Übersicht</h2>
<ul>
<li>Gesamte Tabellen: {stats['total_tables']}</li>
<li>Gesamte Zeilen: {stats['total_rows']}</li>
<li>Gesamte Zellen: {stats['total_cells']}</li>
<li>Leere Zellen: {stats['empty_cells']}</li>
<li>Tabellen mit Header: {stats['tables_with_headers']}</li>
</ul>
"""]
for table in tables:
html_lines.append(f"<h2>Tabelle: {table['name']}</h2>")
html_lines.append("<table>")
for row in table['rows']:
html_lines.append("<tr>")
for cell in row['cells']:
content = cell['content'].replace("\n", "<br>")
html_lines.append(f"<td>{content}</td>")
html_lines.append("</tr>")
html_lines.append("</table>")
html_lines.append("</body></html>")
with open(output_html_path, "w", encoding="utf-8") as f:
f.write("\n".join(html_lines))
print(f"✅ HTML-Report erstellt: {output_html_path}")
webbrowser.open("file://" + str(output_html_path.absolute()))
if __name__ == "__main__":
odt_file = select_odt_file()
if not odt_file:
print("❌ Keine Datei ausgewählt.")
else:
output_file = Path(odt_file).with_suffix(".html")
generate_html_report(odt_file, output_file)
copy_table_to_clipboard(odt_file)