fee free to create a better mechanism for that. We should really re-factor forms and grid
On Wednesday, 4 April 2018 03:46:46 UTC-5, Dave S wrote: > > > > On Tuesday, April 3, 2018 at 7:49:43 AM UTC-7, Alex Beskopilny wrote: >> >> Hi! >> exporter example >> >> 0 pip install xlwt >> 1 at end of gluon/sqlhtml.py >> >> class ExporterXLS(ExportClass): >> label = 'XLS' >> file_ext = "xls" >> content_type = ".xls" >> # https://gist.github.com/brendano/22764 >> # https://groups.google.com/forum/#!topic/web2py/MR_8JzzP9o4 >> def __init__(self, rows): >> ExportClass.__init__(self, rows) >> >> def export(self): >> import xlwt, cStringIO >> if len(self.rows) == 0: >> return 'empty rows-table' >> >> rows_colnames= [name.translate(None,'"') for name in >> self.rows.colnames ] >> >> (table_name, _)= rows_colnames[0].split('.') >> book = xlwt.Workbook() >> sheet = book.add_sheet(table_name) >> first_xls_row= 0 >> # rows.db.licence.fld2.represent(row.fld2,3) >> >> def list2xls(row_num,line_list): >> for col_num, value in enumerate(line_list): >> if value is None: >> value='' >> elif isinstance(value, long): >> value= str(value) >> elif isinstance(value, str): >> value= value.decode('utf8') >> elif isinstance(value, datetime.date): >> value= value.strftime('%d.%m.%Y') >> elif isinstance(value, datetime.datetime): >> value= value.strftime('%d.%m.%Y %H:%M:%S') >> else: >> value='####' >> sheet.write(row_num, col_num, value) >> >> fields=[]; labels=[] >> for col in rows_colnames: >> (t,f) = col.split('.') >> fields.append(f) >> labels.append( self.rows.db[t][f].label ) >> list2xls(first_xls_row, labels) >> >> for r_num, row in enumerate (self.rows, first_xls_row + 1): >> llist=[ row[f] for f in fields] >> list2xls(r_num, llist) >> >> s = cStringIO.StringIO() >> book.save(s) >> return s.getvalue() >> >> 2 gluon/sqlhtml.py >> 2517 exportManager = dict( >> 2518 axls=(ExporterXLS, 'XLS', T('Excell file')), # myfix >> 2519 csv_with_hidden_cols=(ExporterCSV_hidden, 'CSV (hidden >> cols)', T('Comma-separated export including columns not shown; fields from >> other tables are exported as raw values for faster export')), >> ....... >> >> 3 it's work for me :) >> >> >> > It looks like that has to be done each time you have a new version of > web2py. > > /dps > > >> воскресенье, 1 апреля 2018 г., 10:08:30 UTC+3 пользователь Ray (a.k.a. >> Iceberg) написал: >>> >>> Stumbled upon this blog post "Export in web2py's SQLFORM.grid >>> <http://rootpy.com/Export-in-SQLFORM-grid/>" by Prasad Muley. It >>> provides concrete example on how to customize an exporter TO REMOVE THE >>> TABLE PREFIX IN CSV HEADER LINE. That is easier to digest than the standard >>> web2py book's one-liner >>> <http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORMgrid-signature> >>> >>> "(exporters) are all defined in gluon/sqlhtml.py. Take a look at those for >>> creating your own exporter.". >>> >>> Hope that helps! Enjoy! >>> >>> Regards, >>> Ray >>> >>> >>> -- 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.