PHPExcel一些常用方法01

2021-07-10 02:44:48 字數 2008 閱讀 8364

<?php  

require_once

'phpexcel.class.php';   

$str = "title";  

$filename = mb_convert_encoding("**主題/題目","gb2312","utf-8");      

//例項化類

$objexcel = new phpexcel();  

$objwriter = new phpexcel_writer_excel5($objexcel);  

$objexcel->setactivesheetindex(0);  //當前sheet

$objactsheet = $objexcel->getactivesheet();  

$objactsheet->settitle($str);   //sheet標題

$objactsheet->mergecells('a1:al2'); //合併單元格 

$objstylea1 = $objactsheet->getstyle('a1');  

$objaligna1 = $objstylea1->getalignment();  

//    $objaligna1->sethorizontal(phpexcel_style_alignment::horizontal_center);    //左右居中

$objaligna1->setvertical(phpexcel_style_alignment::vertical_center);  //上下居中

//字型及顏色

$objfonta1 = $objstylea1->getfont();  

$objfonta1->setname('黑體');  

$objfonta1->setsize(12);  

$objfonta1->getcolor()->setargb('ffff0000');  

//設定寬度

$objactsheet->getcolumndimension('a')->setwidth(25);  

$objactsheet->getcolumndimension('b')->setwidth(25);  

$objactsheet->getcolumndimension('c')->setwidth(25);  

//設定背景色

$objexcel->getactivesheet()->getstyle(3)->getfill()->setfilltype(phpexcel_style_fill::fill_solid);  

$objexcel->getactivesheet()->getstyle(3)->getfill()->getstartcolor()->setargb($title_back);  

//設定a1的值

$objactsheet->setcellvalue('a1', $str);  

//設定a5邊框

$objstyles = $objexcel->getactivesheet()->getstyle('a5');  

$objbordera5 = $objstyles->getborders();  

$objbordera5->gettop()->setborderstyle(phpexcel_style_border::border_thin);  

//設定上邊框的顏色

$objbordera5 ->gettop()->getcolor()->setargb('ffff0000' );   

$objbordera5->getbottom()->setborderstyle(phpexcel_style_border::border_thin);  

$objbordera5->getleft()->setborderstyle(phpexcel_style_border::border_thin);  

$objbordera5->getright()->setborderstyle(phpexcel_style_border::border_thin); 

一些常用公共方法

根據檔案字尾名獲取檔案的mime型別 檔案字尾名,如 jpg,gif 返回該檔案的mime型別,如 image gif return sresult 根據資料表的列名取的列的序號 列名 資料表 列號,沒有找到返回 1 public static int gettablecolindexbyname ...

一些常用js方法

使用命名空間 var global global.namespace function str else 陣列相關 判斷元素是否存在 第一種寫法 為系統陣列物件新增原型擴充套件方法 array.prototype.inarray function value return false 第二種 自定義...

Swift String 一些常用方法

直接上 字串 1 判斷字串是否為空 var test1str var test1str2 string string println test1str test1str.isempty 沒有值 有值 println test1str2 test1str2.isempty 沒有值 有值 2 計算字串的...