Current location - Loan Platform Complete Network - Big data management - How to read excel file data in php and output it
How to read excel file data in php and output it
PHPExcel

PHPExcel?is a PHP class library used to manipulate Office Excel documents, which is based on Microsoft's OpenXML standard and PHP language. You can use it to read and write spreadsheets in different formats such as Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML and so on.

PHP Read Sample Code

// Get uploaded excel temp file

$path?=? $_FILES["file"]["tmp_name"];

//Move the temporary file to the current directory, you can customize the storage location

move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"] ["name"]);

// Will get the Excel file in the server, here is the name of the uploaded file

$path?=? $_FILES["file"]["name"];

//Call the readExcel function to return a

two-dimensional array

$exceArray?=?readExcel($path);

///////Creates an Excel function that reads

excel function

function?readExcel($path){

//Introduce the PHPExcel class library

include?'Classes/PHPExcel.php';

include?'Classes/PHPExcel/ IOFactory.php';

$type?=?' Excel5';//setting it to Excel5 means it supports 2003 or below,

Excel2007 means version 2007

$xlsReader?=? \PHPExcel_IOFactory::createReader($type);?

$xlsReader->setReadDataOnly(true);

$xlsReader->setLoadSheetsOnly(true);

$Sheets?=? $xlsReader->load($path);

// Start reading the Excel file uploaded to the server, returning a

two-dimensional array

$dataArray?=? $Sheets->getSheet(0)->

toArray();

return?$dataArray;

}