I'm pretty sure that 
archivo='/home/lu/web2py/applications/pruebas/uploads/'+form.vars.pago 
doesn't actually contain the path to your file (and you should also 
probably be using os.path.join() rather than just concatenating)

Here's some old code from an app I had that was allowing upload of excel 
files.

def excel_uploader():
    response.subtitle = "Upload excel file with latest event list"
    from gluon.sqlhtml import form_factory
    form=form_factory(SQLField('import_xls','upload',uploadfolder="uploads"
))
    if form.accepts(request.vars,session):
        request.flash='Received: %s'%request.vars.import_xls
        path = os.path.join(request.folder,'private',
'website_event_list2.xls')
        import shutil
        shutil.copyfileobj(request.vars.import_xls.file,open(path, 
'wb'))#moving 
to known location for later


        redirect(URL(r=request, f='layout_selector'))


    return dict(form=form)



And then the reading of the excel file happened later:

def website_html():
    import xlrd
    from applications.MobilePack_Events.modules.readexcel import readexcel 
as readexcel
    excel_filepath = os.path.join(request.folder,'private',
'website_event_list2.xls')
    xl = readexcel(excel_filepath)
    sheetnames = xl.worksheets()
    #for sheet in sheetnames:
    #    print sheet
    #for row in xl.getiter('Upcoming Events'):
    #            print row
    return dict(rows = xl.getiter('Upcoming Events'))

The readexcel code comes 
from 
http://code.activestate.com/recipes/483742-easy-cross-platform-excel-parsing-with-xlrd/
 

Good Luck,
~Brian

On Thursday, February 14, 2013 8:46:14 AM UTC-6, Omicron VT wrote:
>
> I have this code in controller trying to read an .xls file : 
>
> ******************************** 
> def upload(): 
>      import xlrd 
>
>      form = SQLFORM.factory(Field('pago', 'upload', 
>   
> uploadfolder='/home/user/web2py/applications/pruebas/uploads')).process() 
>
>      if form.accepts(request.vars,keepvalues=True): 
>   
> archivo='/home/lu/web2py/applications/pruebas/uploads/'+form.vars.pago 
>          book = xlrd.open_workbook(archivo) 
>          sh = book.sheet_by_index(0) 
>          columnas = sh.ncols 
>
>      return dict(form=form, columnas=columnas) 
> ********************************** 
>
> Get this error : 
> <type 'exceptions.ValueError'> mmap offset is greater than file size 
>
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to