Here's the code I've frankensteined together from other posts,
import xlrd
import os.path
wb = xlrd.open_workbook(os.path.join('D:\Data','SPS1 demo data.xlsx'))
wb.sheet_names()
sh = #?
Strings=#variables
i = 1
file = open("Output.txt", "w")
while sh.cell(i,3).value = (Strings):
file.write(#row)
i = i + 1
file.close
It's not complete, but what I'm trying to accomplish is a search in column 3(or entire sheet, doesn't matter) for 5 specific strings and output those rows line by line to a text file, if possible csv formatted i.e. commas between each value.
How can I set a variable to 5 possible strings? Would this need to be an array?
I think the way that I have it written here will overwrite the text file each time rather than append it, is that correct? And if so what's the correct function, "file.append(#stuff)"?
This should work. You can't assign 5 strings to a single variable, without using a list or some other data type. You can however check to see if the third cell's value (i[2] - here) is equal to any of the strings you're looking for ("string1" - "string5" - here).
Your output written to the text file "Output.txt" will be comma separated as the rows in your excel are read into python as tuples in a list.