Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Font styling in a csv file

Posted on 2011-09-20
11
293 Views
Last Modified: 2012-05-12
Is there any way to create a csv file & somehow identify cell formatting (font sizes, colors, etc.)?

I'm writing the csv file in php on a web server, to be downloaded to Excel.

I will not be surprised if the answer is no.

Thanks
0
Comment
Question by:Richard Korts
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 7

Accepted Solution

by:
TelnetServices earned 500 total points
ID: 36570967
Hi There

By definition, a CSV file is a "plain text" file http://en.wikipedia.org/wiki/Comma-separated_values

That said - excel can actually open HTML directly (some "XLS" files downloaded from report generators are really HTML files in disguise!)

It's easy and just requires you setting a content type - you can then create a formatted HTML table

See http://mattiasgeniar.be/2008/06/04/creating-excel-files-through-php/ for a guide
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36570972
NO :)
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36570985
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 13

Expert Comment

by:dsmile
ID: 36571711
NO WAY!

CSV is just text file, it CANNOT contain format
0
 
LVL 9

Expert Comment

by:ghodder
ID: 36572350
If you want to create a file in PHP to view in Excel I would recommnd PHPExcel. It can output to XLSX (Office 2007/2010) and is quite good for the purpose.
0
 

Author Comment

by:Richard Korts
ID: 36574481
To TelnetServices:

Should the output file being created in php have an .xls extension or htm (or html)?

I presume I just build html tables in the body to represent the Excel equivalent?

Can I use embedded CSS (not a separate css file, but in the html)?

This sounds like an EXCELLENT solution.

Thanks!
0
 

Author Closing Comment

by:Richard Korts
ID: 36581405
Works VERY easily!
0
 
LVL 7

Expert Comment

by:TelnetServices
ID: 36584349
Sorry - missed your comment - but yes basically all the formatting (more or less) will come through as you expect it to.

Glad it works for you - thx for the points :)

Steve
0
 

Author Comment

by:Richard Korts
ID: 36584375
TelnetServices:

The only thing it does that's sort of odd is that one column is (on some rows) moderately lengthy text, it wraps the cell so a FEW of the rows are "double deep" (in Excel).

I'm thinking of trying to overcome this by determining the maximum width I will need (based on font & number of characters in text) & set a html width parameter for that column based on that value.  

Think that would work?

Thanks
0
 
LVL 7

Expert Comment

by:TelnetServices
ID: 36584392
I think so - the issue is with excel, it tries it's best to maintain the look of the document (rather than maintain structure as such)

Give it a go.
0
 

Author Comment

by:Richard Korts
ID: 36590297
To TelnetServices:

I'm trying to add other formatting. Specifically, row background color. I tried using the traditional <tr bgcolor="hex value">. It puts the background color at dark gray, no matter what.

I also used css style, same result.

Any thoughts?

Maybe I have to do it at the <td> level?

Thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question