KLASSA åtgärder excel dokument till docx file
A downloadable tool
Exporterar text och rubriker gällande krav som uppfylls delvis eller uppfyller inte till docx format för att spara tid med att skapa rapporter till systemadministratör.
Beroenden
Behöver docx, openpyxl och tkinter moduler för att fungera.
Source code:
import os
from openpyxl import load_workbook
from docx import Document
from docx.shared import Inches
import tkinter as tk
from tkinter import filedialog
def export_data():
# Load the workbook and select the worksheet
wb = load_workbook(filename.get())
ws = wb.active
# Create a new Word document with the same filename as the Excel file
doc = Document()
doc_filename = os.path.splitext(filename.get())[0] + ".docx"
# Iterate through the rows in the worksheet
for row in ws.iter_rows(min_row=5):
krav = row[0].value
svar = row[1].value
kommentar = row[2].value
# Only export rows with svar values of 'Uppfyller delvis' or 'Uppfyller inte'
if svar in ['Uppfyller delvis', 'Uppfyller inte']:
# Add the krav, svar, and kommentar to the Word document
doc.add_heading(krav, level=1)
doc.add_paragraph(f"Svar: {svar}")
if kommentar:
doc.add_paragraph(f"Kommentar: {kommentar}")
doc.add_page_break()
# Save the Word document
doc.save(doc_filename)
output_label.config(text=f"Data exported to {doc_filename}")
def browse_input_file():
input_file = filedialog.askopenfilename()
filename.set(input_file)
# Create the main window
root = tk.Tk()
root.title("Excel to Word Exporter")
# Create input file label and entry
filename = tk.StringVar()
input_label = tk.Label(root, text="Input file:")
input_label.grid(row=0, column=0, padx=5, pady=5)
input_entry = tk.Entry(root, textvariable=filename)
input_entry.grid(row=0, column=1, padx=5, pady=5)
# Create browse button for input file
browse_button = tk.Button(root, text="Browse", command=browse_input_file)
browse_button.grid(row=0, column=2, padx=5, pady=5)
# Create export button
export_button = tk.Button(root, text="Export Data", command=export_data)
export_button.grid(row=1, column=0, columnspan=2, padx=5, pady=5)
# Create output label
output_label = tk.Label(root, text="")
output_label.grid(row=2, column=0, columnspan=3, padx=5, pady=5)
# Run the GUI
root.mainloop()
Status | Released |
Category | Tool |
Author | ArchiveTools |
Leave a comment
Log in with itch.io to leave a comment.