Questions about php excel reading

Source: Internet
Author: User
Tags php excel
For the php excel reading problem, after using the PHPexcel class to read an excel file, if the column in the excel file is of the date type, the date value cannot be displayed normally. How can I enable PHP to automatically determine whether the column to be read is of the date type? if it is of the date type, convert it to a value that can be normally displayed through the conversion function. ------ Solution -------------------- I have done this. I 'd like to give you a function and give it a try. previously I found the issue of PH reading excel from php on the Internet.
After reading an excel file in PHP excel, if the column in the excel file is of the date type, the date value cannot be displayed normally. How can I enable PHP to automatically determine whether the column to be read is of the date type? if it is of the date type, convert it to a value that can be normally displayed through the conversion function.

------ Solution --------------------
I have done this. I want to give you a function. I used to find it online.
PHP code
// Excel date conversion function excelTime ($ days, $ time = false) {if (is_numeric ($ days) {// based on 1900-1-1 $ jd = GregorianToJD (1, 1, 1970); $ gregorian = JDToGregorian ($ jd + intval ($ days)-25569); $ myDate = explode ('/', $ gregorian ); $ myDateStr = str_pad ($ myDate [2], 4, '0', STR_PAD_LEFT ). "-". str_pad ($ myDate [0], 2, '0', STR_PAD_LEFT ). "-". str_pad ($ myDate [1], 2, '0', STR_PAD_LEFT ). ($ time? "00:00:00": ''); return $ myDateStr;} elseif (strpos ($ days ,'.')! = 0) {return str_replace ('.', '-', $ days);} return $ days ;}

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.