Skip to content

Instantly share code, notes, and snippets.

@ryoco
Created August 16, 2015 05:49
Show Gist options
  • Save ryoco/30dea5f7c7e3eaec6af6 to your computer and use it in GitHub Desktop.
Save ryoco/30dea5f7c7e3eaec6af6 to your computer and use it in GitHub Desktop.
無認可保育所の xls を csv に直すやつ
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xlrd
import csv
import sys
from datetime import time
import datetime
def csv_from_excel():
wb = xlrd.open_workbook(sys.argv[1])
sh = wb.sheet_by_name('Sheet1')
result_file = open('result_file.csv', 'wb')
wr = csv.writer(result_file, quoting=csv.QUOTE_ALL)
for rownum in xrange(sh.nrows):
this_row = []
for num, row in enumerate(sh.row_values(rownum)):
if (num is 6 or num is 7) and type(row) is float:
if int(row) is 1:
this_row.append("24:00")
else:
x = int(row * 24 * 3600)
this_row.append(time(x//3600, (x%3600)//60).strftime("%H:%M"))
elif num is 10 and type(row) is float:
exceldate = datetime.date(1899, 12, 30)
x = exceldate + datetime.timedelta(days=row)
this_row.append(x)
elif type(row) is unicode:
this_row.append(row.encode('utf8'))
else:
this_row.append(row)
wr.writerow(this_row)
result_file.close()
if __name__ == '__main__':
csv_from_excel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment