# coding:utf-8 import StringIO import xlwt import zipfile import datetime import random, string import os from ftplib import FTP def save2memory(en_cn_map, content): """ 保存内容到xls里面 :param en_cn_map: 英文中文对应字典 {"name": "名字"}, OrderedDict :param content: :return: """ wb = xlwt.Workbook(encoding="utf-8") sheet = wb.add_sheet('info') sort_head = en_cn_map.keys() for i, item in enumerate(en_cn_map): sheet.write(0, i, en_cn_map.get(item)) for row, item in enumerate(content): sort_key = item.keys() for key in sort_key: if key not in sort_head: continue sheet.write(row+1, sort_head.index(key), item.get(key, '')) output = StringIO.StringIO() wb.save(output) return output.getvalue() if __name__ == '__main__': pass