1
我試圖將txt
文件的前三列的內容複製到Excel
文件的前三列。將一列從txt文件複製到Excel文件中的一列,Python
這裏是我的代碼:
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
但是它會將整個TXT陣列Excel
文件的第一列!
什麼你通過一個txt文件的 「列」 的意思是?列是否由製表符分隔? – brianpck
是的,它們是以表格的形式出現的(每列由製表符分隔) – Ssein
您是否正在寫入CSV文件(如標題中)或Excel文件(如您的代碼中)? – brianpck