首页 > 编程知识 正文

Excel对比两列数据重复项,excel两列数据比较重复项

时间:2023-05-04 01:23:09 阅读:280862 作者:3836

这里用的是laravel框架,需求是把几个sheet里面的两列的重复值筛选出来,excel本身好像有这个函数,但不太会用,自定义也不强,我就自己写了个函数,直接上代码:

public function helpDada($value = '') { $files = Storage::allFiles('testData'); foreach ($files as $key => $excel_file_path) { $excel_file_path = 'D:/phpStudy/WWW/' . $excel_file_path; // 按照sheet名字取值 selectSheets('sheet1', 'sheet2') // 按照index取值 selectSheetsByIndex(0,1,2,3),注意,第一个sheet的index为0 $excel_data = Excel::selectSheetsByIndex(1, 2, 3) ->load($excel_file_path) //只取这两列 ->get(['pre_u', 'bcc']) ->toArray(); $sheet2 = array_unique(array_intersect(array_column($excel_data[0], 'pre_u'), array_column($excel_data[0], 'bcc'))); $sheet3 = array_unique(array_intersect(array_column($excel_data[1], 'pre_u'), array_column($excel_data[1], 'bcc'))); $sheet4 = array_unique(array_intersect(array_column($excel_data[2], 'pre_u'), array_column($excel_data[2], 'bcc'))); dd($sheet2, $sheet3, $sheet4); dd(count($sheet2) - 1, count($sheet3) - 1, count($sheet4) - 1); }}

更多用法:
http://www.maatwebsite.nl/laravel-excel/docs/import

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。