Shame on me.
I've wrote cvstxt instead of csvtxt... Anyway you've teach me some tricks,
thanks a lot.
Il giorno domenica 5 ottobre 2014 12:41:24 UTC+2, Leonel Câmara ha scritto:
>
> This worked for me:
>
> Model:
>
> db.define_table('products',
> Field('id_crm', 'integer'),
> Field('code'
This worked for me:
Model:
db.define_table('products',
Field('id_crm', 'integer'),
Field('code'),
Field('description', 'text'),
Field('price_list', 'decimal(10,5)'),
Field('special_offer', 'boolean'),
)
Controller:
def from_csv():
form = SQLFORM.factory(
Field('t
Thanks Leonel.
Here is my form:
form = SQLFORM.factory(
Field('table',requires=IS_IN_SET(db.tables)),
Field('csvfile','upload',uploadfield=False))
form.process()
if form.accepted:
table = form.vars.table
csvtxt = request.vars.csvfile.file.read()
No, what I mean is, can I see the form you use to upload. And can you show
me more of that controller and/or more of the ticket error. The error
you're getting "global name 'cvsfile' is not defined" doesn't make sense to
me.
An alternative is to read the excel directly using xlrd (
http://www.
I'm creating the csv file like that.
>From a CRM I export data in the only format available, Excel.
>From Excel I export in CSV.
After that I have to replace a lot of things inside the file.
First "," with "." for decimal separator.
";" with "," for field separator
"FALSO" with "0"
"VERO" with "1"
How are you creating your csv file input?
Along with delimiter you can also change quotechar and quoting.
--
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)
---
Thanks Leonel
No it don't.
>However, this is not necessary as you can send the delimiter to
import_from_csv_file. So this may be enough:
>db.products.import_from_csv_file(request.vars.csvfile.file, delimiter=';')
Great but I need to replace other characters.
--
Gael Princiva
Does this work?
csvtxt = request.vars.csvfile.file.read()
csvtxt = csvtxt.replace(';', ',')
from cStringIO import StringIO
db.products.import_from_csv_file(StringIO(csvtxt))
However, this is not necessary as you can send the delimiter to
import_from_csv_file. So this may be enough:
db.products.
8 matches
Mail list logo