Solved

Set colspan, rowspan and bgcolor in excel by php?

Posted on 2004-09-20
5
5,316 Views
Last Modified: 2013-12-13
Hi, actually, i want my table in html can be view in excel or cvs. i have done view in excel by cvs format, but i got any problem.

can the excel view is same as in html browser? in html, theres bgcolor and colspan and rowspan. how to do that in excel?

how to set colspan, rowspan and bgcolor in excel as same as in html? and then how to set width coloum is flexible by the text length using script php?

thanks
0
Comment
Question by:abdi1
[X]
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
  • 2
5 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 12125175
Sorry but you cannot do this with CSV. When Excel reads a CSV file, it only works with the data, and doesn't care about anything related to formatting. It doesn't export/save formatting in CSV and it doesn't read any formatting from CSV files, either.

If you absolutely need to do this, your best bet is to try to have PHP use a Windows COM object to create an Excel spreadsheet (the Linux version of PHP cannot use COM objects). The COM object should have methods and functions that will let you format the spreadsheet and save it as a .XLS file. However, I haven't had very much luck with PHP and COM objects before, so good luck. Here's some links to help:

PHP's COM Object Reference
http://us2.php.net/manual/en/ref.com.php

Excel.Application COM Object Reference
http://msdn.microsoft.com/library/en-us/dv_wrcore/html/wrgrfexcelapplicationobject.asp

Again, good luck!

- J
0
 
LVL 9

Accepted Solution

by:
techtonik earned 55 total points
ID: 12131056
Use PEAR Spreadsheet_Excel_Writer class. There's an introductory tutorial about how to use it.
http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php

There are also some commercial scripts available to create Excel files on the fly. For example:
http://www.web-aware.com/biff/biffmanual.htm?id=10&name=biffmanual.zip

Either of these probably do not have facility to automatically convert tables to Excel  files, so you will have to convert them yourself or ask for support. =)



Some more info from Jens Bierkandt on http://www.codecomments.com/PHP_Language/message269479.html (though I haven't tested it):
---
Re: Writing a XLS (Excel) file with PHP

Try to export an Excel Sheet with the needed things as an HTML file.
Open it and copy the details to a PHP file. Fill the values dynamically
with PHP and set the header in the PHP-Script accordingly. Excel will
then open it.
---
Header is cal to this function before any browser output header("Content-Type: application/vnd.ms-excel");



Here is another post from deleted (unfortunately) user notes on header function in PHP manual:
---
andrej at dairyweb dot com dot au
19-Sep-2003 02:02
while looking for a solution to easily convert HTML->excel spreadsheets, while re-using as much of the existing template system as possible.

i stumbled across a nifty little trick with headers that does the job nicely. (note: i have only tested with IE 5.5+). Just call the headers before the HTML that you want to be rendered into a excel document, and there u go

example:
--------[snip]--------
<?php
 header("Content-type: application/vnd.ms-excel");
 header("Content-Disposition: attachment; filename=\"test.xls\"");
?>
<table border="1" cellpadding="3" cellspacing="1">
  <tr>
    <td>CustomerID</td>
    <td>CompanyName</td>
    <td>ContactName</td>
  </tr>
</table>

words words words
--------[snip]--------

hope it helps someone, as it saved me doing it with an external excel writer library
--
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 12135502
I stand corrected - that's a very useful tip, techtonik. I've asked this several times in the past and kept getting the same answer that you can't do it. I will have to try it out (woohoo - new toys!)  :)

- J
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

737 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