#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xlrd
import os
import json
#æºexcelæ件ç»å¯¹è·¯å¾
PATH_TARGET_EXCEL = '/Users/bliss_ddo/Desktop/DMFans/DMFans/Resource/Config/ç²ä¸APPæ示æå.xlsx'
#ç®æ jsonæ件路å¾ï¼å¯ä»¥ç´æ¥é
ç½®æå·¥ç¨ä¸çè·¯å¾ï¼è¦çåå
¥
PATH_TARGET_JSONFILE = '/Users/bliss_ddo/Desktop/DMFans/DMFans/Resource/Config/json_alert_message.json'
#ç®æ defineæ件路å¾ï¼å¦æ没æï¼èæ¬ä¼èªå¨å建
PATH_TARGET_HEADERFILE = '/Users/bliss_ddo/Desktop/test_excel2json.h'
EXCEL_DATA = xlrd.open_workbook(PATH_TARGET_EXCEL)
table = EXCEL_DATA.sheets()[0]
COUNT_ROW = table.nrows
COUNT_COL = table.ncols
#读åexcelåå
¥jsonæ件
arr_big = []
for i in range(1,COUNT_ROW):
dict_key_value = {}
for j in range(0,COUNT_COL):
each_key = table.cell(0,j).value
each_value = table.cell(i,j).value
dict_key_value[each_key.encode('utf-8')]=each_value.encode('utf-8')
arr_big.append(dict_key_value)
json_string = json.dumps(arr_big,ensure_ascii=False)
file_pra_txt = open(PATH_TARGET_JSONFILE,'w')
file_pra_txt.write(json_string)
file_pra_txt.close()
print 'çæjsonæ件æå!'
#读åexcelåå
¥defineæ件
finalString = ''
for i in range(1,COUNT_ROW):
each_string = table.cell(i,0).value
each_comment =table.cell(i,1).value
finalString += '#define '+each_string+' @"'+each_string+ '"//'+each_comment+'\n'
file_header = open(PATH_TARGET_HEADERFILE,'w+')
file_header.write(finalString.encode('utf-8'))
file_header.close()
print 'çædefineæ件æå!'```
温馨提示:内容为网友见解,仅供参考