Python3でテキストファイル(*txt)からexcelファイルに変換するサンプルコード

サンプルコード:
import os
import glob
path = os.getcwd()
files = glob.glob('../trunk/Resource/lang/ja_startnews24/*.txt’)
import xlwt3

if len(files) > 0:
wb = xlwt3.Workbook()
for file in files:
fileName = file.split('\\’)[1].split('.’)[0]
print(fileName)
ws = wb.add_sheet(fileName)
with open(file, encoding=’utf-8′) as a_file:
line_number = 0
for a_line in a_file:
a_line = a_line.rstrip()
mark = a_line.find(“=")
ws.write(line_number, 0, a_line[0:mark])
ws.write(line_number, 1, a_line[mark+1:])
ws.col(0).width = 8000
ws.col(1).width = 40000
line_number += 1
a_file.close()
wb.save('langPack_ja_startnews24.xls’)

Python

Posted by arkgame