Click here to Skip to main content
16,001,961 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Merry X-mas,

I am trying to print the Mysql table in an excel sheet.But the Error shows that the file format is different,My excel file format is xlsx.Here is the code i am using.
PHP
<pre><?PHP // Original PHP code by Chirp Internet: www.chirp.com.au 
// Please acknowledge use of this code by including this header.

function cleanData(&$str) 
{ 
$str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; 
}
include("config.php");
$filename = "website_data_" . date('Ymd') . ".xlsx";
 header("Content-Disposition: attachment; filename=\"$filename\"");
 header("Content-Type: application/vnd.ms-excel"); $flag = false; $result = pg_query("SELECT * FROM jobrequirements") or die('Query failed!'); 
  while(false !== ($row = pg_fetch_assoc($result)))
   { 
   if(!$flag)
    { 
	// display field/column names as first row
	 echo implode("\t", array_keys($row)) . "\r\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\r\n"; } ?>



I couldn't fix it.I request you to help me to fix this problem.
Posted

1 solution

Use .xls instead of .xlsx in the file name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900