我现在使用PHPSpreadsheet,我试图让行自动高度。它在MSOffice中工作正常,但在LibreOffice中不工作。
问题如何在LibreOffice最新版本中启用行自动高度功能。在MSOffice中正常。
自动高度
$spreadsheet->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
foreach($spreadsheet->getActiveSheet()->getRowDimensions() as $rowID) {
$rowID->setRowHeight(-1);
}
字符串
控制器
<?php
require(APPPATH . 'vendor/autoload.php');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class Events extends MX_Controller {
public function test() {
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('')
->setLastModifiedBy('')
->setTitle('')
->setSubject('')
->setDescription('');
$spreadsheet->getDefaultStyle()->getFont()->setName('Arial');
$spreadsheet->getDefaultStyle()->getFont()->setSize(24);
foreach(range('A','B') as $columnID) {
$spreadsheet->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
$spreadsheet->getActiveSheet()->getStyle('A')->getAlignment()->setWrapText(true);
$spreadsheet->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
foreach($spreadsheet->getActiveSheet()->getRowDimensions() as $rowID) {
$rowID->setRowHeight(-1);
}
$spreadsheet->setActiveSheetIndex(0)
->setCellValue("A1",'Firstname')
->setCellValue("B1",'Lastname')
->setCellValue("A2",'John')
->setCellValue("B2",'Doe');
$spreadsheet->getActiveSheet()->setTitle('Users Information');
$spreadsheet->setActiveSheetIndex(0);
/* Here there will be some code where you create $spreadsheet */
// redirect output to client browser
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="myfile.xls"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
exit;
}
}
型
1条答案
按热度按时间2wnc66cl1#
尝试以下代码
字符串