PHPExcel notes, mpdf export

Source: Internet
Author: User
Tags php error log
This article mainly introduces PHPExcel notes and mpdf export. For more information, see phpexcel common operations.
# Import the class library require 'phpexcel/Classes/PHPExcel. php '; require 'phpexcel/Classes/PHPExcel/Writer/excel5.php'; // write class in non-07 Format # basic attribute settings $ objPHPExcel = \ PHPExcel_IOFactory: load('a.xls '); // read the specified excel file $ objPHPExcel-> setActiveSheetIndex (0); // specify the activity worksheet $ objPHPExcel-> getActiveSheet ()-> getDefaultStyle ()-> getFont () -> setName (' '); $ objPHPExcel-> getProperties ()-> setTitle ('XXX'); # cell editing $ objPHPExcel-> getActiveSheet ()-> setCel LValue ('A3 ', 'XXX'); // Set cell A3 to xxx # cell drawing $ objDrawing = new \ PHPExcel_Worksheet_Drawing (); $ objDrawing-> setPath('a.jpg '); // specify the image path. PHPExcel/Classes/PHPExcel/Worksheet/Drawing are required for remote images. php: replace file_exists in Section 106 with file_get_contents $ objDrawing-> setCoordinates ('A4 '); // specify to plot in cell A4 $ objDrawing-> setName ('photo '); $ objDrawing-> setDescription ('photo '); $ objDrawing-> setHeight (120); $ objDrawing-> setWidth (100); $ objDrawing-> setOffsetX (7 ); $ objDrawing-> setOffsetY (7); $ objDrawing-> setWorksheet ($ objPHPExcel-> getActiveSheet (); comment '; $ 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-Disposition: 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'); # html display of excel files (for debugging) $ objWriter = new \ PHPExcel_Writer_HTML ($ objPHPExcel); $ objWriter-> save ('php: // output ');
Use the mpdf library to export PDF files from phpexcel

Export '; $ encoded_filename = rawurlencode ($ filename); $ rendererName = \ PHPExcel_Settings: pai_renderer_mpdf; // specify to export the PDF file $ rendererLibraryPath = 'phpexcel/MPDF57' through the mpdf '; // specify the path of the mpdf class library you downloaded 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-Disposition: 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: // outp Ut '); ############################### pdf export failure troubleshooting methods ############################### 1. PHPExcel/Classes /PHPExcel/Writer/PDF/mPDF. php: add two lines at 105: $ pdf-> useAdobeCJK = true; $ pdf-> SetAutoFont (AUTOFONT_ALL); # Multiple preg_replace calls in the 2 class library use metacharacters e, some earlier versions of php do not support improper use of the regular expression emetacharacter emetacharacters, which may cause five or six triggering points of pdf errors in the class library, because the emetacharacters are called by php in a shell sub-process, the error message is not fed back to the current php process, so even if you configure an error to print it to the screen, the page also does not display the error message. you must view the php error log to view the php error log. In eg_replace, the call of metacharacters e is replaced by the call in the form of preg_replace_callback #3. some phpexcel class libraries have cell styles to identify incorrect lib/PHPExcel/Classes/PHPExcel/Writer/HTML. php: add an if clause at 1236 to judge if (! $ This-> _ useInlineCss) {$ cssClass. = 'style'. $ pSheet-> getCell ($ endCellCoord)-> getXfIndex ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.