因此,我使用PHPExcel生成包含数据库数据的电子表格。我将特定列设置为特定宽度。但是,当我尝试使用整个电子表格的默认字体时,这些宽度似乎被忽略,工作表变宽。我用这个错了吗? @Mark Baker在哪里?
$objPHPExcel = new PHPExcel();
$phpColor = new PHPExcel_Style_Color();
$phpColor->setRGB('051C48');
$objPHPExcel->getDefaultStyle()->getFont()->setColor($phpColor);
$objPHPExcel->getDefaultStyle()->getFont()->setName('Gotham Book');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
$activeSheet = $objPHPExcel->getActiveSheet();
$activeSheet->setShowGridlines(false);
foreach(range('A','F') as $columnID){
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(false);
}
///////////////////////////////// FIRST PHASE /////////////////////////////////////////////////////////
$activeSheet->getColumnDimension('A')->setWidth(22.71);
$activeSheet->getColumnDimension('B')->setWidth(31.71);
$activeSheet->getColumnDimension('C')->setWidth(9.71);
$activeSheet->getColumnDimension('D')->setWidth(9.71);
$activeSheet->getColumnDimension('E')->setWidth(11.85);
$activeSheet->getColumnDimension('F')->setWidth(17.57);
如果您想了解更多信息,请告诉我们。我意识到这些截图可能不是显示最新情况的最佳方法。然而,我可以设置单元格的范围,我只是希望通过设置默认值来获得更清晰的代码。此外,如果我要特定和有需要,请忽略我
$activeSheet->getStyle('A1:F1')->applyFromArray($firstRowStyle);
$activeSheet->getStyle('B2:B50')->applyFromArray($gothamBook10);
$activeSheet->getStyle('C2:C50')->applyFromArray($gothamBook10);
$activeSheet->getStyle('D2:D50')->applyFromArray($gothamBook10);
$activeSheet->getStyle('E2:E50')->applyFromArray($gothamBook10);
$activeSheet->getStyle('F2:F50')->applyFromArray($gothamBook10);