Hi,

I am writing for my invoice app a excel (xlsx) function to export a view of 
al my invoices to excel.
Does anyone has some experience with xlsxwriter? Or some tips or 
alternatives?

Or maybe you advise me to use xlwt from python-excel.org?

I am having trouble with the translatable string that i use in the excel 
function.
It seems it returns the lazyT object in the string but xlsxwriter fails on 
this.

When i set T.lazy = False it has no change with the error..

Does anyone knows the problem?

I have written the following code:

# -*- coding: utf-8 -*-
@auth.requires_login()
def invoice():

    import xlsxwriter

    # Create a workbook and add a worksheet.
    workbook = xlsxwriter.Workbook('Expenses03.xlsx')
    worksheet = workbook.add_worksheet()

    # Add a bold format to use to highlight cells.
    bold = workbook.add_format({'bold': 1})
    eurosign = u"€"
    # Add a number format for cells with money.
    money_format = workbook.add_format({'num_format': eurosign + '#,##0'})

    # Add an Excel date format.
    date_format = workbook.add_format({'num_format': 'd mmmm yyyy'})

    # Adjust the column width.
    worksheet.set_column(1, 1, 30)

    # Write some data headers.
    worksheet.write('A1', T('Invoice no.'), bold)
    worksheet.write('B1', T('Debtor'), bold)
    worksheet.write('C1', T('Invoice date'), bold)
    worksheet.write('D1', T('Amount incl. VAT'), bold)
    worksheet.write('E1', T('Type'), bold)

    # Some data we want to write to the worksheet.
    data = []
    rows = db(db.invoice.company == u.company).select()
    for record in rows:
        if not record.debtor.company_name:
            prefix = ' ' + record.debtor.prefix if record.debtor.prefix 
else ''
            debtor = record.debtor.first_name + prefix + ' ' + 
record.debtor.last_name
        else:
            debtor = record.debtor.company_name
        data.append([record.no, debtor, record.date, 
record.amount_incl_VAT, record.type])

    # Start from the first cell below the headers.
    row = 1
    col = 0

    for no, debtor, date, cost, rtype in data:
        worksheet.write_string  (row, col,     no                )
        worksheet.write_string  (row, col + 1, debtor            )
        worksheet.write_datetime(row, col + 2, date, date_format )
        worksheet.write_number  (row, col + 3, int(cost), money_format)
        worksheet.write_string  (row, col + 4, rtype              )
        row += 1

    # # Write a total using a formula.
    worksheet.write(row, 0, T('Total'), bold)
    worksheet.write(row, 3, '=SUM(C2:C' + str(len(data)+1) + ')', 
money_format)

    workbook.close()


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