php - Download .xls file containing hebrew text -
i have data in hebrew in database , want export data excell file on button click using php in wordpress. on downloading , opening file hebrew text display מפרץ שלמה.
here code:
ob_start(); date_default_timezone_set("asia/bangkok"); $admin_added_customers = $wpdb->get_results ( $wpdb->prepare ( "select * ".$wpdb->prefix . "record not_shipped = %d", 0 ) ); function filterdata(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } // file name download $filename = "unshipped_cards_export_data" . date('y-m-d') . ".xls"; // headers download header("content-type: text/html; charset=utf-16le"); header("content-disposition: attachment; filename=\"$filename\""); //header("content-type: application/vnd.ms-excel"); $keys = array("name","number","first name", "email","address1","address2","city","state","zipcode","country","purchased on", "expire on"); echo implode("\t", $keys) . "\n"; foreach($admin_added_customers $row) { $customer = new wp_user($row->customer_id); echo mb_convert_encoding($customer->billing_first_name." ".$customer->billing_last_name,'utf-16','utf-8')."\t"; echo $row->id."\t"; echo $row->name."\t"; echo $customer->user_email."\t"; echo $customer->billing_address_1."\t"; echo mb_convert_encoding($customer->billing_address_2,'utf-16','utf-8')."\t"; echo mb_convert_encoding($customer->billing_city,'utf-16','utf-8')."\t"; echo mb_convert_encoding($customer->billing_state,'utf-16','utf-8')."\t"; echo $customer->billing_postcode."\t"; echo wc()->countries->countries[$customer->billing_country]."\t"; echo !empty($row->purchase_date) ? date("f j, y", strtotime($row->purchase_date))."\t" : "\t"; echo !empty($row->expiry_date) ? date("f j, y", strtotime($row->expiry_date))."\t" : "\t"; echo "\n"; }
edit 1:
here new code :
header("content-disposition: attachment; filename=\"$filename\""); header("content-type: application/vnd.ms-excel"); echo "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /></head><body>"; $keys = array("name","number","first name", "email","address1","address2","city","state","zipcode","country","purchased on", "expire on"); echo implode("\t", $keys) . "\n"; foreach($admin_added_customers $row) { $customer = new wp_user($row->customer_id); echo $customer->billing_first_name." ".$customer->billing_last_name."\t"; echo $row->id."\t"; echo $row->name."\t"; echo $customer->user_email."\t"; echo $customer->billing_address_1."\t"; echo $customer->billing_address_2."\t"; echo $customer->billing_city."\t"; echo $customer->billing_state)."\t"; echo $customer->billing_postcode."\t"; echo wc()->countries->countries[$customer->billing_country]."\t"; echo !empty($row->purchase_date) ? date("f j, y", strtotime($row->purchase_date))."\t" : "\t"; echo !empty($row->expiry_date) ? date("f j, y", strtotime($row->expiry_date))."\t" : "\t"; echo "\n"; } echo "</body></html>";
this solve issue of hebrew text rather show data in tabular form, showing whole data in first cell of excel.
Comments
Post a Comment