Skip to content

Instantly share code, notes, and snippets.

@Everfighting
Created May 19, 2017 09:02
Show Gist options
  • Save Everfighting/f69cac5cf7ba74e12402675f8522341e to your computer and use it in GitHub Desktop.
Save Everfighting/f69cac5cf7ba74e12402675f8522341e to your computer and use it in GitHub Desktop.
datetime和xlwt结合的相关操作
from datetime import datetime
import xlwt
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('sheet1',cell_overwrite_ok=True)
jy_ts = datetime.strptime(jy_dt, '%Y-%m-%d')
FIXED_COLS = ('统计日期', '星期', '月份')
for i, val in enumerate(FIXED_COLS):
worksheet.write(0, i, val)
worksheet.write(1, 0, jy_ts.strftime('%Y-%m-%d'))
worksheet.write(1, 1, jy_ts.isoweekday())
worksheet.write(1, 2, jy_ts.strftime('%m'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment