Python: Looking To Capture A Particular Cell Value From Individual Csv Files In A Directory And Then List The Values In A New Excel File
I have posted a similar question earlier, however my understanding was that I was dealing with CSV files. What I appear to have are xls files masquerading as CSVs. The CSVs I have
Solution 1:
UPDATED
Based on your answers to my questions, I think your code can be simplified considerably. Please let me know if I'm missing something in the requirement here or if you have any questions:
import xlwt, xlrd, csv, os
files = ['file1.csv','file2.csv','file3.csv','file4.csv']
outputfile = 'outputList.xls'
wbk = xlwt.Workbook()
sheetw = wbk.add_sheet('sheet 1')
row_offset, col_offset = 2, 2# i.e. 2, 2 to print in C3 instead of A1for fname in files:
currentfile = xlrd.open_workbook(fname,'r')
sheetr = currentfile.sheet_by_index(0)
data = sheetr.cell(11,0).value
print data #for testing
sheetw.write(files.index(fname) + row_offset, 0 + col_offset, data)
wbk.save(outputfile)
Post a Comment for "Python: Looking To Capture A Particular Cell Value From Individual Csv Files In A Directory And Then List The Values In A New Excel File"