Search
 
SCRIPT & CODE EXAMPLE
 

PHP

export to excel in php

$queryexport = ("
SELECT username,password,fullname FROM ecustomer_users
WHERE fk_customer='".$fk_customer."'
");

$row = mysql_fetch_assoc($queryexport);

$result = mysql_query($queryexport);
$header = '';

for ($i = 0; $i < $count; $i++){
   $header .= mysql_field_name($result, $i)."	";
   }

while($row = mysql_fetch_row($result)){
   $line = '';
   foreach($row as $value){
          if(!isset($value) || $value == ""){
                 $value = "	";
          }else{
                 $value = str_replace('"', '""', $value);
                 $value = '"' . $value . '"' . "	";
                 }
          $line .= $value;
          }
   $data .= trim($line)."
";
   $data = str_replace("
", "", $data);

if ($data == "") {
   $data = "
no matching records found
";
   }
}
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: attachment; filename=exportfile.xls");
header("Pragma: no-cache");
header("Expires: 0");

// output data
echo $header."
".$data;

mysql_close($conn);`
Comment

create excel file using php]

$books = [
    ['ISBN', 'title', 'author', 'publisher', 'ctry' ],
    [618260307, 'The Hobbit', 'J. R. R. Tolkien', 'Houghton Mifflin', 'USA'],
    [908606664, 'Slinky Malinki', 'Lynley Dodd', 'Mallinson Rendel', 'NZ']
];
$xlsx = SimpleXLSXGen::fromArray( $books );
$xlsx->saveAs('books.xlsx');
//  $xlsx->downloadAs('books.xlsx');
//git repo given below 
Comment

PREVIOUS NEXT
Code Example
Php :: laravel run all seeders 
Php :: php sort multidimensional array by key 
Php :: how to set select option value dynamically in php 
Php :: wordpress custom post type query 
Php :: upload video in laravel 
Php :: laravel request get parameter 
Php :: magento 2 get number of cart items 
Php :: laravel collection sort 
Php :: custom autoload without composer php psr4 
Php :: laravel model withCount relationship condition 
Php :: how to trim string in laravel 
Php :: slugify text in php 
Php :: get curl httcode php 
Php :: Sum two numbers in PHP with HTML input form 
Php :: how to sort with array and after print by for loop in php 
Php :: create array php 
Php :: blank admin page magento 2.3 
Php :: how to make model and controller in laravel 
Php :: how to delete item from array php 
Php :: laravel route required parameters 
Php :: add top menu bar in wordpress 
Php :: minishlink/web-push v5.2.5 requires ext-gmp * 
Php :: IlluminateContractsAuthAuthenticatable, AppModelsUser given, called in 
Php :: php webpage to string 
Php :: ?? php 
Php :: nginx codeigniter remove index.php 
Php :: imagick php 
Php :: debian install php 
Php :: bagisto package generator 
Php :: php contain 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =