'Function to create a spreadsheet (.xls file) of strings with
location, original string and translated string as columns'

@staticmethod
def write_xls(Strings, langcode):

    try:
        from cStringIO import StringIO
    except:
        from StringIO import StringIO
    import xlwt
    from gluon.contenttype import contenttype
    wbk = xlwt.Workbook('utf-8')
    sheet = wbk.add_sheet('Translate')
    style = xlwt.XFStyle()
    font = xlwt.Font()
    font.name = 'Times    New    Roman'
    style.font = font
    sheet.write(0, 0, 'location', style)
    sheet.write(0, 1, 'source', style)
    sheet.write(0, 2, 'target', style)
    row_num = 1
    for (loc, d1, d2) in Strings:
        d2 = d2.decode('string-escape').decode('utf-8')
        sheet.write(row_num, 0, loc, style)
        try:
            sheet.write(row_num, 1, d1, style)
        except:
            current.log.warning('Invalid    source    string!', loc)
            sheet.write(row_num, 1, '', style)
        sheet.write(row_num, 2, d2, style)
        row_num += 1
    for colx in range(0, 3):
        sheet.col(colx).width = 15000
    output = StringIO()
    wbk.save(output)
    filename = ('%s.xls' % langcode)
    disposition = ('attachment;    filename="%s"' % filename)
    response = current.response
    response.headers['Content-Type'] = contenttype('.xls')
    response.headers['Content-disposition'] = disposition
    output.seek(0)
    return output.read()
