Python win32COM/pyautogui doesn't show hebrew text

50 Views Asked by At

I'm working on a project where I need a Win32com package to read all open Excel files and display them with a simple GUI using pyautogui (not necessarily pyautogui, any gui package will do). Any file with a Hebrew name doesn't appear in the list.

import tkinter as tk


def get_open_workbooks():
    xl = win32com.client.dynamic.Dispatch("Excel.Application")
    workbooks = xl.Workbooks
    open_workbooks = []
    print(workbooks)
    print(workbooks.Count)

    for i in range(1, workbooks.Count + 1):
        workbook = workbooks.Item(i)
        if workbook.Name:
            open_workbooks.append(workbook.Name)

    return open_workbooks


def create_ui():
    open_workbooks = get_open_workbooks()

    root = tk.Tk()
    root.title("Open Excel Workbooks")
    root.geometry("400x300")  # Set window size

    listbox = tk.Listbox(root)
    listbox.pack(fill=tk.BOTH, expand=True)
    print(open_workbooks)
    for workbook in open_workbooks:
        listbox.insert(tk.END, workbook)

    root.mainloop()


if __name__ == '__main__':
    create_ui()

^^^ This is the code I'm using

The print statements return only the english filenames (in this example it would log "2" and "[filename1],[filename3]"

enter image description here

^^^ This is what it shows when i have 3 workbooks (3 files) open 2 have English file names and one has a Hebrew filename

enter image description here These are the open excel files

1

There are 1 best solutions below

0
ProjectFluffy On

Excel files sometimes open in "protected view" (learn more here) which opens suspicious in a read-only mode and win32com doesn't register these files as open excel files as implemented in the code above.