PHPexecl table style settings of thinkphp
/*** The following is an example. for rows starting with //, it is optional. open the comment of the corresponding row as needed. * If Excel5 is used, the output content should be GBK encoded. * // Require_once 'PHPExcel. php '; // uncomment // require_once 'phpexcel/Writer/excel5.php '; // for other earlier versions of xls // or /// require_once 'phpexcel/Writer/excel2007.php'; // for excel-2007 format $ objExcel = new PHPExcel (); // Create an instance for processing objects // Create an instance for writing objects in the file format, uncomment $ objWriter = new PHPExcel_Writer_Excel5 ($ objExcel ); // for other version formats // or /// $ objWriter = new PHPExcel_Writer_Excel2007 ($ objExcel); // for the 2007 format // $ obj Writer-> setOffice2003Compatibility (true ); //*************************************/ /set the basic attributes of the document $ objProps = $ objExcel-> getProperties (); // $ objProps-> setCreator ("Zeal Li"); // $ objProps-> setLastModifiedBy ("Zeal Li "); // $ objProps-> setTitle ("Office XLS Test Document"); // $ objProps-> setSubject ("Office XLS Test Document, Demo "); // $ objProps-> setDescription ("Test document, generated by PHPExcel. "); // $ objPro Ps-> setKeywords ("office excel PHPExcel"); // $ objProps-> setCategory ("Test "); //*************************************/ /set the current sheet index, used for subsequent content operations. // Display the call only when multiple sheets are used. // By default, PHPExcel will automatically create the first sheet with the SheetIndex set to 0 $ objExcel-> setActiveSheetIndex (0); $ objActSheet = $ objExcel-> getActiveSheet (); // Set the name of the current active sheet $ objActSheet-> setTitle ('test Sheet '); // Set the cell content /// PHPExcel automatically determines the cell content type based on the input content $ objActSheet-> setCellValue ('A1', 'string content '); // String content $ objActSheet-> setCellValue ('A2 ', 26); // value $ objActSheet-> setCellValue ('A3', true ); // boolean value $ objActSheet-> setCellValue ('A4 ',' = SUM (2: A2) '); // formula // explicitly specify the content type $ objActSheet-> setCellValueExplicit ('a5', '000000', PHPExcel_Cell_DataType: TYPE_STRING ); // merge cells $ objActSheet-> mergeCells ('b1: c22'); // separate cells $ objActSheet-> unmergeCells ('b1: c22 '); //*************************************/ /set the cell style /// set the width $ objActSheet-> getColumnDimension ('B ') -> setAutoSize (true); $ objActSheet-> getColumnDimension ('A')-> setWidth (30); $ objStyleA5 = $ ObjActSheet-> getStyle ('a5 '); // you can specify the numeric format of the cell content. //// If PHPExcel_Writer_Excel5 is used to generate content, // note that in the const variable defined in the PHPExcel_Style_NumberFormat class, other types can be used normally, but when setFormatCode // is FORMAT_NUMBER, the actual effect is not set to "0 ". You need to // modify the getXf ($ style) method in the PHPExcel_Writer_Excel5_Format class source code, // in if ($ this-> _ BIFF_version = 0x0500) {(near 363rd rows) first add a // line of code: // if ($ ifmt = '0') $ ifmt = 1; // set the format to PHPExcel_Style_NumberFormat: FORMAT_NUMBER, to prevent some large numbers from being displayed in scientific notation, you can use the setAutoSize method below to display all the content of each row according to the original content. $ ObjStyleA5-> getNumberFormat ()-> setFormatCode (PHPExcel_Style_NumberFormat: FORMAT_NUMBER); // 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 the alignment mode $ objAlignA5 = $ objStyleA5-> getAlignment (); $ region-> setHorizontal (Region: HORIZONTAL_RIGHT); $ objAlignA5-> setVertical (Region: VERTICAL_CENTER); // set the border $ objBorderA5 = $ objStyleA5-> getBorders (); $ objBorderA5-> getTop ()-> setBorderStyle (PHPExcel_Style_Border: BORDER_THIN); $ objBorderA5-> getTop ()-> getColor ()-> setARGB ('ffff0000 '); // color $ objBorderA5-> getBottom ()-> setBorderStyle (PHPExcel_Style_Border: BORDER_THIN); $ objBorderA5-> getLeft ()-> setBorderStyle (attributes: 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 ');
$ ObjFillA5-> getStartColor ()-> setRGB ('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 by zeal'); $ 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 the cell $ objExcel-> getSheet (1)-> getProtection ()-> setSheet (true ); $ objExcel-> getSheet (1)-> protectCells ('A1: c22', 'phpexcel '); //*************************************/ /Output Content // $ outputFileName = $ title. ". xls "; header (" Content-Type: application/force-download "); header (" Content-Type: application/octet-stream "); header (" Content-Type: application/download "); header ('content-Disposition: attachment; filename = "'. $ outputFileName. '"'); // to the file // header ('content-Disposition: inline; filename = "'. $ outputFileName. '"'); // enter the browser header (" Content-Transfer-Encoding: binary "); header (" Expires: Mon, 26 Jul 1997 05:00:00 GMT "); header ("Last-Modified :". gmdate ("D, d m y h: I: s "). "GMT"); header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0"); header ("Pragma: no-cache "); $ objWriter-> save ('php: // output ');