php execel 导出xml 程序
;
private $footer = ;
private $lines = array ();
private $worksheet_title = table1;
private function addrow ($array)
{
// initialize all cells for this row
$cells = ;
// foreach key -> write value into cells
foreach ($array as $k => $v):
$cells .= . utf8_encode($v) . n;
endforeach;
// transform $cells content into one row
$this->lines[] = n . $cells . n;
}
public function addarray ($array)
{
// run through the array and add them into rows
foreach ($array as $k => $v):
$this->addrow ($v);
endforeach;
}
public function setworksheettitle ($title)
{
// strip out special chars first
$title = preg_replace (/[|:|/|?|*|[|]]/, , $title);
// now cut it to the allowed length
$title = substr ($title, 0, 31);
// set title
$this->worksheet_title = $title;
}
function generatexml ($filename)
{
// deliver header (as recommended in php manual)
header(content-type: application/vnd.ms-excel; charset=utf-8);
header(content-disposition: inline; filename= . $filename . .xls);
// print out document to the browser
// need to use stripslashes for the damn >
echo stripslashes ($this->header);
echo nworksheet_title . >nn;
echo n;
echo implode (n, $this->lines);
echo
nn;
echo $this->footer;
}
}
?>
实例
array (oliver, peter, paul),
array (marlene, lucy, lina)
);
// generate excel file
$xls = new excel_xml;
$xls->addarray ( $doc );
$xls->generatexml (mytest);
?>