-
[Python] 엑셀 코드(xlsx 파일 만들기)Engineering WIKI/Python 2018. 10. 15. 23:23
import xlsxwriter book = xlsxwriter.Workbook("2-1.xlsx") # 엑셀 파일 이름 지정 sheet1 = book.add_worksheet() # Sheet 만들기 file_open = open("2-1.txt","r") # txt 파일 읽기 cnt = 0 # row는 0 for lines in file_open: line = lines.split("\t") # 탭으로 자르기 if cnt > 1048576: # Row 수가 1048576을 넘으면Sheet1 추가 sheet1 = book.add_worksheet() if str(line[0]).strip() !="": # if line[0].strip이 공백이 아니면 sheet1.write(cnt,0,str(line[0]).strip()) #sheet1.write(row, col, item) try : if str(line[1]).strip() !="": # if line[1].strip이 공백이 아니면 sheet1.write(cnt,1,str(line[1]).strip()) # sheet1.write(row, col, item) except: pass cnt +=1 # row수 증가 file_open.close() book.close()
'Engineering WIKI > Python' 카테고리의 다른 글
[Python] shutil 함수 (0) 2019.07.03 [Python] 객체와 인스턴스의 차이 (0) 2019.07.03 [Python] 파이썬2,3 동시사용 (0) 2019.07.02 [Python] is 와 ==의 차이점 (0) 2019.05.30 [Python] string 모듈 (0) 2019.05.27 [Python] tkinter 사용 (0) 2019.02.14 [Python] 2.7 Encoding 에러 해결 (0) 2019.01.26 [Python]Using Python file in Shell Script [ 쉘 스크립트 내에서 파이썬 프로그램 실행 ] (0) 2018.08.05