我正试图将详细目录描述放在中心位置。
我希望页面仅以A1-G1为中心,然后我合并并集中详细产品目录。问题在于,当我输出到PDF时,它仍然在页面的左侧,并且右侧有大量的空白区域。
<?php
include_once 'processor/dbconfig.php';
include_once 'Classes/PHPExcel.php';
/**
* PHPExcel
*
* Copyright (C) 2006 - 2014 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.8.0, 2014-03-02
*/
/** Error reporting */
/** Include PHPExcel */
require_once 'Classes/PHPExcel/IOFactory.php';
// Change these values to select the Rendering library that you wish to use
// and its directory location on your server
//$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
//$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
//$rendererLibrary = 'tcPDF5.9';
$rendererLibrary = '';
//$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = 'Classes/mpdf/' . $rendererLibrary;
$keyword = $_SESSION['btid'];
$sql = "SELECT * FROM patients WHERE order_id = :keyword";
$q=$con->prepare($sql);
$q->bindvalue(":keyword", $keyword);
$q->execute();
$data=$q->fetch(PDO::FETCH_ASSOC);
$pname = $data['first'] . " " . $data['last'];
$street = $data['street'];
$address = $data['city'] . "," . $data['state'] . " " . $data['zip'];
$phone = $data['phone'];
$dob = $data['dob'];
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$worksheet = $objPHPExcel->getActiveSheet();
// Add some data
$worksheet->mergeCells('A1:G1');
$worksheet->mergeCells('C16:E16');
$worksheet->mergeCells('C18:E18');
$worksheet->mergeCells('C20:E20');
$worksheet->mergeCells('C22:E22');
$worksheet->mergeCells('C24:E24');
$worksheet->mergeCells('C26:E26');
$worksheet->mergeCells('C28:E28');
//PATIENT SIDE
$worksheet->SetCellValueByColumnAndRow(0, 1, 'DETAILED Catalog DESCRIPTION');
$worksheet->SetCellValueByColumnAndRow(0, 3, 'Plan:');
$worksheet->SetCellValueByColumnAndRow(0, 4, 'Order ID:');
$worksheet->SetCellValueByColumnAndRow(0, 5, 'DOB:');
$worksheet->SetCellValueByColumnAndRow(0, 6, 'ADDRESS:');
$worksheet->SetCellValueByColumnAndRow(0, 8, 'PHONE:');
$worksheet->SetCellValueByColumnAndRow(0, 10, 'LENGTH OF');
$worksheet->SetCellValueByColumnAndRow(0, 11, 'NEED');
$worksheet->SetCellValueByColumnAndRow(1, 3, $pname);
$worksheet->SetCellValueByColumnAndRow(1, 6, $street);
$worksheet->SetCellValueByColumnAndRow(1, 7, $address);
$worksheet->SetCellValueByColumnAndRow(1, 5, $dob);
$worksheet->SetCellValueByColumnAndRow(1, 8, $phone);
$worksheet->SetCellValueByColumnAndRow(1, 11, '____________');
$worksheet->SetCellValueByColumnAndRow(0, 16, 'Number');
$worksheet->SetCellValueByColumnAndRow(1, 16, 'QTY');
$worksheet->SetCellValueByColumnAndRow(2, 16, 'DESCRIPTION/MAKE/MODEL');
//PROVIDER SIDE
$worksheet->SetCellValueByColumnAndRow(4, 3, 'SUPPLIER NAME:');
$worksheet->SetCellValueByColumnAndRow(4, 4, 'ADDRESS:');
$worksheet->SetCellValueByColumnAndRow(4, 6, 'PHONE:');
//WIDTH OF CELLS
$worksheet->getStyle("A1:G27")->getFont()->setSize(10);
$worksheet->getStyle("A1:G27")->getFont()->setName('Times New Roman');
$worksheet->getColumnDimension('A')->setAutoSize(true);
$worksheet->getColumnDimension('H')->setAutoSize(true);
$worksheet->getColumnDimension('F')->setWidth(14);
//CENTER ALIGN
$worksheet->getStyle("A1:G1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("C16:E16")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B18")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("A18")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("A16")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B16")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("F16")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("C20")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B20")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("A20")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("C22")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B22")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("A22")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("C24")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B24")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("A24")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("C26")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B26")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("A26")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("C28")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B28")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("A28")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle('A16:G17')->getFill()
->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
->setStartColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_YELLOW))
->setRotation(45);
$objPHPExcel->getActiveSheet()->setShowGridLines(false);
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'
);
}
// Redirect output to a client’s web browser (PDF)
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="new.pdf"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->save('php://output');
exit;
答案 0 :(得分:0)
一个老问题:但是万一有人还在看同样的问题。
几年前也遇到了mPDF的中心问题。
不仅仅是这个,还有很多问题。
mPDF不支持很多CSS样式:有些是浮点数,文本对齐只是为了说明一些。此外,PHPExcel在PHPExcel_Style_Alignment上使用text-align,如下面的函数所示。
private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle) {
$css = array();
$css['vertical-align'] = $this->_mapVAlign($pStyle->getVertical());
if ($textAlign = $this->_mapHAlign($pStyle->getHorizontal())) {
$css['text-align'] = $textAlign;
}
return $css;
}
对此的解决方法是使用此内部td标记(在普通表上尝试):
<th align="left"></th>
只是不确定如何在PHPExcel上添加它。