I assume that's not the actual code, as there is a syntax error (no "." 
before the "write"). Also, you appear to be doing the same thing twice -- 
first using str() to convert the Rows to CSV, and then using the 
export_to_csv_file method. As detailed in the book, those methods are the 
same -- just pick one.

Anthony

On Friday, August 7, 2015 at 3:42:17 PM UTC-4, [email protected] wrote:
>
> Ok, i change the code but i get an error:
>
> @auth.requires_login()
> def create_csv():
>     from gluon.contenttype import contenttype
>     import os
>     response.headers['Content-
> Type'] = contenttype('.csv')
>     response.headers['Content-disposition'] = 'attachment; 
> filename=%s_database.csv' % (
>         request.now
>         )
>     import csv
>     s=open('mycsvfile.csv','wb')write(str(db(mydb.mytable.id).select()))
>     db((db.grunddaten.id>0)).select().export_to_csv_file(s, 
> delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
>     s.close()
>
> TicketFile: type 'exceptions.TypeError argument 1 must have a "write" 
> method
>
>
> Am Freitag, 7. August 2015 20:39:32 UTC+2 schrieb [email protected]:
>>
>> He group, 
>>
>> i create serial letters with web2py and pdfLatex. It works fine with a 
>> static csv-file in private folder. 
>> But i want to create the csv and save directly to the folder. No Download!
>>
>> I create the csv ... no Problem:
>>
>> @auth.requires_login()
>> def create_csv():
>>     from gluon.contenttype import contenttype
>>     import os
>>     response.headers['Content-Type'] = contenttype('.csv')
>>     response.headers['Content-disposition'] = 'attachment; 
>> filename=%s_database.csv' % (
>>         request.now
>>         )
>>     import csv, cStringIO
>>     s = cStringIO.StringIO()
>>     db((db.grunddaten.id>0)).select().export_to_csv_file(s, 
>> delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
>>     return s.getvalue()
>>
>> But how can i save this file directly on my folder?
>>
>>

-- 
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.

Reply via email to