The PHP Excel Class Phpexcel uses the method introduction, Excelphpexcel
Phpexcel operation Excel can easily add images, support JPG gif png format.
Download Address: Http://www.codeplex.com/PHPExcel
Below is a summary of several ways to use
include ' phpexcel.php ';
include ' phpexcel/writer/excel2007.php ';
//or include ' phpexcel/writer/excel5.php '; for output. xls
Create an Excel
$objPHPExcel = new Phpexcel ();
Save excel-2007 format
$objWriter = new phpexcel_writer_excel2007 ($objPHPExcel);
//or $objwriter = new Phpexcel_writer_excel5 ($objPHPExcel); not 2007 format
$objWriter->save ("xxx.xlsx");
Direct output to browser
$objWriter = new Phpexcel_writer_excel5 ($objPHPExcel);
Header ("Pragma:public");
Header ("Expires:0″");
Header ("Cache-control:must-revalidate, post-check=0, Pre-check=0″);
Header ("Content-type:application/force-download");
Header ("content-type:application/vnd.ms-execl");
Header ("Content-type:application/octet-stream");
Header ("content-type:application/download");;
Header (' content-disposition:attachment;filename= ' Resume.xls "');
Header ("Content-transfer-encoding:binary");
$objWriter->save (' php://output ');
--
For those unfamiliar with the Phpexcel class library, you can read the contents of the Phpexcel Chinese help manual, and we can phpexcel the relevant examples in the Quick Development Guide for specific examples.
To set properties for Excel:
Create person
$objPHPExcel->getproperties ()->setcreator ("Maarten Balliauw");
Last modified person
$objPHPExcel->getproperties ()->setlastmodifiedby ("Maarten Balliauw");
Title
$objPHPExcel->getproperties ()->settitle ("Office" XLSX Test Document ");
Topic
$objPHPExcel->getproperties ()->setsubject ("Office" XLSX Test Document ");
Describe
$objPHPExcel->getproperties ()->setdescription ("Test document for Office-XLSX, generated using PHP classes.");
Key words
$objPHPExcel->getproperties ()->setkeywords ("Office openxml PHP");
Kinds
$objPHPExcel->getproperties ()->setcategory ("Test result file");
——————————————————————————————————————–
Set the current sheet
$objPHPExcel->setactivesheetindex (0);
Set the name of the sheet
$objPHPExcel->getactivesheet ()->settitle (' simple ');
Set the value of a cell
$objPHPExcel->getactivesheet ()->setcellvalue (' a1′, ' String ');
$objPHPExcel->getactivesheet ()->setcellvalue (' a2′, 12);
$objPHPExcel->getactivesheet ()->setcellvalue (' a3′, true);
$objPHPExcel->getactivesheet ()->setcellvalue (' c5′, ' =sum (C2:C4) ');
$objPHPExcel->getactivesheet ()->setcellvalue (' b8′, ' =min (B2:C5) ');
Merge cells
$objPHPExcel->getactivesheet ()->mergecells (' a18:e22′);
Separating cells
$objPHPExcel->getactivesheet ()->unmergecells (' a28:b28′);
Protect cell
$objPHPExcel->getactivesheet ()->getprotection ()->setsheet (true); Needs to BES set to true in order to enable any worksheet protection!
$objPHPExcel->getactivesheet ()->protectcells (' a3:e13′, ' phpexcel ');
Set format
Set Cell number formats
echo Date (' H:i:s '). "Set cell number FORMATSN";
$objPHPExcel->getactivesheet ()->getstyle (' e4′)->getnumberformat ()->setformatcode (phpexcel_style_ Numberformat::format_currency_eur_simple);
$objPHPExcel->getactivesheet ()->duplicatestyle ($objPHPExcel->getactivesheet ()->getstyle (' e4′), ' E5: e13′);
Setting width width
Set column Widths
$objPHPExcel->getactivesheet ()->getcolumndimension (' B ')->setautosize (true);
$objPHPExcel->getactivesheet ()->getcolumndimension (' D ')->setwidth (12);
Set font
$objPHPExcel->getactivesheet ()->getstyle (' b1′)->getfont ()->setname (' Candara ');
$objPHPExcel->getactivesheet ()->getstyle (' b1′)->getfont ()->setsize (20);
$objPHPExcel->getactivesheet ()->getstyle (' b1′)->getfont ()->setbold (true);
$objPHPExcel->getactivesheet ()->getstyle (' b1′)->getfont ()->setunderline (Phpexcel_style_font:: Underline_single);
$objPHPExcel->getactivesheet ()->getstyle (' b1′)->getfont ()->getcolor ()->setargb (phpexcel_style_ Color::color_white);
$objPHPExcel->getactivesheet ()->getstyle (' e1′)->getfont ()->getcolor ()->setargb (phpexcel_style_ Color::color_white);
$objPHPExcel->getactivesheet ()->getstyle (' d13′)->getfont ()->setbold (true);
$objPHPExcel->getactivesheet ()->getstyle (' e13′)->getfont ()->setbold (true);
Set align
$objPHPExcel->getactivesheet ()->getstyle (' d11′)->getalignment ()->sethorizontal (phpexcel_style_ Alignment::horizontal_right);
$objPHPExcel->getactivesheet ()->getstyle (' d12′)->getalignment ()->sethorizontal (phpexcel_style_ Alignment::horizontal_right);
$objPHPExcel->getactivesheet ()->getstyle (' d13′)->getalignment ()->sethorizontal (phpexcel_style_ Alignment::horizontal_right);
$objPHPExcel->getactivesheet ()->getstyle (' a18′)->getalignment ()->sethorizontal (phpexcel_style_ Alignment::horizontal_justify);
Center vertically
$objPHPExcel->getactivesheet ()->getstyle (' a18′)->getalignment ()->setvertical (phpexcel_style_ Alignment::vertical_center);
Set the border of column
$objPHPExcel->getactivesheet ()->getstyle (' a4′)->getborders ()->gettop ()->setborderstyle (PHPExcel _style_border::border_thin);
$objPHPExcel->getactivesheet ()->getstyle (' b4′)->getborders ()->gettop ()->setborderstyle (PHPExcel _style_border::border_thin);
$objPHPExcel->getactivesheet ()->getstyle (' c4′)->getborders ()->gettop ()->setborderstyle (PHPExcel _style_border::border_thin);
$objPHPExcel->getactivesheet ()->getstyle (' d4′)->getborders ()->gettop ()->setborderstyle (PHPExcel _style_border::border_thin);
$objPHPExcel->getactivesheet ()->getstyle (' e4′)->getborders ()->gettop ()->setborderstyle (PHPExcel _style_border::border_thin);
Set the color of the border
$objPHPExcel->getactivesheet ()->getstyle (' d13′)->getborders ()->getleft ()->getcolor () Setargb (' ff993300′);
$objPHPExcel->getactivesheet ()->getstyle (' d13′)->getborders ()->gettop ()->getcolor ()->setARGB (' ff993300′);
$objPHPExcel->getactivesheet ()->getstyle (' d13′)->getborders ()->getbottom ()->getcolor () Setargb (' ff993300′);
$objPHPExcel->getactivesheet ()->getstyle (' e13′)->getborders ()->gettop ()->getcolor ()->setARGB (' ff993300′);
$objPHPExcel->getactivesheet ()->getstyle (' e13′)->getborders ()->getbottom ()->getcolor () Setargb (' ff993300′);
$objPHPExcel->getactivesheet ()->getstyle (' e13′)->getborders ()->getright ()->getcolor () Setargb (' ff993300′);
Set Fill Color
$objPHPExcel->getactivesheet ()->getstyle (' a1′)->getfill ()->setfilltype (Phpexcel_style_fill::fill_ SOLID);
$objPHPExcel->getactivesheet ()->getstyle (' a1′)->getfill ()->getstartcolor ()->setargb (' FF808080′ ') ;
$objPHPExcel->getactivesheet ()->getstyle (' b1′)->getfill ()->setfilltype (Phpexcel_style_fill::fill_ SOLID);
$objPHPExcel->getactivesheet ()->getstyle (' b1′)->getfill ()->getstartcolor ()->setargb (' FF808080′ ') ;
>>> more PHP tutorial content, please pay attention to the PHP programming section of this site.
Add picture
$objDrawing = new phpexcel_worksheet_drawing ();
$objDrawing->setname (' Logo ');
$objDrawing->setdescription (' Logo ');
$objDrawing->setpath ('./images/officelogo.jpg ');
$objDrawing->setheight (36);
$objDrawing->setworksheet ($objPHPExcel->getactivesheet ());
$objDrawing = new phpexcel_worksheet_drawing ();
$objDrawing->setname (' Paid ');
$objDrawing->setdescription (' Paid ');
$objDrawing->setpath ('./images/paid.png ');
$objDrawing->setcoordinates (' b15′);
$objDrawing->setoffsetx (110);
$objDrawing->setrotation (25);
$objDrawing->getshadow ()->setvisible (true);
$objDrawing->getshadow ()->setdirection (45);
$objDrawing->setworksheet ($objPHPExcel->getactivesheet ());
After the default sheet, create a worksheet
echo Date (' H:i:s '). "Create new Worksheet objectn";
$objPHPExcel->createsheet ();
$objWriter = Phpexcel_iofactory::createwriter ($objExcel, ' Excel5 ');
$objWriter-save (' php://output ');
Phpexcel generate Excel can not read
Summarize PHP export Excel PHP Import Excel phpexcel instructions for use Phpexcel 2009/03/06 02:37 method One: Features, simple, worry,
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:attachment;filename=test_data.xls");
$tx = ' table header ';
echo $tx. " \ n ";
The output reads as follows:
echo "Name". " \ t ";
echo "Age". " \ t ";
echo "Education". " \ t ";
echo "\ n";
echo "Zhang San". " \ t ";
echo "25". " \ t ";
echo "Undergraduate". " \ t ";
?>
Method Two: Referring to the small class library recommended in Google code (roughly the same as method one, more complex points)
Code.google.com/p/php-excel/downloads/list
Method Three: Phpexcel class library, powerful, support win Excel2003, win Excel2007.
Www.codeplex.com/PHPExcel
To set the include path for the Phpexcel class library
Set_include_path ('. '). Path_separator.
' D:\Zeal\PHP_LIBS '. Path_separator.
Get_include_path ());
/**
* The following are examples of use, for lines beginning with////are optional, depending on your needs
* Open the comment for the corresponding line.
* If you use Excel5, the content of the output should be GBK encoded.
*/
Require_once ' phpexcel.php ';
Uncomment
Require_once ' phpexcel/writer/excel5.ph ... Remaining full text >>
What else is phpexcel like in PHP? Introduce
Phpexcel Phpexcel is a fairly powerful MS Office Excel document Generation Library, and Phpexcel is a good choice when it comes to outputting more complex format data. However, the use of the method is relatively cumbersome. List it in mind.
--PHP Code--
To set the include path for the Phpexcel class library
Set_include_path ('. '). Path_separator.
' D:\Zeal\PHP_LIBS '. Path_separator.
Get_include_path ());
/**
* The following are examples of use, for lines beginning with////are optional, depending on your needs
* Open the comment for the corresponding line.
* If you use Excel5, the content of the output should be GBK encoded.
*/
Require_once ' phpexcel.php ';
Uncomment
Require_once ' phpexcel/writer/excel5.php '; For other low version xls
Or
Require_once ' phpexcel/writer/excel2007.php '; For excel-2007 format
Create a Processing object instance
$objExcel = new Phpexcel ();
Create a file format to write to an object instance, uncomment
$objWriter = new Phpexcel_writer_excel5 ($objExcel); For other version formats
Or
$objWriter = new phpexcel_writer_excel2007 ($objExcel); For 2007 formats
$objWriter->setoffice2003compatibility (TRUE);
//*************************************
Set document basic Properties
$objProps = $objExcel->getproperties ();
$objProps->setcreator ("Zeal Li"); Set author
$objProps->setlastmodifiedby ("Zeal Li"); Set the last modified person
$objProps->settitle ("Office XLS Test Document"); Set Title
$objProps->setsubject ("Office XLS Test Document, Demo"); Set theme
$objProps->setdescription ("Test document, generated by .....") Remaining full text >>
http://www.bkjia.com/PHPjc/828047.html www.bkjia.com true http://www.bkjia.com/PHPjc/828047.html techarticle The PHP Excel class Phpexcel uses the method introduction, Excelphpexcel Phpexcel operation Excel can conveniently add the picture, supports the JPG gif png format. Download address: Http://www.codeplex.com/PHPExcel ...