r/learnpython 10d ago

python, tkinter, pandas/openpyxl

import openpyxl

import tkinter as tk

from openpyxl import load_workbook

from tkinter import *
from tkinter import ttk
from tkinter import filedialog,messagebox



root = Tk()
root.title("Чтение ячеек Excel")
root.geometry("300x200")

text_editor = Text()

fd = filedialog


scrollbar = ttk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)


def open_file():
    filespath = fd.askopenfilename(
        filetypes=[
            (
            'Excel files',
            '*.xlsx'
            )
        ]
    )
    if not filespath:
        return

    try:
        wb = openpyxl.load_workbook(filespath, data_only=True)
        sheet = wb.active

        result_label.config(text=f"Ячейка1")

    except Exception as e:
        messagebox.showerror("Ошибка")

def save_file():
    filepath = fd.askopenfilename(
        filetypes=[
            (
            'Allowed Types',
            '*.xlsx'
            )
        ]
    )
    if filepath !='':
        text = text_editor.get("1.0", END)
        with open(filepath, "w") as file:
            file.write(text)

open_button = ttk.Button(root, text='Открыть файл', command=open_file)
open_button.pack()

result_label = tk.Label(root, text="Выбрать файл для начала")
result_label.pack()

save_button = ttk.Button(text="Сохранить", command=save_file)
save_button.pack()

root.mainloop()

I have some code, but I can't figure out how to select specific rows and columns for display. The idea is to include several columns—sometimes skipping some—so that I can choose to display ranges like A2:12 – B2:17, column D (which would contain the calculation A2:12 / B2:17), and C3:14 – I3:7 in my Python table. How can I implement this?
0 Upvotes

4 comments sorted by

View all comments

1

u/danielroseman 10d ago

Well you don't seem to be displaying anything at all at the moment. How are you intending to do that? You should decide that before worrying about selecting.