这是我从pdf中提取的数据框。 pdf中有3个子标题。我可以将范围,平均值和变化作为pettah的子列,以及平均值列的6月16日和6月15日。我希望所有范围的平均值,变化,6月16日和6月15日成为子标题列。将pdf转换为数据框时,默认使用unnamed。
<?php
namespace App\Jobs;
use App\Registration;
use Cyberduck\LaravelExcel\ImporterFacade;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class BulkUploadJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $path;
public function __construct($path)
{
$path = $path;
}
public function handle()
{
// Cyberduck Facade for Importing file from provided path
$excel = ImporterFacade::make('Excel');
// Loading file from local public path
$excel->load(public_path('uploads/' . $this->path));
// storing data in a collection variable
$collection = $excel->getCollection();
$batch = random_int(1111, 9999);
foreach ($collection as $reg) {
if (is_numeric($reg[0])) {
$registration = Registration::find($reg[0]);
if (isset($registration)) {
registration->firstname = $reg[1];
$registration->save();
} else {
$registration = new Registration();
$registration->id = $reg[0];
$registration->firstname = $reg[1];
$registration->save();
}
}
}
}
}