Python Forum

Full Version: How can I copy and paste data from text file into an Excel sheet?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am trying to automate a process that basically reads in values from text files into certain excel cells. I have a template in excel that will read data from various sheets under certain names. For example, the template will read in data from "Video scores". Video scores is a .txt file that I copy and paste into excel. There are 5 different text files used in each project so it gets tedious after a while and when there are a lot of projects to complete.

How can I import or copy and paste these .txt files into excel to a specified sheet? I have been using openpyxl for the other parts of this project, but I am open to using another library if it can't be done with openpxl.

I've also tried opening and reading a file, but I couldn't figure out how to do what I want with that either. I have found a list of all the files I need, its just a matter of getting them into excel.

Here is a sample of the .txt file: https://pastebin.com/FUvH6TbM

One thing I have tried to do is user pyperclip to open and copy the text file. I have that saved to a variable, so if I could somehow open excel and hit "paste" it would format fine.

If I were to manually copy all of the .txt file and paste it directly into excel, it would format absolutely perfectly. I just dont know how I can do this with Python.

Thanks in advance for anyone who helps.
Is this the original file?
if so you have a problem, The file you posted to pastebin is space delimited, and it looks like a random number of spaces separates fields.

Is this the way the original file is, or are there tabs (or some other delimiter)?

if tabs (or other unique delimiter) you can treat the file as csv, import directly into excel
(Mar-18-2020, 10:53 PM)Larz60+ Wrote: [ -> ]Is this the original file?
if so you have a problem, The file you posted to pastebin is space delimited, and it looks like a random number of spaces separates fields.

Is this the way the original file is, or are there tabs (or some other delimiter)?

if tabs (or other unique delimiter) you can treat the file as csv, import directly into excel

Hey thanks for the reply. For whatever reason its formatted weird in pastebin. The .txt file is formatted correctly and when I manually copy and paste it into excel, it also is pasted in correctly.

I tried converting it to a .csv and importing it that way but it didnt work right. How can I do this?
the question is about the delimiter. what is it?

just attach a portion of the text file here.
instead of replying directly below post, choose New Reply button
from there you can add attachment.
Sorry, im not sure how to attach a file. Here is the .txt file : https://file.io/eDaZIF
bad link
if you read the rest of my post, I explained how to attach a file
Hey Larz,

I did read your reply, im not sure if I am just being stupid or blind, but I cant find it Sad.

I can see link, image and code inserts, but not for a file an attachment. Here is what i see [Image: 6zBPWo8]

My apologies, its probably staring at me dead in the face! Anyways, i've uploaded that file to the cloud if you wanted to try and download it on your own computer here.

Sorry again! Hope that link is a better one and thanks a million for your help.
use New Reply button when responding
it has attachment button or
correct your file link so can download
@Larz - they are using New replay

@IrishOrigi, note that currently you don't have permission to post attachments.

https://python-forum.io/misc.php?action=help&hid=31
Ahh, that would explain it!
Pages: 1 2