国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
PHPExcel notes, mpdf export, phpexcelmpdf
phpexcel common processing
Use mpdf library to export pdf files from phpexcel
Home Backend Development PHP Tutorial PHPExcel notes, mpdf export, phpexcelmpdf_PHP tutorial

PHPExcel notes, mpdf export, phpexcelmpdf_PHP tutorial

Jul 12, 2016 am 08:53 AM
phpexcel

PHPExcel notes, mpdf export, phpexcelmpdf

phpexcel common processing

##導(dǎo)入類庫
require 'PHPExcel/Classes/PHPExcel.php';
require 'PHPExcel/Classes/PHPExcel/Writer/Excel5.php'; //非07格式的寫出類
 
##基礎(chǔ)屬性設(shè)定
$objPHPExcel = \PHPExcel_IOFactory::load('a.xls'); //讀入指定excel文件
$objPHPExcel->setActiveSheetIndex(0); //指定活動工作表
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('宋體');
$objPHPExcel->getProperties()->setTitle('xxx');
 
##單元格編輯
$objPHPExcel->getActiveSheet()->setCellValue('A3', 'xxx'); //設(shè)定A3單元格值為xxx
 
##單元格繪圖
$objDrawing = new \PHPExcel_Worksheet_Drawing();
$objDrawing->setPath('a.jpg'); //指定圖片路徑。若要遠(yuǎn)程圖片需PHPExcel/Classes/PHPExcel/Worksheet/Drawing.php:106處file_exists換成file_get_contents
$objDrawing->setCoordinates('A4'); //指定在A4單元格繪圖
$objDrawing->setName('Photo');
$objDrawing->setDescription('Photo');
$objDrawing->setHeight(120);
$objDrawing->setWidth(100);
$objDrawing->setOffsetX(7);
$objDrawing->setOffsetY(7);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
 
##excel文件瀏覽器下載導(dǎo)出
$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-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');
 
##excel文件html顯示(可用于調(diào)試)
$objWriter = new \PHPExcel_Writer_HTML($objPHPExcel);
$objWriter->save('php://output');

Use mpdf library to export pdf files from phpexcel

$filename='a.pdf';
$encoded_filename = rawurlencode($filename);
$rendererName = \PHPExcel_Settings::PDF_RENDERER_MPDF; //指定通過mpdf類庫導(dǎo)出pdf文件
$rendererLibraryPath = 'PHPExcel/MPDF57'; //指定你下載的mpdf類庫路徑
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://output');
 
 
##############################
##pdf導(dǎo)出失敗的一些錯誤解決方法
##############################
 
##1 pdf中文亂碼問題
PHPExcel/Classes/PHPExcel/Writer/PDF/mPDF.php:105處加兩行設(shè)定:
$pdf->useAdobeCJK = true;
$pdf->SetAutoFont(AUTOFONT_ALL);
 
##2 類庫里面多處preg_replace調(diào)用使用了元字符e,而部分低版本php不支持正則表達式e元字符
e元字符的不當(dāng)使用并導(dǎo)致pdf報錯的觸發(fā)點在類庫里面大概有五六處吧,
由于e元字符是一個shell下的子進程php調(diào)用,所以報錯信息不會反饋到當(dāng)前php進程中,故即便你配置了錯誤打印到屏幕, 頁面也不會顯示報錯信息, 必須查看php報錯日志
查看php報錯日志,把提示的preg_replace中元字符e的調(diào)用替換為preg_replace_callback形式的調(diào)用
 
##3 部分版本phpexcel類庫有單元格樣式判斷錯誤
lib/PHPExcel/Classes/PHPExcel/Writer/HTML.php:1236處加個if判斷
if (!$this->_useInlineCss) {
  $cssClass .= ' style' . $pSheet->getCell($endCellCoord)->getXfIndex();

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125248.htmlTechArticlePHPExcel notes, mpdf export, phpexcelmpdf phpexcel common processing ##Import class library require 'PHPExcel/Classes/PHPExcel.php ';require 'PHPExcel/Classes/PHPExcel/Writer/Excel5.php'; //Non-07 format...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Complete Guide: How to process Excel files using php extension PHPExcel Complete Guide: How to process Excel files using php extension PHPExcel Jul 28, 2023 pm 10:01 PM

Complete Guide: How to Process Excel Files Using PHP Extension PHPExcel Introduction: Excel files are often used as a common format for data storage and exchange when processing large amounts of data and statistical analysis. Using the PHP extension PHPExcel, we can easily read, write and modify Excel files to effectively process Excel data. This article will introduce how to use the PHP extension PHPExcel to process Excel files and provide code examples. 1. Install PHPExc

PHP development: Use PHPExcel to process Excel files PHP development: Use PHPExcel to process Excel files Jun 15, 2023 pm 03:45 PM

With the advent of the digital age, data has become the most important part of our daily lives and work, and Excel files have become one of the important tools for data processing. I believe that many PHP developers will often encounter the use of Excel files for data processing and operations at work. This article will introduce you to the methods and precautions for using the PHPExcel library to process Excel files. What is PHPExcel? PHPExcel is a PHP class

How to use phpexcel to convert Excel files to CSV files and open them How to use phpexcel to convert Excel files to CSV files and open them Mar 27, 2023 pm 04:16 PM

?PHPEXCEL is an excellent PHP class library for reading and writing Excel files. It provides a very sufficient API that allows us to use PHP to read and write Excel files. Sometimes, we need to convert Excel files into CSV files for use on some occasions. So, this article mainly describes how to use the PHPEXCEL class library to convert Excel files into CSV files and open them.

Why phpexcel has become the focus of PHP developers Why phpexcel has become the focus of PHP developers Mar 27, 2023 pm 06:15 PM

PHPExcel is an open source PHP library for processing Microsoft Excel files. It can read, create, modify and save Excel files. It is a powerful and highly customizable tool that can be used to handle tasks such as data analysis, report generation, data import and export, etc. In this article, we will introduce why PHPExcel has become the focus of PHP developers.

Create Excel files using PHP and PHPExcel Create Excel files using PHP and PHPExcel May 11, 2023 am 08:40 AM

In today's era of rapid information transfer, data processing and storage have become increasingly important. The use of Excel tables is the first choice for many people because Excel tables can integrate various data and can be easily analyzed and processed. In order to complete the creation of Excel tables more efficiently, we can use two powerful tools, PHP and PHPExcel. In this article, we will introduce how to create Excel files using PHP and PHPExcel. 1. Install PHPExcel first

How to use PHPExcel to process Excel files? How to use PHPExcel to process Excel files? Jun 01, 2023 pm 02:01 PM

PHPExcel is an open source PHP library for processing Microsoft Excel (.xls and .xlsx) files. It can read, write and operate Excel files, and provides a wealth of functions and methods. Using the PHPExcel library in PHP projects, you can quickly and easily process Excel files and implement functions such as data import, export and data processing. This article will introduce how to use PHPExcel to process Excel files. 1. To install PHPExcel, use

PHP development tips: How to use PHPExcel and PHPExcel_IOFactory to operate MySQL database PHP development tips: How to use PHPExcel and PHPExcel_IOFactory to operate MySQL database Jul 02, 2023 pm 02:28 PM

PHP development tips: How to use PHPExcel and PHPExcel_IOFactory to operate MySQL database Overview: In web development, processing Excel files is a common and important task. PHPExcel is a powerful and easy-to-use PHP library that can help us read and write Excel files. This article will introduce how to use PHPExcel and PHPExcel_IOFactory libraries to operate MySQL database. step 1

PHP development skills: How to use PHPExcel to operate MySQL database PHP development skills: How to use PHPExcel to operate MySQL database Jul 02, 2023 pm 12:21 PM

PHP development skills: How to use PHPExcel to operate MySQL database. With the booming development of the Internet, a large amount of data is stored in the database, and operations such as import, export, and processing are required. In PHP development, PHPExcel is a powerful library that can simplify the interaction with Excel files and realize the import and export of data. This article will introduce how to use PHPExcel to operate the MySQL database and implement data import and export functions. Installation and configuration of PHPExcel

See all articles