Neveen,

I've got a mini app that I upload excel files to for later parsing, here's 
now I do it. Getting the file would probably be even easier if you used an 
upload field in the DB & CRUD forms.

def excel_uploader():
    response.subtitle = "Upload excel file "
    from gluon.sqlhtml import form_factory
    form=form_factory(SQLField('import_xls','upload'))
    if form.accepts(request.vars,session):
        request.flash='Received: %s'%request.vars.import_xls
        path = 
os.path.join(request.folder,'private','spreadsheet_to_process.xls')
        #I happen to be copying the uploaded file to a known location & 
filename, but you wouldn't have to
        #the uploaded file gets saved to the /uploads folder with a 
auto-generated name too
        import shutil
        shutil.copyfileobj(request.vars.import_xls.file,open(path, 'wb'))

        #Then redirect to the next screen (or do the processing now)
        redirect(URL(r=request, f='process_excel'))

    return dict(form=form)

def process_excel():
    import xlrd
    from applications.app_name.modules.readexcel import readexcel as 
readexcel
    #see 
http://code.activestate.com/recipes/483742-easy-cross-platform-excel-parsing-with-xlrd/


    excel_filepath = 
os.path.join(request.folder,'private','spreadsheet_to_process.xls')
    xl = readexcel(excel_filepath)
    sheetnames = xl.worksheets()
    #for sheet in sheetnames:
    #    print sheet
    #for row in xl.getiter('Sheet  name'):
    #            print row
    return dict(rows = xl.getiter('Sheet Contents'))

Reply via email to