#!/usr/bin/env python
* coding:utf-8 *
import openpyxl from openpyxl.workbook import Workbook from openpyxl.writer.excel import ExcelWriter import json def newwb_write_data(data,save_path,sheetName,f_row,f_col): try: book = openpyxl.load_workbook(save_path) except Exception as e: book = Workbook() if sheetName in book.sheetnames: sheet = book.get_sheet_by_name(sheetName) else: sheet = book.create_sheet(sheetName,0) for line in data: for col in range(f_col, f_col+len(line) + 1): sheet.cell(row=f_row, column=col).value = line[col - 1 - f_col] f_row += 1 # 工作簿保存到磁盘 book.save(save_path) if name == ‘main’ : data = [ [‘序号’, ‘组号’, ‘申报单位’, ‘姓名’, ‘准考号’, ‘考试分数(卷面分)’] , [‘1’, ‘1’, ‘xxxx, ‘lll’, ‘2012051224’, ‘67.834’] ] # json_data = json.dumps([‘20’, ‘3’, ‘客运公司’, ‘姚佳媛’, ‘2012130613’, ‘63.914’],ensure_ascii=False) # print json_data # json_data2 = json.dumps(json_data,ensure_ascii=False) # print json_data2 # with open(‘1ttt.json’,‘r’) as f: # all2 = f.read() # print all2 # json.dump(json_data,f) # data1 = [ # [‘序号’, ‘组号’, ‘申报单位’, ‘姓名’, ‘准考号’, json_data2]] newwb_write_data(data,‘test44.xlsx’,u’招录人员名单2’,40,2) # import yaml # # t1 = yaml.safe_load(json_data2) # print t1 # f1 = yaml.safe_load(t1) # print f1[2]
|