Writes out to old excel format.

    Args:
        data: 2D list of tables/worksheets.
        file_name: Name of the output file.
        worksheet_names: A list of worksheet names (optional).

def write_xls(data, file_name, worksheet_names=None):
    '''
    Writes out to old excel format.

    Args:
        data: 2D list of tables/worksheets.
        file_name: Name of the output file.
        worksheet_names: A list of worksheet names (optional).
    '''
    workbook = xlwt.Workbook()
    for sheet_index, sheet_data in enumerate(data):
        if worksheet_names and sheet_index < len(worksheet_names) and worksheet_names[sheet_index]:
            name = worksheet_names[sheet_index]
        else:
            name = 'Worksheet {}'.format(sheet_index)
        sheet = workbook.add_sheet(name)
        for row_index, row in enumerate(sheet_data):
            for col_index, value in enumerate(row):
                sheet.write(row_index, col_index, value)
    workbook.save(file_name)