您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

phpexcel 一些基本的设置

2024/3/27 9:33:14发布16次查看
最近 做项目接触到了导出excel 关于一些 表格的属性基本设置 要是有什么问题 希望大家指出来 共同学习
//引入类
        header('content-type: text/html; charset=utf-8');
        import('org.util.phpexcel');
        import('org.util.phpexcel.writer.excel5');
        import('org.util.phpexcel.iofactory.php');
//实例化对象
        $objphpexcel = new \phpexcel();
 //设置工作簿的名称
        $objphpexcel->getactivesheet()->settitle('预算经费表');
 //合并单元格
        $objphpexcel->getactivesheet()->mergecells('a1:h1');
//拆分单元格
     //$objphpexcel->getactivesheet()->unmergecells('a1:h1');
//设置单元格字体
        $objphpexcel->getactivesheet()->getstyle('a2')->getfont()->setname('宋体') //字体
        ->setsize(12) //字体大小
        ->setbold(true); //字体加粗
//设置行的高度
        $objphpexcel->getactivesheet()->getrowdimension('1')->setrowheight(31.5);
        $objphpexcel->getactivesheet()->getrowdimension('2')->setrowheight(31.5);
        $objphpexcel->getactivesheet()->getrowdimension('3')->setrowheight(69.75);
//长度不够显示的时候 是否自动换行
        $objphpexcel->getactivesheet()->getstyle('b')->getalignment()->setwraptext(true);
//设置打印 页面 方向与大小(此为横向)
        $objphpexcel->getactivesheet()->getpagesetup()->setorientation(\phpexcel_worksheet_pagesetup::orientation_landscape);
        $objphpexcel->getactivesheet()->getpagesetup()->setpapersize(\phpexcel_worksheet_pagesetup::papersize_a4);
//冻结标题
    //$objphpexcel->getactivesheet()->freezepane('a1');
    //$objphpexcel->getactivesheet()->freezepane('a2');
    $objphpexcel->getactivesheet()->freezepanebycolumnandrow(8,4);//(列,行)
//设置水平居中 
    $objphpexcel->getactivesheet()->getstyle('a1')->getalignment()->sethorizontal(\phpexcel_style_alignment::horizontal_center);    
    $objphpexcel->getactivesheet()->getstyle('b2')->getalignment()->sethorizontal(\phpexcel_style_alignment::horizontal_center);
//垂直居中
    $objphpexcel->getactivesheet()->getstyle('a1')->getalignment()->setvertical(\phpexcel_style_alignment::vertical_center);
    $objphpexcel->getactivesheet()->getstyle('b2')->getalignment()->setvertical(\phpexcel_style_alignment::vertical_center);
//左对齐
        $objphpexcel->getactivesheet()->getstyle('a')->getalignment()->sethorizontal(\phpexcel_style_alignment::horizontal_justify);
//右对齐
    $objphpexcel->getactivesheet()->getstyle('a')->getalignment()->sethorizontal(\phpexcel_style_alignment::horizontal_right);
// 设置页面边距为0.5厘米 (1英寸 = 2.54厘米)
    $margin = 1.78 / 2.54;   //phpexcel 中是按英寸来计算的,所以这里换算了一下
    $marginright = 1 / 2.54;   //phpexcel 中是按英寸来计算的,所以这里换算了一下
    //$pagemargins->settop($margin);       //上边距
    //$pagemargins->setbottom($margin); //下
    $objphpexcel->getactivesheet()->getpagemargins()->setleft($margin);      //左
    $objphpexcel->getactivesheet()->getpagemargins()->setright(marginright);    //右
    //$objphpexcel->getactivesheet()->getpagesetup()->setfittowidth('1');//自动填充到页面的宽度
    //$objphpexcel->getactivesheet()->getpagesetup()->setfittoheight('1');//自动填充到页面的高度
//设置 标题索引    (点击 标题 跳转到对应的工作簿中)
       $objphpexcel->getactivesheet()->getcell('b4')->gethyperlink()->seturl(sheet://'计算机软件技术'!a1);
//设置边框
    $objphpexcel->getactivesheet()->getstyle('a1:h8')->getborders()->getallborders()->setborderstyle(\phpexcel_style_border::border_thin);
phpexcel类.rar ( 841.2 kb 下载:17 次 )
ad:真正免费,域名+虚机+企业邮箱=0元
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product