我正在尝试使用文本旋转到90以使单元格具有垂直文本,但它不起作用,所有文本水平显示,也许我做错了什么? 这是我的PHP代码
$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;
}
}
答案 0 :(得分:0)
简单:
$activeSheet->getStyle('A1')->getAlignment()->setTextRotation(90);
答案 1 :(得分:0)
您可以通过两种方式定义文本旋转:
第一种方式:
$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);
第二种方式:
$activeSheet->getStyle('A1')->getAlignment()->setTextRotation(90);