我正在使用 PhpSpreasdheet php 库。我已经完成了几乎所有我想要对特定列求和并想要显示该列的总数的所有内容。请参阅我的输出如下:-
我试过下面的代码: -
$spreadsheet = new Spreadsheet();
$Excel_writer = new Xlsx($spreadsheet);
$spreadsheet->setActiveSheetIndex(0);
$activeSheet = $spreadsheet->getActiveSheet();
$activeSheet->setCellValue('A1', 'Location');
$activeSheet->setCellValue('B1', 'Media Vehicle');
$activeSheet->setCellValue('C1', 'Dimension');
$activeSheet->setCellValue('D1', 'Amount');
$spreadsheet->getActiveSheet()->setAutoFilter('A1:D1');
$locations = DB::table('locations')->get();
$locations = json_decode(json_encode($locations),true);
$i = 2;
foreach($locations as $location){
$activeSheet->setCellValue('A'.$i , $location['location']);
$activeSheet->setCellValue('B'.$i , $location['media_vehicle']);
$activeSheet->setCellValue('C'.$i , $location['dimension']);
$activeSheet->setCellValue('D'.$i , $location['amount']);
$i++;
}
$samplepath = storage_path('/excels/sampleExcel'.str_random(5).'.xlsx');
$Excel_writer->save($samplepath);
echo 'saved'; die;
我想要总金额栏。我想让动态。如果将来它将是 10 行,那么它将计算 10 行的数量列数。