Python Forum
How can I copy and paste data from text file into an Excel sheet?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I copy and paste data from text file into an Excel sheet?
#11
Quote:Buran: @Larz - they are using New replay

If a post is answered on the same page as the actual post, there's no obvious option available to attach.
It is necessary to click on 'New Reply' button which will bring up a new page with attach option available.

But of course (as you say) if poster doesn't have attach option available, that won't work either.
Reply
#12
Any ideas on what way I can do this?
Reply
#13
You have to give the auto task manager time to change your user group to give you permissions. As of right now your user group is "User" instead of "registered" so you should be good to go now.

As Larz60+ explained - use New Reply button, don't use quick reply form form at the bottom of this page.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#14
Perfect, here is the text file. So I have 5 in total of these text files that I have stored in a list in my code. I was planning on using a for loop for each one which would work fine, its just a matter of finding the code to actually WRITE/COPY & PASTE to the excel sheet! Ive been researching this for over a day and I have absolutely no more ideas on what I can do :(

Attached Files

.txt   example linearity.txt (Size: 2.59 KB / Downloads: 214)
Reply
#15
This will read all into a bunch of lists making them very easy to work with:
import os
import re


# Make sure path is set to current directory
os.chdir(os.path.abspath(os.path.dirname(__file__)))


def read_data(filename):
    with open(filename) as fp:
        lines = fp.read().split('\n')
        for n, line in enumerate(lines):
            line = line.strip()
            line = re.sub(' +',' ', line)
            # header special case
            if n == 0:
                columns = line.split('\t')
            else:
                columns = line.split()
            print(f"{columns}")


if __name__ == '__main__':
    read_data('example_linearity.txt')
results:
Output:
['Freq(Hz)', 'Class 1 + (dB)', 'Class 1 - (dB)', 'Class 2 + (dB)', 'Class 2 - (dB)', 'voltage (mVrms)', 'NI voltage (mVrms)', 'SLM (dB)', 'NI SLM (dB)', 'Input (dB)', 'Expected SPL (dB', 'overload'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '76.0000', '0.0000', '94.0000', '94.3497', '94.0000', '94.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '135.1492', '0.0000', '99.0000', '99.3496', '99.0000', '99.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '240.3331', '0.0000', '104.0000', '104.3490', '104.0000', '104.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '427.3794', '0.0000', '109.0000', '109.3531', '109.0000', '109.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '760.0000', '0.0000', '114.0000', '114.3511', '114.0000', '114.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '852.7340', '0.0000', '115.0000', '115.1273', '115.0000', '115.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '956.7833', '0.0000', '116.0000', '116.3524', '116.0000', '116.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '1073.5285', '0.0000', '117.0000', '117.3523', '117.0000', '117.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '1204.5188', '0.0000', '118.0000', '118.3528', '118.0000', '118.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '42.7379', '0.0000', '89.0000', '89.3501', '89.0000', '89.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '24.0333', '0.0000', '84.0000', '84.3497', '84.0000', '84.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '13.5149', '0.0000', '79.0000', '79.3494', '79.0000', '79.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '7.6000', '0.0000', '74.0000', '74.3495', '74.0000', '74.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '4.2738', '0.0000', '69.0000', '69.3492', '69.0000', '69.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '2.4033', '0.0000', '64.0000', '64.3489', '64.0000', '64.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '1.3515', '0.0000', '59.0000', '59.3489', '59.0000', '59.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.7600', '0.0000', '54.0000', '54.3481', '54.0000', '54.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.4274', '0.0000', '49.1000', '49.3496', '49.0000', '49.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.2403', '0.0000', '44.1000', '44.3487', '44.0000', '44.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.1351', '0.0000', '39.1000', '39.3472', '39.0000', '39.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.0760', '0.0000', '34.3000', '34.3524', '34.0000', '34.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.0760', '0.0000', '34.3000', '34.3504', '34.0000', '34.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.0677', '0.0000', '33.3000', '33.3623', '33.0000', '33.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.0604', '0.0000', '32.4000', '32.3638', '32.0000', '32.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.0538', '0.0000', '31.5000', '31.3587', '31.0000', '31.0000', '0.0000'] ['8000.0000', '1.1000', '-1.1000', '1.4000', '-1.4000', '0.0480', '0.0000', '30.5000', '30.3642', '30.0000', '30.0000', '1.0000']
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Paste text with caret already positioned inside a placeholder; Wehaveall 2 1,046 May-14-2025, 01:12 AM
Last Post: armorerratic
  docx file to pandas dataframe/excel iitip92 1 3,026 Jun-27-2024, 05:28 AM
Last Post: Pedroski55
  Copy and Paste Files - Command MicheliBarcello 2 987 Jun-25-2024, 05:04 AM
Last Post: rodiongork
  Reading an ASCII text file and parsing data... oradba4u 2 1,569 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 1,450 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Python openyxl not updating Excel file MrBean12 1 2,268 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 1,679 Feb-07-2024, 12:24 PM
Last Post: Viento
  What script to paste folders thenewcoder 1 1,391 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 3,010 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 2,181 Nov-03-2023, 05:13 PM
Last Post: noisefloor

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020