-1

I want to color a row with i am outputting. How can i add properties to that row. Like i want to color that row. How can i add color to that row in csv file. How can add properties like center, bold.

import csv
from django.http import HttpResponse

def GenerateCompanyCSV(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="Company_Report-%s.csv"' % datetime.date.today()

    query_set = Company.objects.exclude(id=1).exclude(
                            company_is_deleted=True
                            ).annotate(
                            number_of_company_users=Count('userprofile')
                        ) 

    output = []

    for query in query_set:
        output.append([
            query.company_name, 
            query.company_email, 
            query.number_of_company_users, 
            query.company_created, 
            query.company_monthly_payment, 
            query.company_tab_opts, 
            query.company_status, 
            ])

    writer = csv.writer(response)
    # Output Color for this row
    writer.writerow(['Company Name', 'Company Email', 'Count Of Total Users', 'Created Date', 'Current Monthly Payment', 'Is TABopts Customer', 'Status'])
    #CSV Data
    writer.writerows(output)

    return response
Cipher
  • 2,060
  • 3
  • 30
  • 58
  • Possible duplicate of [Write csv file with color code](https://stackoverflow.com/questions/12066511/write-csv-file-with-color-code) – Fynn Becker Feb 07 '19 at 14:01

1 Answers1

1

CSV can't do that.

You need a rich table format like the one that open office is using

Or the one that excel is using

Mihai Andrei
  • 1,024
  • 8
  • 11