gpt4 book ai didi

symfony - 如何使用phpexcel包读取xls文件?在 Symfony2

转载 作者:行者123 更新时间:2023-12-04 14:49:25 24 4
gpt4 key购买 nike

phpExcel 包提供了写入 xls 文件的方法,但我不知道如何使用此包读取 xls 文件。
可以在以下地址找到捆绑包:http://knpbundles.com/liuggio/ExcelBundle

谢谢你的帮助

最佳答案

如果你真的想阅读 EXCEL 文件,你可以在官方文档中找到一个例子:
https://github.com/PHPOffice/PHPExcel/blob/develop/Examples/28iterator.php

代码 :

$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();
$file = $this->get('kernel')->getRootDir()."/../web/uploads/import/membres.xlsx";
if (!file_exists($file)) {
exit("Please run 05featuredemo.php first." );
}
$objPHPExcel = \PHPExcel_IOFactory::load($file);

echo date('H:i:s') , " Iterate worksheets" , EOL;
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
echo 'Worksheet - ' , $worksheet->getTitle() , EOL;

foreach ($worksheet->getRowIterator() as $row) {
echo ' Row number - ' , $row->getRowIndex() , EOL;

$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
foreach ($cellIterator as $cell) {
if (!is_null($cell)) {
echo ' Cell - ' , $cell->getCoordinate() , ' - ' , $cell->getCalculatedValue() , EOL;
}
}
}
}


// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;

关于symfony - 如何使用phpexcel包读取xls文件?在 Symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9436576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com