Search code examples
python-3.xxlrdrapidminer

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 have plain text in column A (A1-A1500) as well as the according filename in column C (C1-C1500). Now my question: Is there any possibility (I am thinking of the xlrd module) to read the content of every cell in column A and print this to a new created txt file with the filename being given in corresponding column C?

As I have never worked with the xlrd module before I am a bit lost at the moment...


Solution

  • 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 _ in os.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)