1. Use php excelreader to operate the php class of excel, generate and read excel, etc. Powerful functions.
Download Address: http://sourceforge.net/projects/phpexcelreader/
After decompression, there are many examples in it, and the call method is simple.
Example 1
The code is as follows: |
Copy code |
<? Php /** * * @ Copyright 2007-2012 Xiaoqiang. * @ Author Xiaoqiang. Wu <jamblues@gmail.com> * @ 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 to Excel5 format (Excel97-2003 Workbook) $ PHPExcel = $ reader-> load ("31excel5.xls"); // load an excel file $ Sheet = $ PHPExcel-> getSheet (0); // read first ?? Worksheet $ HighestRow = $ sheet-> getHighestRow (); // gets the total number of rows. $ HighestColumm = $ sheet-> getHighestColumn (); // gets the total number of columns $ HighestColumm = PHPExcel_Cell: columnIndexFromString ($ colsNum); // Convert a letter column to a numeric column, for example, AA to 27 /** Read the data of each cell cyclically */ For ($ row = 1; $ row <= $ highestRow; $ row ++) {// The number of rows starts with 1st For ($ column = 0; $ column <$ highestColumm; $ column ++) {// The number of columns starts with 0th $ ColumnName = PHPExcel_Cell: stringFromColumnIndex ($ column ); Echo $ columnName. $ row. ":". $ sheet-> getCellByColumnAndRow ($ column, $ row)-> getValue (). "<br/> "; } } ?> |
Example 2
The code is as follows: |
Copy code |
<? Php /** * * @ Copyright 2007-2012 Xiaoqiang. * @ Author Xiaoqiang. Wu <jamblues@gmail.com> * @ 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 to Excel5 format (Excel97-2003 Workbook) $ PHPExcel = $ reader-> load ("31excel5.xls"); // load an excel file $ Sheet = $ PHPExcel-> getSheet (0); // read first ?? Worksheet $ HighestRow = $ sheet-> getHighestRow (); // gets the total number of rows. $ HighestColumm = $ sheet-> getHighestColumn (); // gets the total number of columns /** Read the data of each cell cyclically */ For ($ row = 1; $ row <= $ highestRow; $ row ++) {// The number of rows starts with 1st For ($ column = 'a'; $ column <= $ highestColumm; $ column ++) {// The number of columns starts with column. $ Dataset [] = $ sheet-> getCell ($ column. $ row)-> getValue (); Echo $ column. $ row. ":". $ sheet-> getCell ($ column. $ row)-> getValue (). "<br/> "; } } ?> |
2. phpdocx: php class for word operations
PHPDocx is a PHP class library used to generate completely dynamic and fully compatible Word documents.
You may need to generate a report directly from any data set or table file. These reports may contain data such as icons, images, tables, beginning and end.
PHPDocx can use some predefined template files to generate word documents, which greatly simplifies the workload. With a few pieces of code, you can integrate PHPDocx into your WEB site or network application to provide a valuable service for your users or employees.
Example
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 you want to append to the word document is placed in a section. So you need a section: $ Section = $ PHPWord-> createSection (); // After creating a section, 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 you can create a user defined style to the word document // And give the addText function the name of the style: $ PHPWord-> addFontStyle ('myownerstyle', 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 an 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 '); |
Address: http://www.phpdocx.com/
Online demo address: http://www.phpdocx.com/demo/sample-word-report
3. php class for tcpdf pdf operations
Download Address: http://sourceforge.net/projects/html2fpdf? Source = recommended
Online demo address: http://www.tcpdf.org/examples.php
After the download, there are basically examples, and the downloaded content is relatively large, because there are many examples, such as pdf files and word files, for example, there are also many font files. The class file to be used is not big. You don't have to look for it everywhere when you record it. Haha.
After 65 examples of TCPDF, you can fully master its usage.
You can perform the following five steps:
1. require_once import the tcpdf. Php file and the corresponding language of the config/lang/Directory
2. Instantiate TCPDF
3. Set the format of a PDF document, including the document information, header, footer, font, outer spacing, image border, and paging.
4. The content of the imported PDF document can be a single line or multiple lines of simple strings, or HTML strings.
5. Output PDF document