反馈请联系hertz@hertzwang.com,谢谢
前言:
安装xlrd
执行 pip install xlrd
安装
- 注:提示
-bash: pip: command not found
,执行sudo easy_install pip
安装pip
执行Python
# -*- coding: utf-8 -*-
import xdrlib ,sys
import xlrd
import os
# 文件名
fileName = 'yapi.xlsx'
# 属性名称列
propertyNameCol = 0
# 属性类型列
propertyTypeCol = 1
# 属性注释列
propertyDescCol = 4
#打开excel文件
def open_excel():
try:
data = xlrd.open_workbook(fileName)
return data
except Exception,e:
print str(e)
def print_excel():
data = open_excel() #打开excel文件
sheet1 = data.sheet_by_index(0) #选择第1个Sheet
nrows = sheet1.nrows
os.system('clear')
for rownum in range(0, nrows):
name = sheet1.cell_value(rownum, propertyNameCol)
type = sheet1.cell_value(rownum, propertyTypeCol)
desc = sheet1.cell_value(rownum, propertyDescCol)
nstype = 'NSNumber'
if type == 'string':
nstype = 'NSString'
print ('/// %s' % (desc))
print ('@property (nonatomic, copy) %s* %s;' % (nstype, name))
print('')
#主函数
def main():
print_excel()
if __name__=="__main__":
main()