How to make all coumns of same width in Phpspreadsheet

I am using Php spreadsheet to export the data in Excel file.

Below is the code to export the data. Data is exporting correctly but the last column width is not same as the previous columns
As shown in the image below the last column width is not the same as previous columns
Current Image

image

Below is the code

public function actionExport()
    {
$spreadsheet = new Spreadsheet();

$sheet = $spreadsheet->getActiveSheet();
$sheet = $spreadsheet->removeSheetByIndex(0);


//Get dates of report which needs to be displayed on each sheets 
$sql='SELECT DateofReport from ascteacherreport where UserId=:Id order by DateofReport ASC';

$datesRows = \Yii::$app->db->createCommand($sql)->bindValues([':Id'=>\Yii::$app->user->identity->getonlyid()])
               ->queryColumn();

// Get times for each date report of user
$sql2 = ''; // contains the query to fetch the time



// Get student details for each time
$sql3 = ''; //contains the sql query to fetch students

$col1=3;
 $row = 7;
 $column1=2;
//Loop through dates for each sheet
foreach($datesRows as $date)
{
    $workSheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, $date);
    $spreadsheet->addSheet($workSheet);
    
    $params[':date'] = $date;

    // Execute the time query
     $timedetails = \Yii::$app->db->createCommand($sql2, $params)->queryAll(); 

foreach($timedetails as $idx => $td){
    $row1=9;
    $col = $idx +3;
    $rowno=9;

foreach ($workSheet->getColumnIterator() as $column) {
   $workSheet->getColumnDimension($column->getColumnIndex())->setWidth(28);
}
 $workSheet->getCellByColumnAndRow($col, $row)->setValue($td['Time'])->getStyle($col.$row) ->applyFromArray($styleArray); // Print Time

$params1[':Id']=$td['ASCReportDetailsId'];
$StudentDetails=\Yii::$app->db->createCommand($sql3, $params1)->queryAll();

foreach($StudentDetails as $id=>$StudentDetais1) // Print Student details
		  {
$workSheet->getCellByColumnAndRow($col,$row1++)->setValue($StudentDetais1['StudentName'])->getStyle($col1.$row1)->applyFromArray($styleArray1)->getFont()->setBold(true);

$workSheet->getCellByColumnAndRow($col,$row1++)->setValue($StudentDetais1['Subject'])->getStyle($col1.$row1)->applyFromArray($styleArray1)->getAlignment()->setWrapText(true);
$workSheet->getCellByColumnAndRow($col,$row1++)->setValue($StudentDetais1['Topic'])->getStyle($col1.$row1)->applyFromArray($styleArray1)->getAlignment()->setWrapText(true);
$workSheet->getCellByColumnAndRow($col,$row1++)->setValue($StudentDetais1['Confidence'])->getStyle($col1.$row1)->setQuotePrefix(true)->applyFromArray($styleArray1)->getAlignment()->setHorizontal('left');

$workSheet->getCellByColumnAndRow($column1, $rowno++)->setValue('Student Name')->getStyle($column1.$rowno)->applyFromArray($styleArray1);
$workSheet->getCellByColumnAndRow($column1, $rowno++)->setValue('Subject')->getStyle($column1.$rowno)->applyFromArray($styleArray1);
$workSheet->getCellByColumnAndRow($column1, $rowno++)->setValue('Topic')->getStyle($column1.$rowno)->applyFromArray($styleArray1);
$workSheet->getCellByColumnAndRow($column1, $rowno++)->setValue('Confidence')->getStyle($column1.$rowno)->applyFromArray($styleArray1);

$highestRow = $workSheet->getHighestRow();
$highestColumn = $workSheet->getHighestColumn();
	}
$workSheet->getStyle('C9:'.$highestColumn.''.$highestRow)->applyFromArray($styleArray1);
	}
}

$writer = new Xlsx($spreadsheet);



ob_start();

$writer->save('php://output');
$writer->save('Report'.'.xlsx');


header('Content-type: application/.xlsx');
header('Content-Disposition: attachment; filename="'.'Report'.'.xlsx"');
}

Hmm, looks like you are using ->setWidth() which is what I would recommend. Perhaps 28 isn’t a large enough value? Another option is the ->setAutoSize(true) method, but in this case I think you’d want to not set the ->setWrapText(true) as this may interfere with the autosizing.