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

how do i use php read excel file

Mark Baker was extremely helpful in guiding me to the right answer. I don't use Composer with PHP (I should probably learn), but given that, in order to get this to work I went to the GitHub page for PHPExcel (https://github.com/PHPOffice/PHPExcel), clicked the green Clone and download button, and then the Download ZIP link.

After unzipping the file, I got a folder called PHPExcel-1.8. I moved that folder to the same folder as both the Excel file I wanted to read (in my code below test.xlsx) and the PHP file that has the code below.

The key to getting it to work was inputting the correct path to the IOFactory.php file. It may seem simple to some, but it was tripping me up.
Comment

php read excel file

I use PHP-ExcelReader to read xls files, and works great.
Comment

PREVIOUS NEXT
Code Example
Php :: laravel eloquent update 
Php :: file_get_content 
Php :: php include external directory path 
Php :: laravel 8 websockets 
Php :: add brackets to string php 
Php :: wp_debug 
Php :: php build query from array 
Php :: luhn algorithm 
Php :: php foreach loop first element 
Php :: Add Text Before the Product Title 
Php :: echo in console command laravel 
Php :: javascript function in php json_encode 
Php :: PHP str_word_count — Return information about words used in a string 
Php :: if exists in string count php 
Php :: replace word in string php 
Php :: codeigniter session destroy automatically after redirect 
Php :: symfony messenger transport 
Php :: update query laravel 
Php :: php count days excluding weekends 
Php :: laravel module package 
Php :: php search multidimensional array for multiple values 
Php :: php array_fill 
Php :: php add to array 
Php :: php mysql prepared statements 
Php :: php round nearest half 
Php :: array_merge in php 
Php :: php display json in browser 
Php :: php try to decode json 
Php :: laravel 9 excel 
Php :: Program for factorial of a number in php 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =