PHPExcel Read excel

Source: Internet
Author: User
: This article mainly introduces PHPExcel reading. if you are interested in PHP tutorials, refer to it. Require_ Once './library/excel/PHPExcel. php ';

// File to be read
$ FilePath = 'test.xlsx ';

$ PHPExcel = new PHPExcel ();

/** Excel is read using excel2007 by default. if the format is incorrect, it will be read using the previous version */
$ PHPReader = new PHPExcel_Reader_Excel2007 ();
If (! $ PHPReader-> canRead ($ filePath ))
{
$ PHPReader = new PHPExcel_Reader_Excel5 ();
If (! $ PHPReader-> canRead ($ filePath ))
{
Echo 'no Excel ';
Return;
}
}

$ PHPExcel = $ PHPReader-> load ($ filePath );
/** Read the first worksheet in an excel file */
$ CurrentSheet = $ PHPExcel-> getSheet (0 );
/** Obtain the largest column number */
$ AllColumn = $ currentSheet-> getHighestColumn ();
/** Obtain the total number of rows */
$ AllRow = $ currentSheet-> getHighestRow ();
/** Output from the second row because the first row column name in the excel table */
For ($ currentRow = 1; $ currentRow <= $ allRow; $ currentRow ++)
{
/** Output from column */
For ($ currentColumn = 'a'; $ currentColumn <= $ allColumn; $ currentColumn ++)
{
$ Val = $ currentSheet-> getCellByColumnAndRow (ord ($ currentColumn)-65, $ currentRow)-> getValue ();/** ord () convert characters into decimal numbers */
Echo $ val. "\ t ";
}
Echo"
";
}

?>

The above introduces PHPExcel reading, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.