I am trying to copy the contents of first three columns of a txt file to the first three columns of a Excel file.
Here is my code:
import XlsxWriter
worksheet1 = workbook.add_worksheet()
worksheet1.write('A1', 'Time', bold);worksheet1.write('B1', 'User Value', bold);worksheet1.write('C1','Address', bold);worksheet1.write('D1', 'Serial Number', bold);
items = os.listdir(directory)
for FILE in items:
if FILE.endswith('file.txt'):
FileSelection = directory+'/' + FILE
Array1 = []
with open(FileSelection, 'r') as f:
for line in f:
valuesList = line.split('\t')
#print valuesList
Array1.append(valuesList)
for j in range(len(Array1)):
if j == 0:
continue
else:
print Array1[j][0]
worksheet1.write('A2:D2', Array1[j][0]) #I want to say, copy the columns A to D but start from the second raw
However it copies whole the txt array to first column of Excel file!