由mPDF使用phpExcel生成的PDF中的Cellpadding?

时间:2019-01-30 05:28:59

标签: php phpexcel mpdf

使用mPDF / phpExcel导出pdf时,是否可以向单元格中添加填充/间距?我的细胞紧挨着卡住,很难阅读。

//编辑。已更新代码...

如何向其中添加填充? $objWorksheet->getCellByColumnAndRow($excelCol,$excelRow)->getStyle()数组中的某个地方?

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

$objReader = PHPExcel_IOFactory::createReader("Excel2007");
$objReader->setIncludeCharts(TRUE);
$objPHPExcel = $objReader->load("excel.xlsx");

$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
$rendererLibraryPath = dirname(__FILE__) . '/mpdf';

$objWorksheet = $objPHPExcel->getActiveSheet();

$excelRow = 1;
$excelCol = 0;
$columns = Array('Title 1','Title 2','Title 3');
foreach($columns as $column_title)
{
    $objWorksheet->setCellValueByColumnAndRow($excelCol, $excelRow, $column_title);
    $objWorksheet->getCellByColumnAndRow($excelCol,$excelRow)->getStyle()->applyFromArray(
                array(
                    'font' => array(
                        'bold' => true,
                    ),
                    'alignment' => array(
                        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
                    ),
                    'borders' => array(
                        'top' => array(
                            'style' => PHPExcel_Style_Border::BORDER_THIN,
                            'color' => array('rgb' => '000000')
                        ),
                        'bottom' => array(
                            'style' => PHPExcel_Style_Border::BORDER_THIN,
                            'color' => array('rgb' => '000000')
                        )
                    ),
                    'fill' => array(
                        'type' => PHPExcel_Style_Fill::FILL_SOLID,
                        'color' => array('rgb' => 'd9d9d9')
                    )
                )
           );
    $objWorksheet->getColumnDimensionByColumn($excelCol)->setAutoSize(true);
    $objWorksheet->getCellByColumnAndRow($excelCol,$excelRow)->getStyle()->getAlignment()->setWrapText(false);
    $excelCol++;
}

$objWorksheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objWorksheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER);
$objWorksheet->getPageSetup()->setFitToPage(true);
$objWorksheet->getPageSetup()->setFitToWidth(1);
$objWorksheet->getPageSetup()->setFitToHeight(0);
$objWorksheet->getPageMargins()->setTop(0.5);
$objWorksheet->getPageMargins()->setRight(0.7);
$objWorksheet->getPageMargins()->setBottom(0.5);
$objWorksheet->getPageMargins()->setLeft(0.75);

if (!PHPExcel_Settings::setPdfRenderer(
        $rendererName,
        $rendererLibraryPath
    )) {
    die(
        'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
        '<br />' .
        'at the top of this script as appropriate for your directory structure'
    );
}

header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="pdf.pdf"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->save('php://output');
exit;

0 个答案:

没有答案