I am want to export data to excel sheet from custom table.this table is created from wp_list_table in admin section of wordpress. followed is the code i implemented to fetch the data in excel sheet.
global $wpdb;
$data ="";
$values = $wpdb->get_results('SELECT company_name,firstname,email,phone,country FROM (table_name) where id='.$id.' ;',ARRAY_A);
$header = "Name" . "t";
$header .= "Email" . "t";
$header .= "Phone" . "t";
$header .= "Country" . "t";
foreach($values as $line){
$row1 = array();
$row1[] = $line['firstname'];
$row1[] = $line['email'];
$row1[] = $line['phone'];
$row1[] = $line['country'];
$data .= join("t", $row1)."n";
}
header("Content-type: application/xls");
header("Content-Disposition: attachment; filename=expot.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$headern$data";
exit();
My issue is that on exporting the data whole html of the page is also there in my excel sheet. my excel sheet look like attached image
Please suggest whats wrong in the code. why it is getting whole page html in excel sheet.
Regards
swati