Thinkphp+phpexcel the method to read the file date (including time and seconds) _php instance

Source: Internet
Author: User
Tags php template time and seconds

The example in this article describes the Thinkphp+phpexcel implementation method for reading file dates. Share to everyone for your reference, specific as follows:

When we read the Excel file using Phpexcel, we found that the time is similar to the number: 41890.620138889, then how to treat it as we want 2014-09-08 14:53:00 in the format of the date, look at the code:

Vendor (' PHPExcel.PHPExcel.IOFactory ');
$inputFileName = ' Public/demo/demo.xls ';
$objReader = new Phpexcel_reader_excel5 ();
$objPHPExcel = $objReader->load ($inputFileName);
$sheet = $objPHPExcel->getsheet (0);
$highestRow = $sheet->gethighestrow (); Get the total number of rows
$highestColumn = $sheet->gethighestcolumn ();//Get the overall number of columns
$tempArray = Array ();
For ($j =2 $j <= $highestRow $j + +) {for
  ($k = ' A '; $k <= $highestColumn; $k + +) {
    if ($k = = ' h ') {//Specify H as column of time
      $tempArray [] = Gmdate ("y-m-d h:i:s", phpexcel_shared_date::exceltophp ($objPHPExcel->getactivesheet ()-> Getcell ("$k $j")->getvalue ());
    } else{
       $tempArray [] = $objPHPExcel->getactivesheet ()->getcell ("$k $j")->getvalue ();
    }
    echo "<pre>";
    Print_r ($tempArray);
    Unset ($tempArray);
    echo "</pre>";
  }
}

The exceltophp function in the Phpexcel_shared_date class is a key part!

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Common Methods Summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", " A summary of cookie usage in PHP, the basics of Smarty Templates tutorial and the PHP template technology summary.

I hope this article will help you with the PHP program design based on thinkphp framework.

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.