This worked nice
my code at the end was

formImport =  SQLFORM.factory(Field('csvfile','upload',uploadfield=False))
formImport.process()
if formImport.accepted:
try:
db.workers.import_from_csv_file(request.vars.csvfile.file, delimiter=";")
except: 
formImport.errors.csvfile = 'Invalid file format.'

One more question

How can I set maximum nb of records user can import?

thank you

On Wednesday, July 22, 2015 at 10:43:01 AM UTC+8, Yebach wrote:
>
> I forgot to saay that I have an sqlformgrid in whoch i am importing
> On Jul 22, 2015 1:43 AM, "Derek" <sp1d...@gmail.com> wrote:
>
>> I would first suggest you export to csv (even a blank table) and then you 
>> will know the headers you need for your file.
>>
>> On Tuesday, July 21, 2015 at 12:07:34 AM UTC-7, Yebach wrote:
>>>
>>> Hello
>>>
>>> I would like to import csv file into a database table - user imports
>>>
>>> how do you recommend to do it. I guess telling users to set the column 
>>> names matching the headers in CSV but how do i match them after for import.
>>> I also have to add two fields with user id and another one that is based 
>>> on user id to be inserted
>>>
>>>
>>> My table is 
>>>
>>> CREATE TABLE workers
>>> (
>>>   id serial NOT NULL,
>>>   w_organisation integer,
>>>   w_user integer,
>>>   w_status integer,
>>>   w_first_name character varying(32),
>>>   w_last_name character varying(32),
>>>   w_nick_name character varying(32),
>>>   w_email character varying(64),
>>>   w_note text,
>>>   CONSTRAINT workers_pkey PRIMARY KEY (id)
>>>
>>> )
>>>
>>>
>>> I am strugling with import function
>>>
>>> Please help i need this fast 
>>>
>>> Thank you
>>>
>>  -- 
>> 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 a topic in the 
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/web2py/FhgWebuuk4o/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to