Home > Article > Backend Development > When PHPexcel imports excel data, string format the data in the rows and columns_PHP tutorial
In the process of using phpExcel, it is inevitable to encounter various problems, especially when importing excel tables. We always cannot get the expected excel data from the editor, such as the following:
Obviously, I actually just want the text in this object, it it it. . . Some people won’t be able to bear it
In fact, the solution to this problem is very simple. Here 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, just add a (string) in front of $objPHPExcel->getActiveSheet ()->getCell ( "$k$j" )->getValue ();
It's that simple!