正在为公司内部写一个简单的web应用, 基本上就是查询应用,根据访问者输入的信息,返回数据库中相应的值,无写入操作,由于数据源就是从一张excel表格(大概有2000行、20列的数据)中得来的,我想图方便,不去将excel转换成譬如sqlite的数据库文件了,直接通过xlrd模块读取其中的数据,基本上我也将其写好了,如下。这个应用届时可能会有大概10个人以内同时查询操作,不知道这方案可行不?也还没有试过不知道多人同时访问会出现excel表被占用无法打开的类似问题吗?
import xlrd
fname = "spreadsheet.xlsx"
bk = xlrd.open_workbook(fname)
try:
sh = bk.sheet_by_name("sheet")
except:
print 'no sheet found'
nrows = sh.nrows
ncols = sh.ncols
#excel中的列名
name = 0
address = 1
phone = 2
age = 3
people = []
for i in xrange(2, nrows):
people.append(sh.cell_value(i, 0))
person = 'Tom'
if person in people:
print 'yes'
#查找到了该人返回其年龄列的值
print sh.cell_value((people.index(person)+2), age)
else:
print 'person not found'
import xlrd
fname = "spreadsheet.xlsx"
bk = xlrd.open_workbook(fname)
try:
sh = bk.sheet_by_name("sheet")
except:
print 'no sheet found'
nrows = sh.nrows
ncols = sh.ncols
#excel中的列名
name = 0
address = 1
phone = 2
age = 3
people = []
for i in xrange(2, nrows):
people.append(sh.cell_value(i, 0))
person = 'Tom'
if person in people:
print 'yes'
#查找到了该人返回其年龄列的值
print sh.cell_value((people.index(person)+2), age)
else:
print 'person not found'