我正在使用 phpspreadsheet v1.3.1。
我正在构建一个 Excel 文件(下载),一切正常。唯一的问题是定义 setPrintArea...它总是将标准 PrintArea 返回到 excel 中。基本上,我构建了 Excel 行并在定义 printArea 之后...我之前也尝试过这样做,但没有成功。
$spreadsheet = IOFactory::load("template.xlsx");
$worksheet = $spreadsheet->getActiveSheet();
foreach ($rows AS $k => $v ) {
$worksheet->getCell('F' . ($k + 3))->setValue($v);
$worksheet->getCell('G' . ($k + 3))->setValue($v);
}
$worksheet->getPageSetup()->setPrintArea('A1:AG58');
...
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output'); //-- force download version
该区域有 58 行,但我无法将区域设置为“AG”单元格...基本上,我想在一页上打印所有 excel,而不是打印到 8 行。
Thx !
setPrintArea() 定义要打印的内容,但不定义如何打印。
要将所有列 A->AG 和 58 行显示在单个页面上,您可以使用:
$worksheet->getPageSetup()->setFitToPage(true);
或限制一维
$worksheet->getPageSetup()->setFitToWidth(1);
$worksheet->getPageSetup()->setFitToHeight(0);
https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#setting-printer-options-for-excel-files https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#setting-printer-options-for-excel-files
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)