首页 / PHP / phpspreadsheet
phpspreadsheet
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了phpspreadsheet,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2128字,纯文字阅读大概需要4分钟。
内容图文
![phpspreadsheet](/upload/InfoBanner/zyjiaocheng/1229/4defb96ee85347898f81b3bbf12a1699.jpg)
2019-5-9 8:20:07 星期四
昨天在看PHPExcel的时候, github上作者说已经停止更新了, 推荐使用phpspreadsheet,
查看了一下官方文档, 功能还挺强大的, 可以读取图表, 还可以读取格中使用了公式表计算的值, 而且是链式操作, 还使用了composer更新
简单写了一个小demo
安装
按照官网的命令, 先通过composer 把phpspreadsheet下载下来, 主要是使用autoload, phpspreadsheet有多层继承,抽象和接口
1. composer init
2. composer require phpoffice/phpspreadsheet
demo
1 include(‘D:/server/code/composer/vendor/autoload.php‘); //将安装phpspreadsheet后的 2 3use PhpOffice\PhpSpreadsheet\IOFactory; 4 5 6$inputFileType = ‘Xls‘; 7$inputFileName = ‘C:\Users\zhangzhibin\Downloads\PhpSpreadsheet-1.6.0\PhpSpreadsheet-1.6.0\samples\Reader\sampleData\example2.xls‘; 8 910$reader = IOFactory::createReader($inputFileType); 11$reader->setReadDataOnly(true); //只读取数据, 不读取其他东西12$worksheetData = $reader->listWorksheetInfo($inputFileName); //获取Excel中的所有表单的统计信息, 并不读取数据1314foreach ($worksheetDataas$worksheet) { 15echo ‘表单名‘ . $worksheet[‘worksheetName‘].‘<br>‘; 16echo ‘Rows: ‘ . $worksheet[‘totalRows‘] . ‘ Columns: ‘ . $worksheet[‘totalColumns‘].‘<br>‘; 17echo ‘Cell Range: A1:‘ . $worksheet[‘lastColumnLetter‘] . $worksheet[‘totalRows‘].‘<br>‘; 18} 1920//读取表单中的数据21try { 22echo ‘加载前内存使用 ‘.strval(memory_get_usage(false)).‘<br>‘; 23$spreadsheet = IOFactory::load($inputFileName); 24echo ‘加载后内存使用 ‘.strval(memory_get_usage(false)).‘<br>‘; 2526foreach ($spreadsheet->getWorksheetIterator() as$worksheet) { 27echo ‘表格名 - ‘ . $worksheet->getTitle().‘<br>‘; 2829foreach ($worksheet->getRowIterator() as$row) { 30echo ‘ 行号 - ‘ . $row->getRowIndex().‘ 当前使用内存:‘.memory_get_usage(false).‘<br>‘; 3132$cellIterator = $row->getCellIterator(); 33$cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set34foreach ($cellIteratoras$cell) { 35if ($cell !== null) { 36//echo ‘单元格 - ‘ . $cell->getCoordinate() . ‘ - ‘ . $cell->getCalculatedValue().‘<br>‘;37echo ‘单元格 - ‘ . $cell->getCoordinate() . ‘ - ‘ . $cell->getValue().‘<br>‘; 38 } 39 } 40 } 41 } 42 } catch (InvalidArgumentException $e) { 43echo$e->getMessage(); 44 }
原文:https://www.cnblogs.com/iLoveMyD/p/10836389.html
内容总结
以上是互联网集市为您收集整理的phpspreadsheet全部内容,希望文章能够帮你解决phpspreadsheet所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。