thenpc
thenpc

Reputation: 1

Python script that allows me to load multiple cells from a spreadsheet that are in the clipboard and paste each individual cell one at a time

I'm trying to copy multiple cells from a table of a document and I want to be able to press a hotkey that will act as a paste function, pasting one cell at a time starting with the first.

data
Cell 1
Cell 2
Cell 3

Hotkey paste Cell 1, Hotkey paste Cell 2, Hotkey paste Cell 3

import pandas as pd
import keyboard
import pyperclip

df = []
var = 0

def load_cells():
    print("Load Hotkey pressed")
    global df, var
    df = pd.read_clipboard(sep=",", names=["vals"])
    var = len(df)
    return df
    
def paste_cell():
    print("paste Hotkey pressed")
    global df, var
    if var < len(df):
        pyperclip.copy(str(df.iloc[var, 0]))
        var += 1

keyboard.add_hotkey('ctrl+alt+x', load_cells)
keyboard.add_hotkey('ctrl+alt+z', paste_cell)   
keyboard.add_hotkey('ctrl+alt+a', print(df)) 

My current error is "TypeError: 'NoneType' object is not callable" but I've be struggling with many versions of this and think I think I'm not headed in the right direction.

Print functions added to attempt to locate errors but I haven't been able to get anything loaded to the dataframe.

Help appreciated.

Upvotes: 0

Views: 67

Answers (1)

Azur_Was_here
Azur_Was_here

Reputation: 80

I can't comment yet because I don't have fifty rep. But are you saying that when you press a hotkey you get a TypeError? If so that means the function you are trying to call is not defined, what about when you press the hotkey that calls print(df)? I'll edit my answer once I get some more information.

Upvotes: 0

Related Questions