捆绑phpExcel提供了写xls文件的方式,但我不知道如何使用此捆绑包读取文件xls ..捆绑包可以在以下地址找到:http://knpbundles.com/liuggio/ExcelBundle
谢谢你的帮助
小智 5
如果您真的想阅读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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12837 次 |
| 最近记录: |