I simply want the columns to autosized. I am using php spreadsheet and I can’t find how to do it. I have searched other questions but they are using functions that i can’t event find in my lib worksheet.php like getActiveSheet()
Any advise ? This is my code
$spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'Projects First Year'); $sheet->setCellValue('B1', 'Grades'); $sheet->setCellValue('A2', 'PHP Project 2020'); $sheet->setCellValue('B2', $_SESSION['phpScore']);
Advertisement
Answer
For spreadsheet the answer is:
require 'vendor/autoload.php'; use PhpOfficePhpSpreadsheetSpreadsheet; use PhpOfficePhpSpreadsheetWriterXlsx; use PhpOfficePhpSpreadsheetIOFactory; foreach (range('A','B') as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); }