利用python将excel数据导入epidata【原创】
(2014-04-03 21:38:05)
1、了解rec文件结构,参考:http://wangli12a.blog.163.com/blog/static/7796125200871957220/
2、利用xlrd读取excel文件,按照rec数据要求进行组织数据
3、利用二进制方式进行追加数据
具体实现:
#encoding:utf-8
import sys
import xlrd
from datetime import date,datetime,time
from xlrd import open_workbook,xldate_as_tuple
def getDict():
f=open("d:\\a.rec",'rb')
line=f.readline()
nline=line.split(' ')[0]
n=int(nline)
arr=[]
for i in
range(n):
line=f.readline()
if(int(line[38:40])>0):
dict={}
dict["type"]=line[0]
dict["length"]=line[38:40]
arr.append(dict)
f.close
return
arr
def readXls():
data=xlrd.open_workbook('d:\\aa.xls')
f=open("d:\\a.rec",'ab')
table=data.sheets()[0]
nrows=table.nrows
ncols=table.ncols
arr=getDict()
for i in
range(1,nrows):
rowstr=''
for j in range(ncols):
cell=table.cell(i,j)
if(cell.ctype==0):##空格
s=''
if(cell.ctype==1):##字符串
s=cell.value
if(cell.ctype==2):##数值
s=str(int(cell.value))
if(cell.ctype==3):##日期
date_value=xldate_as_tuple(cell.value,0)
s=date(*date_value[:3]).strftime('%d/%m/%Y')
2、利用xlrd读取excel文件,按照rec数据要求进行组织数据
3、利用二进制方式进行追加数据
具体实现:
#encoding:utf-8
import sys
import xlrd
from datetime import date,datetime,time
from xlrd import open_workbook,xldate_as_tuple
def getDict():
def readXls():