Very early, the use of PHP to generate execl is a troublesome thing, I will generally use CSV to replace, now such tools are many, and more mature. Not only Excel, Word,pdf.
1,php Excelreader the PHP class that operates Excel, generates, reads Excel, and so on. Features are powerful.
Download Address: http://sourceforge.net/projects/phpexcelreader/
After decompression, there are many examples, the invocation method is simple.
Example 1
The code is as follows |
Copy Code |
/** * * @copyright 2007-2012 Xiaoqiang. * @author Xiaoqiang.wu * @version 1.01 */ Error_reporting (E_all); Date_default_timezone_set (' Asia/shanghai '); /** Phpexcel_iofactory */ Require_once '. /classes/phpexcel/iofactory.php '; Check Prerequisites if (!file_exists ("31excel5.xls")) { Exit ("not found 31EXCEL5.XLS.N"); } $reader = Phpexcel_iofactory::createreader (' Excel5 '); Set in EXCEL5 format (excel97-2003 workbook) $PHPExcel = $reader->load ("31excel5.xls"); Loading Excel files $sheet = $PHPExcel->getsheet (0); Read the first?? Work table $highestRow = $sheet->gethighestrow (); Total number of rows obtained $highestColumm = $sheet->gethighestcolumn (); Total number of columns obtained $highestColumm = phpexcel_cell::columnindexfromstring ($colsNum); The letter column is converted to a number column such as: AA to 27 /** cycle through the data of each cell */ for ($row = 1; $row <= $highestRow; $row + +) {//lines start at line 1th for ($column = 0; $column < $highestColumm; $column + +) {//Number of columns starts with column NO. 0 $columnName = Phpexcel_cell::stringfromcolumnindex ($column); Echo $columnName. $row. ":". $sheet->getcellbycolumnandrow ($column, $row)->getvalue (). " "; } } ?> |
Example 2
The code is as follows |
Copy Code |
/** * * @copyright 2007-2012 Xiaoqiang. * @author Xiaoqiang.wu * @version 1.01 */ Error_reporting (E_all); Date_default_timezone_set (' Asia/shanghai '); /** Phpexcel_iofactory */ Require_once '. /classes/phpexcel/iofactory.php '; Check Prerequisites if (!file_exists ("31excel5.xls")) { Exit ("not found 31EXCEL5.XLS.N"); } $reader = Phpexcel_iofactory::createreader (' Excel5 '); Set in EXCEL5 format (excel97-2003 workbook) $PHPExcel = $reader->load ("31excel5.xls"); Loading Excel files $sheet = $PHPExcel->getsheet (0); Read the first?? Work table $highestRow = $sheet->gethighestrow (); Total number of rows obtained $highestColumm = $sheet->gethighestcolumn (); Total number of columns obtained /** cycle through the data of each cell */ for ($row = 1; $row <= $highestRow; $row + +) {//lines start at line 1th for ($column = ' a '; $column <= $highestColumm; $column + +) {//The number of columns starts with column A $dataset [] = $sheet->getcell ($column. $row)->getvalue (); Echo $column. $row. ":". $sheet->getcell ($column. $row)->getvalue (). " "; } } ?> |
2,phpdocx PHP classes that manipulate word
Phpdocx is a PHP class library for generating fully dynamic, fully compatible Word documents.
You may need to generate reports directly from any data collection or tabular file. These reports may include icons, pictures, tables, start, end, and so on.
Phpdocx is able to use some pre-defined template files to generate Word documents, which greatly simplifies the effort. With a little bit of code, you can integrate Phpdocx into your Web site or network application, which can provide a valuable service to your users or employees.
Cases
The code is as follows |
Copy Code |
Basic Example Include the phpword.php, all other classes were loaded by an autoloader Require_once ' phpword.php '; Create a new Phpword Object $PHPWord = new Phpword (); Every element want to append to the Word document are placed in a section. So-Need a section: $section = $PHPWord->createsection (); After creating a sections, you can append elements: $section->addtext (' Hello world! '); You can directly style your text by giving the AddText function an array: $section->addtext (' Hello world! I am formatted. ', array (' name ' = ' Tahoma ', ' Size ' =>16, ' bold ' =>true)); If you often need the same style again your can create a user defined style to the Word document and give the AddText function the name of the style: $PHPWord->addfontstyle (' Myownstyle ', Array (' name ' = ' Verdana ', ' Size ' =>14, ' color ' = ' 1b2232 ')); $section->addtext (' Hello world! I am formatted by a user defined style ', ' myownstyle '); You can also putthe appended element to local object A call functions like this: $myTextElement = $section->addtext (' Hello world! '); $myTextElement->setbold (); $myTextElement->setname (' Verdana '); $myTextElement->setsize (22); At least write the document to webspace: $objWriter = Phpword_iofactory::createwriter ($PHPWord, ' Word2007 '); $objWriter->save (' Helloworld.docx '); |
Download Address: http://www.phpdocx.com/
Online Demo Address: Http://www.phpdocx.com/demo/sample-word-report
3,tcpdf PHP class for manipulating PDFs
Download Address: http://sourceforge.net/projects/html2fpdf/?source=recommended
Online Demo Address: http://www.tcpdf.org/examples.php
After downloading, basically has the example, after downloading the thing is relatively big, this is because, there are many examples, for example uses the Pdf,word file This kind, also has many font files. The class file to use is not really big. When you have a record, you don't have to look around. Ha ha.
With the tcpdf of 65 examples, you will be able to fully master the way it is used.
The following 5 steps can be broadly divided:
1. Require_once the appropriate language for importing tcpdf.php files and config/lang/directories
2. Instantiating Tcpdf
3. Format PDF document, including document information, header, footer, font, outer space, picture border, pagination, etc.
4. Import the contents of a PDF document, which can be single-line or multiline simple strings, or HTML-formatted strings, etc.
5. Output PDF document
http://www.bkjia.com/PHPjc/631579.html www.bkjia.com true http://www.bkjia.com/PHPjc/631579.html techarticle very early, the use of PHP to generate execl is a troublesome thing, I will generally use CSV to replace, now such tools are many, and more mature. Not only Excel, Word,pdf. ...