0

hi everyone,
i write data from database to the csv file,but i face problem how to print the csv file with multiple colors background for example first line is green then second line must be blue,
please help me how can i do this in php

4
Contributors
8
Replies
10
Views
6 Years
Discussion Span
Last Post by chrishea
1

You shouldn't post the same question in multiple forums. Start somewhere and if you don't get an answer there, you will probably get a suggestion on the best place to get an answer.

A CSV file is pretty simple. It is almost the same as a text file in terms of any sort of formatting. If you want to save the file with formatting included, then you should save it in some other format

You don't say how you want to print this file. If you are creating the file in PHP then saving it locally on your PC, then you could open it in Excel or some other spreadsheet program and manually add colors then print it. If it is still on the server, you could open it in a PHP program and have the program add colors to the text. You can't save formatting in a CSV file as you would in a Word (.doc) file.

Votes + Comments
If I'd seen this I wouldn't have posted.
0

If you display contents in a table define two CSS classes for row background color - one for even rows and one for odd rows.

.tr_even {background_color: gray;}
.tr_odd {background_color: white;}

Then check the row number and use code:

($row_No % 2) ? echo '<tr class="tr_odd">' : echo '<tr class="tr_even">
0

Thank you for helping,
Actually i get data from database and then write the data to csv file,the generated csv file still on the server with download link,i want if the user download the file,it must be multiple colors,
how can i do it

2

I am afraid you can't. CSV is as far as I know a text file and can not contain formatting. You should save your data in excel or ods or pdf (or similar) to use formatting.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.