Require_once 'phpexcel. php '; /// Require_once 'phpexcel/Writer/excel5.php'; // used for other earlier versions of xls // Or /// Require_once 'phpexcel/Writer/excel2007.php'; // used for excel-2007 format // Create a processing object instance $ ObjExcel = new PHPExcel (); // Create a file format to write the object instance, uncomment //// $ ObjWriter = newPHPExcel_Writer_Excel5 ($ objExcel); // used for other version formats // Or //// $ ObjWriter = newPHPExcel_Writer_Excel2007 ($ objExcel); // used in 2007 format $ ObjProps = $ objExcel-> getProperties (); // Set the Creator $ ObjProps-> setCreator ('xulu '); // Set the last Modifier $ ObjProps-> setLastModifiedBy ("XuLulu "); // Description $ ObjProps-> setDescription ("MoBi class "); // Set the title $ ObjProps-> setTitle ('manager '); // Set the question $ ObjProps-> setSubject ("OfficeXLS Test Document, Demo "); // Set keywords $ ObjProps-> setKeywords ('manager '); // Set the category $ ObjProps-> setCategory ("Test "); // Worksheet settings $ ObjExcel-> setActiveSheetIndex (0 ); $ ObjActSheet = $ objExcel-> getActiveSheet (); // Cell assignment example: $ ObjActSheet-> setCellValue ('a1', 'id '); $ ObjActSheet-> setCellValue ('b1 ', 'hashcode '); $ ObjActSheet-> setCellValue ('c1', 'modelname '); $ ObjActSheet-> setCellValue ('d1 ', 'indexname '); $ ObjActSheet-> setCellValue ('a1', 'string content'); // string content $ ObjActSheet-> setCellValue ('a2 ', 26); // Value $ ObjActSheet-> setCellValue ('a3 ', true); // Boolean Value $ ObjActSheet-> setCellValue ('a4 ',' = SUM (A2: A2) '); // Formula // Example of automatically setting the cell width: $ ObjActSheet-> getColumnDimension ('A')-> setAutoSize (true ); // Example of manually setting the cell width: // $ ObjActSheet-> getColumnDimension ('A')-> setWidth (10 ); // Exported file name $ OutputFileName = iconv ('utf-8', 'gb2312', 'xululu _ '. time (). '.xlsx '); // Export the file directly $ ObjWriter-> save ($ outputFileName ); // Directly output the file to the browser 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-excel '); Header ('content-Type: application/octet-stream '); Header ('content-Type: application/download '); Header ('content-Disposition: attachment; filename = '. $ outputFileName ); Header ('content-Transfer-Encoding: binary '); $ ObjWriter-> save ('php: // output '); Other settings: // Explicitly specify the content type $ ObjActSheet-> setCellValueExplicit ('a5 ', '123 ', PHPExcel_Cell_DataType: TYPE_STRING ); // Merge Cells $ ObjActSheet-> mergeCells ('b1: c22 '); // Separate cells $ ObjActSheet-> unmergeCells ('b1: c22 '); // Get the cell style $ ObjStyleA5 = $ objActSheet-> getStyle ('a5 '); // Set the font $ ObjFontA5 = $ objStyleA5-> getFont (); $ ObjFontA5-> setName ('courier new '); $ ObjFontA5-> setSize (10 ); $ ObjFontA5-> setBold (true ); $ ObjFontA5-> setUnderline (PHPExcel_Style_Font: UNDERLINE_SINGLE ); $ ObjFontA5-> getColor ()-> setARGB ('ff9999999999 '); // Set alignment $ ObjAlignA5 = $ objStyleA5-> getAlignment (); $ ObjAlignA5-> setHorizontal (PHPExcel_Style_Alignment: HORIZONTAL_RIGHT ); $ ObjAlignA5-> setVertical (PHPExcel_Style_Alignment: VERTICAL_CENTER ); // Set the border $ ObjBorderA5 = $ objStyleA5-> getBorders (); $ ObjBorderA5-> getTop ()-> setBorderStyle (PHPExcel_Style_Border: BORDER_THIN ); $ ObjBorderA5-> getTop ()-> getColor ()-> setARGB ('ffff000000'); // color $ ObjBorderA5-> getBottom ()-> setBorderStyle (PHPExcel_Style_Border: BORDER_THIN ); $ ObjBorderA5-> getLeft ()-> setBorderStyle (PHPExcel_Style_Border: BORDER_THIN ); $ ObjBorderA5-> getRight ()-> setBorderStyle (PHPExcel_Style_Border: BORDER_THIN ); // Set the fill color $ ObjFillA5 = $ objStyleA5-> getFill (); $ ObjFillA5-> setFillType (PHPExcel_Style_Fill: FILL_SOLID ); $ ObjFillA5-> getStartColor ()-> setARGB ('ffeeeeeee '); // Copy the style information from the specified cell. $ ObjActSheet-> duplicateStyle ($ objStyleA5, 'b1: C22 '); //************************************* // Add an image $ ObjDrawing = new PHPExcel_Worksheet_Drawing (); $ ObjDrawing-> setName ('zealimg '); $ ObjDrawing-> setDescription ('image inserted byzeal '); $ ObjDrawing-> setPath ('./zeali.net.logo.gif '); $ ObjDrawing-> setHeight (36 ); $ ObjDrawing-> setCoordinates ('c23 '); $ ObjDrawing-> setOffsetX (10 ); $ ObjDrawing-> setRotation (15 ); $ ObjDrawing-> getShadow ()-> setVisible (true ); $ ObjDrawing-> getShadow ()-> setDirection (36 ); $ ObjDrawing-> setWorksheet ($ objActSheet ); // Add a new worksheet $ ObjExcel-> createSheet (); $ ObjExcel-> getSheet (1)-> setTitle ('test 2 '); // Protect cells $ ObjExcel-> getSheet (1)-> getProtection ()-> setSheet (true ); $ ObjExcel-> getSheet (1)-> protectCells ('a1: c22', 'phpexcel '); |