$rokstr .= "</tr>"; } echo $rokstr; exit; } add_action('wp_ajax_search_action', 'search_action'); add_action('wp_ajax_nopriv_search_action', 'search_action'); $data = array('0' => array('Name' => 'user1', 'Status' => 'complete', 'Priority' => 'Low', 'Salary' => '001'), '1' => array('Name' => 'user2', 'Status' => 'inprogress', 'Priority' => 'Low', 'Salary' => '111'), '2' => array('Name' => 'user3', 'Status' => 'hold', 'Priority' => 'Low', 'Salary' => '333'), '3' => array('Name' => 'user4', 'Status' => 'pending', 'Priority' => 'Low', 'Salary' => '444'), '4' => array('Name' => 'user5', 'Status' => 'pending', 'Priority' => 'Low', 'Salary' => '777'), '5' => array('Name' => 'user6', 'Status' => 'pending', 'Priority' => 'Low', 'Salary' => '777')); if (isset($_POST["ExportType"])) { switch ($_POST["ExportType"]) { case "export-to-excel": // Submission from $filename = $_POST["ExportType"] . ".xls"; // header("Content-Type: application/vnd.ms-excel"); // header("Content-Disposition: attachment; filename=\"$filename\""); ExportFile($myrows); //$_POST["ExportType"] = ''; exit; case "export-to-csv": // Submission from $filename = $_POST["ExportType"] . ".csv"; //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Content-type: text/csv"); header('Content-Type: application/csv'); header("Content-Disposition: attachment; filename=\"{$filename}\""); //header("Expires: 0"); ExportCSVFile($myrows); //$_POST["ExportType"] = ''; exit; case "export-to-pdf": exporttopdf();
<?php // sample array data $data = array('0' => array('Name' => 'user1', 'Status' => 'complete', 'Priority' => 'Low', 'Salary' => '001'), '1' => array('Name' => 'user2', 'Status' => 'inprogress', 'Priority' => 'Low', 'Salary' => '111'), '2' => array('Name' => 'user3', 'Status' => 'hold', 'Priority' => 'Low', 'Salary' => '333'), '3' => array('Name' => 'user4', 'Status' => 'pending', 'Priority' => 'Low', 'Salary' => '444'), '4' => array('Name' => 'user5', 'Status' => 'pending', 'Priority' => 'Low', 'Salary' => '777'), '5' => array('Name' => 'user6', 'Status' => 'pending', 'Priority' => 'Low', 'Salary' => '777')); if (isset($_POST["ExportType"])) { switch ($_POST["ExportType"]) { case "export-to-excel": // Submission from $filename = $_POST["ExportType"] . ".xls"; header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=\"{$filename}\""); ExportFile($data); //$_POST["ExportType"] = ''; exit; case "export-to-csv": // Submission from $filename = $_POST["ExportType"] . ".csv"; header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Expires: 0"); ExportCSVFile($data); //$_POST["ExportType"] = ''; exit; default: die("Unknown action : " . $_POST["action"]); break; } } function ExportCSVFile($records) {