123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace Tool\ShanTaoTool;
- use Tool\ShanTaoTool\Excel\Export;
- use Tool\ShanTaoTool\Exception\FileException;
- class ExcelTool
- {
- /**
- * 导出csv文件
- * @param array $headers 列名
- * @param array $datas 数据
- * @param string $fileName 文件名
- */
- public static function exportToCsv($headers,$datas,$fileName)
- {
- $export = new Export();
- $export->exportToCsv($headers,$datas,$fileName);
- }
- /**
- * 导出excel文件
- * @param array $headers 列名
- * @param array $datas 数据
- * @param string $fileName 文件名
- */
- public static function exportToExcel($headers,$datas,$fileName)
- {
- $export = new Export();
- $export->exportToExcel($headers,$datas,$fileName);
- }
- /**
- * 获取csv内容
- * @param string $filePath 文件内容
- */
- public static function importCsv($filePath)
- {
- $handle = fopen($filePath,"r");
- if(!$handle){
- throw new FileException("文件打开失败");
- }
- $list=[];
- while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
- $num = count($data);
- for ($c=0; $c < $num; $c++) {
- $arr[]=$data[$c];
- }
- $list[]=$arr;
- unset($arr);
- }
- fclose($handle);
- return $list;
- }
- /**
- * 获取excel的内容
- * @param $filePath
- */
- public static function importExcel($filePath)
- {
- $export = new Export();
- return $export->importExcel($filePath);
- }
- }
|