export data from database to excel in php code example
Example 1: export html table data to excel in php
Use a PHP Excel for generatingExcel file. You can find a good one called PHPExcel here: https:
And for PDF generation use http:
Example 2: Using the PHPExcel library to read an Excel file and transfer the data into a database
include 'PHPExcel/IOFactory.php';
$inputFileName = './sampleData/example1.xls';
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 1; $row <= $highestRow; $row++){
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE);
}