tags:

views:

67

answers:

2

I have the following method to create an Excel file from in PHP starting with a two-dimensional array:

header("Content-Disposition: attachment; filename=ExcelFile.xls");
header("Content-Type: application/vnd.ms-excel"); 



$Data[] = array('field1', 'field2', 'field3');
$Data[] = array('field1', 'field2', 'field3');
$Data[] = array('field1', 'field2', 'field3');

foreach($Data as $key => $val) {
    echo implode("\t", array_values($val)) . "\n"; 
}

Would it be possible to include a hyperlink to a webpage in this file?

A: 

Refer this Link

Click Here

pavun_cool
any way to do this without ZEND?
Brian
Never click here.
SpawnCxy
A: 

For any kind of useful cell manipulation besides the basic .csv output approach, you might want to consider PHP COM.

Here's a very rough example that borrows heavily from this link just to give you the gist of what it'll look like:

//create instance of excel on the server
$excel = new COM("excel.application") or die("Unable to create excel object");

//add a book and a worksheet and activate the worksheet
$workbook = $excel->Workbooks->Add();
$worksheet=$workbook->Worksheets(1);
$worksheet->activate;

//pick an active cell (here it's A1) and add text plus a hyperlink
$cell=$worksheet->Cells(1,1);
$cell->Activate;
$cell->value = 'your hyperlink text';

//i took this syntax from my native MS VBA, so check syntax
$cell->Hyperlinks.Add.ActiveCell, 'http://yourdomain.com'

//save your doc
$worksheet->SaveAs([[your path]]);

//close everything up and free up resources
$worksheet->Close(false);
$excel->Workbooks->Close();
unset($sheet);
$excel->Quit();
$excel = null;

Results may vary, depending on all the bug reports one reads on this topic.

LesterDove