我的代码如下                $filename = "Invoice". $_GET['fh_id'] .".xls";
$fullUrl = HTTP_SERVER.DIR_WS_CATALOG."invoices/".$filename;
date_default_timezone_set('Asia/Shanghai');
/** PHPExcel_IOFactory */
require_once 'classes/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("invoice_tpl.xls");
$data = array();
foreach ($products_arr as $key=>$product){
$data[] = array('pkgs_nol'  => $product['pkgs_count'],
'weight'    => $product['products_weight'],
'Cubage'    => $product['volume_weight'],
'title' => $product['products_name_en'],
'price' => $product['custom_price'],
'quantity' => $product['tb_qty']
   );
}

$baseRow = 15;
foreach($data as $r => $dataRow) {
$row = $baseRow + $r;
$objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);
$objPHPExcel->getActiveSheet()->mergeCells('A'.$row.':B'.$row);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $dataRow['pkgs_nol']);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $dataRow['weight']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, $dataRow['Cubage']);
$objPHPExcel->getActiveSheet()->mergeCells('E'.$row.':F'.$row);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, $dataRow['title']);
$objPHPExcel->getActiveSheet()->setCellValue('G'.$row, $dataRow['quantity']);
$objPHPExcel->getActiveSheet()->setCellValue('H'.$row, $dataRow['price']);
$objPHPExcel->getActiveSheet()->mergeCells('I'.$row.':J'.$row);
$objPHPExcel->getActiveSheet()->setCellValue('I'.$row, $dataRow['quantity']*$dataRow['price']);
}
$objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);
$objPHPExcel->getActiveSheet()->setTitle('GMC Commercial Invoice');
// Redirect output to a client’s web browser (Excel5)

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="GMC Commercial Invoice'. $_GET['fh_id'] .'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save("invoices/".$filename);
$objWriter->save('php://output');
// download($filename,$fullUrl);
exit;执行$objWriter->save('php://output'), 在网页上输出excel的文件,打开时总是出现乱码格式不正确.
而执行$objWriter->save("invoices/".$filename); 在服务器保存下来的文件却能够正确地打开. 我另外按这里http://blog.csdn.net/xuyanlu/article/details/7011751  写了一个download()函数, 想把服务器的excel文档下载下来,打开后同样也是格式不正确和乱码.请教高手!
谢谢!