2014-11-05 2 views
1

디렉토리에 Excel 파일이 여러 개있어서 쓰기 작업을 수행 할 때 한 번에 파일을 열려고합니다 (예 : 모든 Excel 파일의 첫 번째 행에 "Hi"쓰기).). 파이썬에서 그렇게 할 수있는 방법이 있습니까?Python을 사용하여 multiple excel 파일 열기

답변

0

더 많은 제어가 필요한 경우이 같은 것을 할 수있다 (그는 원래 저자 인 경우, 제이 확실하지라는 사람으로부터 솔루션을. http://www.python-excel.org/)

import xlwt 

x=1 
y=2 
z=3 

list1=[2.34,4.346,4.234] 

book = xlwt.Workbook(encoding="utf-8") 

sheet1 = book.add_sheet("Sheet 1") 

sheet1.write(0, 0, "Display") 
sheet1.write(1, 0, "Dominance") 
sheet1.write(2, 0, "Test") 

sheet1.write(0, 1, x) 
sheet1.write(1, 1, y) 
sheet1.write(2, 1, z) 

sheet1.write(4, 0, "Stimulus Time") 
sheet1.write(4, 1, "Reaction Time") 

i=4 

for n in list1: 
    i = i+1 
    sheet1.write(i, 0, n) 



book.save("trial.xls") 
0

당신은 사용할 수 있습니다

import csv  
with open('A.csv','w') as a, open ('B.csv', 'w') as b: 
    a_reader = csv.reader(a) 
    b_reader = csv.reader(b) 
    ... 

는 이제 두 파일을 반복 할 수 있습니다.

파이썬 모듈 fileinput도 도움이 될 수 있습니다. 인수로 전달 된 여러 파일의 행을 반복 할 수 있습니다.

관련 문제