PHPExcel library will good for Reading , Writing and Creating spreadsheet documents in PHP
How to read Xlsx in php ?
download PhpExcel and put in project .
and enable PHP extension php_zip , php_xml , php_gd2
include 'PHPExcel.php';
$objPHPExcel = PHPExcel_IOFactory::load("text.xlsx");
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
var_dump($sheetData);
more example
get the active sheet
include 'PHPExcel.php';
$objPHPExcel = PHPExcel_IOFactory::load("text.xlsx");
$worksheet = $objPHPExcel->getActiveSheet();
read cell of xlsx in php
$worksheet->getCell("A12")->getValue() ;
//do calculation here
or set new cell for calculation result in xlsx at php
$worksheet->setCellValue('B12', '=DPRODUCT(A4:E10,"Yield",A1:B2)');
write xlsx file in php
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('test.xlsx');
if you are using PHP version 5.6 or higher than its good to use PhpSpreadsheet
PhpSpreadsheet is the next version of PHPExcel.
download PhpSpreadsheet and put in your project
include PhpSpreadsheet and use it
$filename="read.xlsx";
include 'PHPExcel/IOFactory.php';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
or
include 'PHPExcel/IOFactory.php';
$inputFileType = 'Xls';
//$inputFileType = 'Xlsx';
$filename='example1.xls';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($inputFileName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);