What file is the above written on in OP's Laravel project? (My question is not only to the OP but to everyone reading.)
Laravel Excel Cropping column
I am using Laravel excel with TCPDF to export data to PDF. I have a column that has long values and its cropping the data. Is there a way I can wrap text and make the data visible?
I have tried few things like setting width and wrap text but both doesnt seem to work.
I have tried to wrap text using
$event->sheet->getDelegate()->getStyle('A1:W1')->getAlignment()->setWrapText(true); and setting width using
$event->sheet->getDelegate()->getColumnDimension($column)->setWidth(50); Both have been written under AfterSheet function.
AfterSheet::class => function (AfterSheet $event) {
$event->sheet->getDelegate()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); $event->sheet->getDelegate()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4); $event->sheet->getDelegate()->getPageMargins()->setLeft(0.3);
$event->sheet->getDelegate()->getHeaderFooter()->setDifferentOddEven(false);
$event->sheet->getDelegate()->getHeaderFooter()->setOddFooter('&R&F Page &P / &N');
$event->sheet->getDelegate()->getPageSetup()->setFitToPage(true);
if (count($this->results)) {
// Custom Formatting to set width of columns:
for ($i = 1; $i <= count(reset($this->results)); $i++) {
$column = Coordinate::stringFromColumnIndex($i);
//$event->sheet->getDelegate()->getColumnDimension($column)->setAutoSize(true);
$event->sheet->getDelegate()->getColumnDimension($column)->setWidth(50);
$event->sheet->getDelegate()->getStyle('A1:W1')->getAlignment()->setWrapText(true);
}
}
},
Please or to participate in this conversation.