php - PHPSpreadsheet textRotation to 90 not working

I am trying to use text Rotation to 90 to have cell with vertical text, but it is not working, all text shown horizontally, maybe I make something wrong? Here is my php code
$spreadsheet = new Spreadsheet();
// Create a new worksheet called "Technical Skills"
$technicalSkillsSheet = new Worksheet($spreadsheet, 'Technical Skills');
// Attach the "Technical Skills" worksheet as the first worksheet in the Spreadsheet object
$spreadsheet->addSheet($technicalSkillsSheet, TECHNICAL_SKILLS_INDEX);
$sheet = $spreadsheet->getSheet(TECHNICAL_SKILLS_INDEX);
foreach($term_sheet_array as $term_sheet){
$sheet->setCellValue($term_sheet['cell'], $term_sheet['name']);
$styleArray = array(
'fill' => array(
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
'startColor' => array(
'argb' => $term_sheet["color"],
),
),
'alignment' => array(
'wrapText' => TRUE,
'textRotation' => 90,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM,
),
);
$sheet->getStyle($term_sheet['cell'])->applyFromArray($styleArray);
$color_key++;
if($color_key >= count($sheetColors)){
$color_key = 0;
}
}
Answer
Solution:
Simple:
$activeSheet->getStyle('A1')->getAlignment()->setTextRotation(90);
Answer
Solution:
You can define text rotation in two ways:
First way:
$styleArray = [
'font' => [
'bold' => true,
'size' => 14,
],
'alignment' => [
'textRotation' => 90,
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER
]
];
$activeSheet->getStyle('A1')->getAlignment()->applyFromArray($styleArray);
Second way:
$activeSheet->getStyle('A1')->getAlignment()->setTextRotation(90);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: npm err! code 1
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.