试图从 Symfony3 中的命名空间加载 class "PHPExcel_Cell"
Attempted to load class "PHPExcel_Cell" from namespace in Symfony3
Attempted to load class "PHPExcel_Cell" from namespace "ImportBundle\Traits".
Did you forget a "use" statement for another namespace?
500 Internal Server Error - ClassNotFoundException
我试过 use PHPExcel\Cell;
但还是不行。我不知道如何加载 class 或 holiuggiow 以将列索引获取为整数。
我使用 PHPExcel_Cell::stringFromColumnIndex
的原因是因为我想使用该方法将列索引获取为整数。
提前感谢您的帮助。
private function test($objPHPExcel)
{
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$columnIndex = $worksheet->getHighestColumn();
// Get error when on this line
echo PHPExcel_Cell::stringFromColumnIndex($columnIndex)
}
}
试试这个:
echo \PHPExcel_Cell::stringFromColumnIndex($columnIndex)
而不是这个:
echo PHPExcel_Cell::stringFromColumnIndex($columnIndex)
除了@Matteo 已经回答的命名问题:
The reason I use the PHPExcel_Cell::stringFromColumnIndex because I want use that method to get column index as integer.
stringFromColumnIndex()
取一个数字列索引(0、1、2 等),returns 取一个字符串(A、B、C 等),所以与你说的相反你想做什么;
和 getHighestColumn()
returns 一个字符串(A、B、C 等),因此您试图通过将字符串视为整数来将字符串列地址转换为字符串列地址, 根据 PHP 宽松类型规则,它将把任何字符串地址视为 0。
您应该改用 columnIndexFromString()
,它采用字符串列地址(A、B、C 等)和 returns 数字(1、2、3 等)。
Attempted to load class "PHPExcel_Cell" from namespace "ImportBundle\Traits".
Did you forget a "use" statement for another namespace?
500 Internal Server Error - ClassNotFoundException
我试过 use PHPExcel\Cell;
但还是不行。我不知道如何加载 class 或 holiuggiow 以将列索引获取为整数。
我使用 PHPExcel_Cell::stringFromColumnIndex
的原因是因为我想使用该方法将列索引获取为整数。
提前感谢您的帮助。
private function test($objPHPExcel)
{
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$columnIndex = $worksheet->getHighestColumn();
// Get error when on this line
echo PHPExcel_Cell::stringFromColumnIndex($columnIndex)
}
}
试试这个:
echo \PHPExcel_Cell::stringFromColumnIndex($columnIndex)
而不是这个:
echo PHPExcel_Cell::stringFromColumnIndex($columnIndex)
除了@Matteo 已经回答的命名问题:
The reason I use the PHPExcel_Cell::stringFromColumnIndex because I want use that method to get column index as integer.
stringFromColumnIndex()
取一个数字列索引(0、1、2 等),returns 取一个字符串(A、B、C 等),所以与你说的相反你想做什么;
和 getHighestColumn()
returns 一个字符串(A、B、C 等),因此您试图通过将字符串视为整数来将字符串列地址转换为字符串列地址, 根据 PHP 宽松类型规则,它将把任何字符串地址视为 0。
您应该改用 columnIndexFromString()
,它采用字符串列地址(A、B、C 等)和 returns 数字(1、2、3 等)。