Phpexcel Exporting PDF files garbled

Source: Internet
Author: User
The code procedure is to read the template file Template.xls. Write the corresponding content and export the PDF file. The Template.xls file contains tables and Japanese. Personally think that there is no font for the reason, but how to correspond to the King Prawn told!!!
Require_once ' excel/phpexcel.php '; $objPHPExcel = Phpexcel_iofactory::load ("Template.xls"); $objPHPExcel Setactivesheetindex (0); $objWorksheet = $objPHPExcel->getactivesheet ();//write Content $objworksheet->getcell ("C1")- >setvalue ("test");//dummy film $objdrawing = new Phpexcel_worksheet_drawing (); $objDrawing->setname (' Stamp '); $ Objdrawing->setdescription ("AAAA"), $objDrawing->setpath ("images/p1.jpg"); $objDrawing->setcoordinates ( ' M1 '); $objDrawing->setoffsetx ($objDrawing->setrotation); $objDrawing->setheight (73); $ Objdrawing->getshadow ()->setvisible (true), $objDrawing->getshadow ()->setdirection (), $objDrawing- >setworksheet ($objWorksheet); $objWorksheet->settitle (' simple '); Ob_end_clean (); Header (' Content-type: Application/pdf '); header (' Content-disposition:attachment;filename= "detail.pdf"); Header (' Cache-control:max-age =0 '); $objWriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' PDF '); $objWriter->save (' Php://output '); exit;


Reply to discussion (solution)

Exported PDF file, border is very coarse, Japanese content is garbled

What is the UTF-8 code?? If not, use Iconv????。

No coding problem, garbled problem solved.
Simplified Chinese display, font set to Arialunicid0-chinese-simplified
Japanese display, font set to Arialunicid0-japanese

Hope to be useful to everyone.
However, there is no solution to the problem of displaying the thick black box ~ ~ ~

What is the UTF-8 code?? If not, use Iconv????。


There is no coding problem.
Simplified Chinese display, font set to Arialunicid0-chinese-simplified
Japanese display, font set to Arialunicid0-japanese.

Phpexcel generates a PDF with a major flaw: if you have a picture in Excel, the resulting PDF will not be retained, so you can use this to generate PDF files is not the best solution!

Phpexcel generates a PDF with a major flaw: if you have a picture in Excel, the resulting PDF will not be retained, so you can use this to generate PDF files is not the best solution!


Many of the predetermined content is constant, and the format requirements are complex, so the content and format into a template xls file. This feature does not involve the picture.

There is no better solution, not to write all the content, but first import the template, based on the template to modify the content, save as a PDF file? Prawn recommend a Solution ~ ~


Phpexcel generates a PDF with a major flaw: if you have a picture in Excel, the resulting PDF will not be retained, so you can use this to generate PDF files is not the best solution!


Many of the predetermined content is constant, and the format requirements are complex, so the content and format into a template xls file. This feature does not involve the picture.

There is no better solution, not to write all the content, but first import the template, based on the template to modify the content, save as a PDF file? Prawn recommend a Solution ~ ~



According to the code scheme above, you can keep the picture of the dynamic writing cell in the PDF.



Phpexcel generates a PDF with a major flaw: if you have a picture in Excel, the resulting PDF will not be retained, so you can use this to generate PDF files is not the best solution!


Many of the predetermined content is constant, and the format requirements are complex, so the content and format into a template xls file. This feature does not involve the picture.

There is no better solution, not to write all the content, but first import the template, based on the template to modify the content, save as a PDF file? Prawn recommend a Solution ~ ~



According to the code scheme above, you can keep the picture of the dynamic writing cell in the PDF.



However, the display format of the problem, do not know if encountered, for a moment, I upload a picture.

is an Excel template file


The following figure is the resulting PDF file, why the format is inconsistent with the Excel template file

I used the 2.1 version of the test, the generated PDF, the cell border support is not very good, inexplicably there will be some bold border, the specific code-level reasons have not been well analyzed; maybe that's a flaw in it.

Personal feeling you use it to deal with the PDF, just like you have to use a bike to drive the speed of the car, after all, this is not its professional, it is the professional operation of Excel

Personal feeling you use it to deal with the PDF, just like you have to use a bike to drive the speed of the car, after all, this is not its professional, it is the professional operation of Excel


Thank you for your expert ^_^
  • 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.