0

I am trying to copy a list in a specific spot of an Excel file, and I want it line by line. I am not sure where to start. Any ideas?

import pyperclip

# this makes the list from a txt file.
blof = open("blacklist_list.txt", "r")

list_of_sn = []
for line in blof:
    stripped_line = line.strip()
    line_list = stripped_line.split()
    list_of_sn.append(line_list)
blof.close()
# i can use print(list_of_sn) to see what the txt file shows

# this will put this in the clipboard very handy when i need
# to copy something but need to paste it later tho.
pyperclip.copy(str(list_of_sn))
paste = pyperclip.paste()

with open("test.xlsx", "w") as g:
    g.write(paste)
Laurent
  • 12,287
  • 7
  • 21
  • 37
  • `'new.txt'` doesn't look like an Excel file. Are you actually working with Excel? – BigBen Dec 29 '21 at 20:43
  • sorry forgot to take out that. was trying it in a txt file first to see if it paste in a txt file. but i get a error when i put it a excel sheet. ```excel cannot open the file 'text.xlsx because the file format or file extension is not valid. verify that the file has not been corrupted and that the file extension match the format of the file. fix it – charles rushin Dec 29 '21 at 20:46
  • going to try with pandas to see if that works – charles rushin Dec 29 '21 at 20:54

0 Answers0