I tried doing:
...
wb = load_workbook(filename= os.path.join(request.folder, 'static',
'survey.xlsx'))
cells = wb['Sheet1']
if row.n1 == 'Yes':
cells['I8'] = 'Yes'
else:
cells['I8'] = 'No'
Doing this allows me to submit the form without error..but when I open the
file it inserts "No" even if the selected option was Yes. :(
On Wednesday, January 6, 2016 at 11:16:28 AM UTC-8, [email protected]
wrote:
>
> I am sure this is a problem with openpyxl and not web2py, although I do
> not understand exactly why it is happening. Is there a way around it or to
> fix it?
>
> When I submit the form the error is:
> *<type 'exceptions.ValueError'> Cannot convert['Yes'] to Excel*
>
> Here is the code:
>
>
> q = ('Yes', 'No')
>
> def surv_excel(row):
> from openpyxl import load_workbook
> from openpyxl.writer.excel import save_virtual_workbook
> from cStringIO import StringIO
> from openpyxl.styles import PatternFill, Border, Side, Alignment,
> Protection, Font
> import os
> wb = load_workbook(filename= os.path.join(request.folder, 'static',
> 'survey.xlsx'))
> cells = wb['Sheet1']
> cells['I8'] = row.n1
> cells['I10'] = row.n2
> cells['I12'] = row.n3
> cells['I14'] = row.n4
> excel_file = StringIO()
> excel_file.write(save_virtual_workbook(wb))
> excel_file.seek(0)
> return db.mysurvey.surv_file.store(excel_file, 'surveyresult.xlsx')
>
>
> db.define_table('surv',
> Field('n1', 'list:string'),
> Field('n2', 'list:string'),
> Field('n3', 'list:string'),
> Field('n4', 'list:string'),
> Field('surv_file', 'upload', compute=surv_excel),
> Field('created_by', 'reference auth_user',
> default=auth.user_id, readable=False, writable=False))
>
> db.surv.n1.requires = IS_IN_SET(q)
> db.surv.n2.requires = IS_IN_SET(q)
> db.surv.n3.requires = IS_IN_SET(q)
> db.surv.n4.requires = IS_IN_SET(q)
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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/d/optout.