Phpexcel Common Processing
# #导入类库 require ' phpexcel/classes/phpexcel.php '; Require ' phpexcel/classes/phpexcel/writer/excel5.php '; Write Class # #基础属性设定 $objPHPExcel = \phpexcel_iofactory::load (' A.xls ') in non-07 format; Read into the specified Excel file $objPHPExcel->setactivesheetindex (0);
Specifies the active worksheet $objPHPExcel->getactivesheet ()->getdefaultstyle ()->getfont ()->setname (' Arial ');
$objPHPExcel->getproperties ()->settitle (' xxx '); # #单元格编辑 $objPHPExcel->getactivesheet ()->setcellvalue (' A3 ', ' xxx ');
Set A3 cell value to XXX # #单元格绘图 $objDrawing = new \phpexcel_worksheet_drawing (); $objDrawing->setpath (' a.jpg '); Specifies the picture path. To phpexcel/classes/phpexcel/worksheet/drawing.php:106 a remote picture, replace file_exists with file_get_contents $objDrawing-> Setcoordinates (' A4 ');
Specifies that the drawing $objDrawing->setname (' Photo ') in the A4 cell;
$objDrawing->setdescription (' Photo ');
$objDrawing->setheight (120);
$objDrawing->setwidth (100);
$objDrawing->setoffsetx (7);
$objDrawing->setoffsety (7);
$objDrawing->setworksheet ($objPHPExcel->getactivesheet ()); # #excel文件浏览器下载Export $filename = ' A.xls ';
$encoded _filename = Rawurlencode ($filename);
$ua = $_server["Http_user_agent"];
Header (' Content-type:application/vnd.ms-excel '); if (Preg_match ("/msie/", $ua) | | preg_match ("/trident\/7.0/", $ua) | | preg_match ("/edge/", $ua)) {header (' Content-dispo Sition:attachment; Filename= "'. $encoded _filename. '"');
} else if (Preg_match ("/firefox/", $ua)) {header ("content-disposition:attachment; Filename*=\ "UTF8 '". $filename. '"');
} else {header (' content-disposition:attachment filename= '. $filename.
'"');
}
Header ("Pragma:no-cache");
Header ("expires:0");
$objWriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 ');
$objWriter->save (' php://output ');
# #excel文件html显示 (available for debugging) $objWriter = new \phpexcel_writer_html ($objPHPExcel); $objWriter->save (' php://output ');
Export PDF files from Phpexcel using the Mpdf library
$filename = ' a.pdf ';
$encoded _filename = Rawurlencode ($filename); $rendererName = \phpexcel_settings::P df_renderer_mpdf; Specifies that the PDF file is exported through the Mpdf class library $rendererLibraryPath = ' phpexcel/mpdf57 '; Specifies that you downloaded the Mpdf class library path if (!\phpexcel_settings::setpdfrenderer ($rendererName, $rendererLibraryPath)) {die (' please
Set the $rendererName and $rendererLibraryPath values '.
Php_eol.
' As appropriate for your directory structure ');
Header (' content-type:application/pdf '); if (Preg_match ("/msie/", $ua) | | preg_match ("/trident\/7.0/", $ua) | | preg_match ("/edge/", $ua)) {header (' Content-dispo Sition:attachment; Filename= "'. $encoded _filename. '"');
} else if (Preg_match ("/firefox/", $ua)) {header ("content-disposition:attachment; Filename*=\ "UTF8 '". $file _name. '"');
} else {header (' content-disposition:attachment filename= '. $file _name.
'"');
}
Header ("Pragma:no-cache");
Header ("expires:0");
$objWriter = new \phpexcel_writer_pdf ($objPHPExcel); $objWriter->setprecalculatEformulas (FALSE);
$objWriter->save (' php://output '); ############################## # #pdf导出失败的一些错误解决方法 ############################## # #1 PDF Chinese garbled problem phpexcel/classes/
phpexcel/writer/pdf/mpdf.php:105 Place add two lines set: $pdf->USEADOBECJK = true;
$pdf->setautofont (Autofont_all); # #2 Class Library There are multiple preg_replace calls using the Meta character e, and some of the lower version of PHP does not support the regular expression e-meta character e-meta character of improper use and lead to a PDF error trigger point in the class library there are about five or six, because e-meta character is a shell under the child process PHP call , so the error information will not be fed back to the current PHP process, so even if you have configured the wrong print to the screen, the page will not display errors, you must check the PHP error log to check the PHP error log, the hint of the preg_replace in the preg_replace_ of the call of the character E to replace the Callback form of Call # #3 partial version Phpexcel class Library has cell styles to judge errors lib/phpexcel/classes/phpexcel/writer/html.php:1236 add an If to judge if (! $this- >_USEINLINECSS) {$cssClass. = ' style '. $pSheet->getcell ($endCellCoord)->getxfindex ();