Php-PHP: Traverse excel documents and Output Content

Source: Internet
Author: User
SetOutputEncoding (& #39; GB2312 & #39;); set text input to php

Header ("Content-Type: text/html; charset = GB2312 ");
// This is the excel_reader2.php package for download! Baidu!
Require_once 'Excel/excel_reader2.php ';
$ Dir = "wps/"; // folder name
$ Handle = opendir ($ dir. "."); // open the Directory
$ Row = array ();
While (false! ==( $ File = readdir ($ handle )))
{
If ($ file! = "." & $ File! = ".."){
$ Row [] = $ dir. $ file; // output file name
// Echo $ file;
}
}
Closedir ($ handle); // Close The OpenEd directory
// Print_r ($ row );
$ Data = new Spreadsheet_Excel_Reader ();
$ Data-> setOutputEncoding ('gb2312'); // sets the text output encoding.
// Read the Excel file
// The problem starts from here. The following is a loop of excel documents, but the output content remains unchanged!
// For ($ k = 0; $ k $ data-> read ($ row [0]); // This is a function in the package that reads the excel document
// $ Data-> sheets [0] ['numrows '] indicates the number of rows in Excel
For ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++ ){
}
//}
// $ Data-> sheets [0] ['numrows '] is an array, $ data-> sheets [0] ['numrows '] [2] contents of each row (two rows in my table in total, all tables are the same! The title of the first behavior. the content of the second row is to be read, so it is 2). after the loop here, the array will remain unchanged, and the loop content will always be the first read content! Please loop through all the content in the document!

print_r($data->sheets[0]['cells'][2]);

?>

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.