Postingan lainnya
Export data dengan phpexcel selalu object of class stdclass could not be converted to string
Hallo semua, saya newbie ! Saya punya koding seperti ini:
$dataArray = [];
$header = $this->getHeader($schedule_id);
$discs = DB::table('interview_test_disc_answer')
->where('id_interview_schedules', $schedule_id)
->select('sort','ops_a', 'ops_b', 'ops_c', 'ops_d')
->orderby('sort', 'ASC')
->whereNull('deleted_at');
$dataArray[] = ['No', 'Col A', 'Col B', 'Col C', 'Col D'];
$dataArray[] = $discs->get()->toArray();
//foreach($discs as $row){
// $dataArray[] = $row->toArray();
//}
//var_dump($dataArray);
Excel::create('disc-applications', function($excel) use ($dataArray, $header){
$excel->setTitle('Disc Applications');
$excel->setCreator('Recruit')->setCompany($this->companyName);
$excel->setDescription('disc-applications file');
$excel->sheet('sheet1', function ($sheet) use ($dataArray, $header) {
$sheet->setCellValue('A1', 'Title');
$sheet->setCellValue('B1', 'Disc Applications');
$sheet->setCellValue('A2', 'Name');
$sheet->setCellValue('B2', $header->full_name);
$sheet->setCellValue('A3', 'Position');
$sheet->setCellValue('B3', $header->title);
$sheet->setCellValue('A4', 'Location');
$sheet->setCellValue('B4', $header->location);
$sheet->fromArray($dataArray, null, 'A7', false, false);
$sheet->row(1, function ($row) {
$row->setFont(array(
'bold' => true
));
});
});
})->download('xlsx');
Tapi selalu error: Object of class stdClass could not be converted to string
Adakah yg keliru dari kodingan tersebut?
0
Tanggapan
errornya pada baris berapa (di kode kamu baris yang mana) keterangannya, agar yang mau bantu juga lebih mudah
1 Jawaban:
saya menduga variabel $header ini, bukan tipe objek tapi array; sehingga menimbulkan error. object of class stdclass could not be converted to string. Cobak cek.
0