Oh my god, it worked again!! >I also want to export the csv file with " " for characters. Do you know if we can do this ? I want do quotechar='"' just like the following link.
http://www.web2py.com/books/default/chapter/29/6?search=csv#Data-representation On Feb 3, 2:54 pm, Anthony <abasta...@gmail.com> wrote: > Take your query out of quotes -- a query has to be a DAL Query object, but > you have simply passed in a string. > > Anthony > > > > > > > > On Friday, February 3, 2012 3:31:23 PM UTC-5, Omi Chiba wrote: > > > I want to export the specific table data to csv. I tried the code > > after appadmin but I got a "TypeError: 'str' object is not callable" > > error. Can you guys help ? > > > I also want to export the csv file with " " for characters. > > > Model > > ---------------------- > > db.define_table('IQWAGFTY', > > Field('TYPRCD', length=15), > > Field('TYPRKJ', length=50), > > Field('TYTYPE', length=2), > > primarykey=['TYPRCD']) > > > Controller > > -------------------------- > > def export_csv(): > > import gluon.contenttype > > response.headers['Content-Type'] = \ > > gluon.contenttype.contenttype('.csv') > > db = request.args[0] > > query = 'db.IQWAGFTY.TYPRCD!=""' > > response.headers['Content-disposition'] = 'attachment; > > filename=IQWAGFTY.csv' > > return str(db(query,ignore_common_filters=True).select()) > > > def index(): > > if request.vars.csvfile != None: > > import_csv(db[request.vars.table],request.vars.csvfile.file) > > response.flash = T('data uploaded') > > return dict() > > > View - default/index > > ------------------------------ > > {{left_sidebar_enabled=right_sidebar_enabled=False}} > > {{extend 'layout.html'}} > > > <h3>Step 1. Download file</h3> > > [ <a href="{{=URL('export_csv',args='db.IQWAGFTY')}}">{{="export as > > csv file"}}</a> ] > > > Traceback > > ------------------------------ > > Traceback (most recent call last): > > File "C:\web2py\gluon\restricted.py", line 204, in restricted > > exec ccode in environment > > File "C:/web2py/applications/Inventory_Reserve_Admin/controllers/ > > default.py", line 82, in <module> > > File "C:\web2py\gluon\globals.py", line 172, in <lambda> > > self._caller = lambda f: f() > > File "C:/web2py/applications/Inventory_Reserve_Admin/controllers/ > > default.py", line 22, in export_csv > > return str(db(query,ignore_common_filters=True).select()) > > TypeError: 'str' object is not callable