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 make view command 
Php :: only display part of string php 
Php :: php time ago 
Php :: php replace all spaces with dashes 
Php :: php get first element of array 
Php :: Convert String to Date and Date-Time in PHP 
Php :: laravel sail publish 
Php :: create foreign key laravel migration 
Php :: exec command not working in php but works in terminal 
Php :: mac address php 
Php :: get am pm 12 hour timee laravel 
Php :: why pusher not working in laravel 
Php :: laravel ckeditor 
Php :: get country from clouflare 
Php :: laravel 4.2 migration 
Php :: total days between two dates carbon 
Php :: wordpress add_submenu_page 
Php :: laravel launch only one dusk test 
Php :: get month from database php 
Php :: valet switch php version 
Php :: php check if folder exists 
Php :: laravel 8 route 
Php :: take and skip in laravel 
Php :: How to use my constants in Larvel 
Php :: laravel check if exists in table 
Php :: laravel date format 
Php :: insert data using mysqli in php 
Php :: php get filetype 
Php :: remove item in an array php 
Php :: array find php 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =