When importing excel data in PHPexcel, format the data strings in the row and column.

Source: Internet
Author: User
In the process of using phpExcel, various problems are inevitable. especially when importing an excel table, we cannot always obtain the expected excel data from editing. for example, the following is: obviously, I only want the text in this object, and it just needs it... Some will be affected... syntaxHighlighter. all (); in the process of using phpExcel, it is inevitable that you will encounter a variety of problems, especially when importing an excel table, we are always unable to get the expected excel data from editing, for example, the following is:

 
Obviously, I only want the text in this object, and it just needs it... Some cannot stand it.
In fact, this solution is very simple. The following is the entire code snippet.
 

[Php]
Require_once SITE_PATH. '/PHPExcle/Classes/PHPExcel. php ';
Require_once SITE_PATH. '/PHPExcle/Classes/PHPExcel/IOFactory. php ';
Require_once SITE_PATH. '/PHPExcle/Classes/PHPExcel/Reader/Excel5.php ';
$ ObjReader = PHPExcel_IOFactory: createReader ('excel5 ');
 
$ ObjPHPExcel = $ objReader-> load ($ fileurl );
$ Sheet = $ objPHPExcel-> getSheet (0 );
$ HighestRow = $ sheet-> getHighestRow ();
$ HighestColumn = $ sheet-> getHighestColumn ();
 
For ($ j = 2; $ j <= $ highestRow; $ j ++ ){
For ($ k = 'a'; $ k <= $ highestColumn; $ k ++ ){
$ Array [$ j] [$ k] = (string) $ objPHPExcel-> getActiveSheet ()-> getCell ("$ k $ j")-> getValue ();
}
}
?>

That is, add a (string) in front of $ objPHPExcel-> getActiveSheet ()-> getCell ("$ k $ j")-> getValue ();.
That's easy!


Author longxuu

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.