Because it is hard to deal with different standards among different browsers, I give up trying to export html table using js or jQuery. I wonder if I can POST the table in html back to server and generate an .xls file on the server for user to download.
Now on the server side using PHPExcel, my code is like this:
$filename = "DownloadReport";
$table = $_POST['table'];
ini_set('zlib.output_compression','Off');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
//the folowing two lines make sure it is saved as a xls file
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
$objReader = PHPExcel_IOFactory::createReader('HTML');
$objPHPExcel = $objReader->load($table);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
The problem is I cannot load html table directly. How can I deal with that?
And one more question is that as I set the headers in php, the file is not downloading when I click the button. Actually I can view all the attributes of Header of the POST response, and also the content of response(in FireBug), which are all correct.