Skip to content Skip to sidebar Skip to footer

Read Excel Cells And Copy Content To Txt File

I am working with RapidMiner at the moment and am trying to copy my RapidMiner results which are in xlsx files to txt files in order to do some further processing with python. I do

Solution 1:

I can recommend openpyxl for every tasks concerning .xlsx handling.

For your requirements:

from openpyxl import *
import os    

p = 'path/to/the/folder/with/your/.xlsx'
files = [_ for _ inos.listdir(p) if _.endswith('.xlsx')]

for f in files:

     wb = load_workbook(os.path.join(p, f))
     ws = wb['name_of_sheet']
     for row in ws.rows:
         with open(row[2].value+'.txt', 'w') as outfile:
              outfile.write(row[0].value)

Solution 2:

Good day! So, I'm not sure I understand your question correctly, but have you tried a combination of Read Excel operator with the Loop Examples operator? Your loop subprocess could then use Write CSV operator or similar.

Solution 3:

Thanks to @corinna the final code is:

from openpyxl import *
import os


p = r'F:\Results'
files = [_ for _ in os.listdir(p) if _ .endswith('.xlsx')]
os.chdir(r"F:\Results")
for f in files:

    file_location = load_workbook(os.path.join(p, f))
    sheet = file_location['Normal']
    for row in sheet.rows:
        withopen(row[2].value + '.txt', "w") as outfile:
            outfile.write(row[0].value)

Post a Comment for "Read Excel Cells And Copy Content To Txt File"