php - All records are displaying on a single row when exporting array to a csv file -
i pulling data api exporting excel file.
here's code:
// api code request here $jsondecode = json_decode($content); // echo '<pre>'; // var_dump($jsondecode); foreach( $jsondecode $value ) { //if null, create blank field if ( ( !isset( $value ) ) || ( $value == "" ) ){ $value = "\t"; } //else, assign field value our data else { $value = str_replace( '"' , '""' , $value ); $value = '"' . $value . '"' . "\t"; } //add field value our row $line .= $value; } //trim whitespace each row $data .= trim( $line ) . "\n"; //remove carriage returns data $data = str_replace( "\r" , "" , $data ); $file_name = 'excel_data'; //create file , send browser user download header("content-type: application/vnd.ms-excel"); header( "content-disposition: filename=".$file_name.".xls"); print "$header\n$data"; exit;
as shown above, after pulling data api, pass through phpexcel library export excel file data exported displays in on single row shown below:
how can have each of record of data in excel file display on new line/row?
Comments
Post a Comment