Microsoft Excel .xls format (as well as the others) saves its files
out in custom binary formats. It is very difficult to import them
unless you have a way of decoding the binary format.
Using csv, you can easily set up auto-importers (as long as the csv
data-structure is fairly static).
This is a bit hacky, but you should be able to get the idea...
########### CSV Example
def importer():
my_inserts=[]
form=SQLFORM.factory(
Field('csv_file', 'upload' ,
uploadfolder=os.path.join(request.folder,'static/temp'))
)
if form.accepts(request.vars, session):
my_file=open(os.path.join(request.folder, 'static/temp',
'form.vars.csv_file), 'r')
line=my_file.readline()
while line !="":
# Be careful how you delimit / split your vars!
my_vars=line.split(",") # or whatever
try:
my_inserts.append(
db.my_table.insert(
field_one=my_vars[0]
)
)
except:
# Error handling...
pass
my_file.close()
## Delete the file...
os.unlink(os.path.join(request.folder, 'static/temp',
form.vars.csv_file))
return dict(form=form, inserts=my_inserts)
###############################################################
Obviously it would be beneficial to do some validation etc. before
hand. There's almost definitely some decent python-based csv-parsing
module out there (and a better way to accomplish this task), but with
the way that the csv files (which I'm importing) are generated, I have
to manually parse them due to poor csv-exporting facilities in the
responsible apps.
Martin