dongqieli4164 2019-07-05 07:03
浏览 96

如何使用PHP为pdf中的单元格赋予颜色?

I need to give color to a specific cell in pdf which is generated from my MySQL database, How to set the color to the specific value?

I have no clue about giving color to the specific value, I there any way help me out?

my pdf generate page is:

$fdate = date('Y-m-d H:i:s', strtotime($fromdate));
$tdate = date('Y-m-d H:i:s', strtotime( $todate));

/*$channelsCol = Channels::find()
                    ->select(['channel_name'])
                    ->where('DeviceRefID != :id',['id' => 0 ])
                    ->orderBy('channel_no')
                    ->all();*/
$channelscol = \Yii::$app->db
                    ->createCommand("select channel_name from channels where deviceRefID !=0")
                    ->queryAll();

$pdfpages = $this->getNoOfPdfs(count($channelscol));
$noOfPages = count($pdfpages[0]);
$collist=[];
$selectlist=[];
for($i=0; $i < $noOfPages;$i++)
{
    $collist[$i] = 'Select SQL_BUFFER_RESULT "LogDateTime  ",';
    $selectlist[$i] = 'select LogDateTime,'; 
}

$count =0;
$counter=1;

for($i=0;$i<$noOfPages;$i++)
{
    for($j=$pdfpages[0][$i];$j<$pdfpages[1][$i];$j++)
    {
        $collist[$i] = $collist[$i] . '"'.$channelscol[$j-1]['channel_name'] .'",';
        $selectlist[$i] = $selectlist[$i] . 'Channel'.$j.'Value,';
        $count = $count + 1;
    }
}

for($i=0;$i <$noOfPages ;$i++)
{
    $collist[$i] = rtrim($collist[$i],",");
    $selectlist[$i] = rtrim($selectlist[$i],",");
}

//$path ="/var/www/devicesadmin/yii-app/web/devicelog/devicelog" . date("Y-m-d-H-i-s").".csv";
$logfilename =[];
$logfailure="";
for($i=0;$i < $noOfPages; $i++)
{   
    $logfilename[$i] = $pdfpages[2][$i] . date("Y-m-d-H-i-s") . mt_rand() . ".csv";
    //$path ='D:/Raffi/ProjectsPhp/DevicesAdminProject/yii-app/web/devicelog//' . $logfilename[$i];
    $path =  "/var/www/devicesadmin/yii-app/web/devicelog/"  . $logfilename[$i];
    $export =' INTO OUTFILE "' . $path . '" FIELDS TERMINATED BY "," ENCLOSED BY \'"\' LINES TERMINATED BY \'\
\' FOR UPDATE';
    $whereclause = "where LogDatetime between '" . $fdate . "' and '" .$tdate ."'";
    $finalsql = $collist[$i] . ' Union all ' .$selectlist[$i] .' From devicelog '. $whereclause . $export;
    try {
       Yii::$app->db->createCommand($finalsql)->execute();
       //file_put_contents("D:\my.txt", $this->getHTML($path, $header));
       //echo html($this->getHTML($path, $header));
       //exit();        
        $pdf=new \PDF('P','mm','Legal');
        $pdf->AliasNbPages();
        //$pdf=new \PDF('L','mm','Legal',130);
        $pdf->AddPage();
        $pdf->SetFont('helvetica','',10);
        $pdf->WriteHTML($this->getHTML($path));
        $logfilename[$i] = "dl" . $pdfpages[2][$i] . date("Y-m-d-H-i-s").".pdf";
        //$filename = "D:/Raffi/ProjectsPhp/DevicesAdminProject\yii-app\web\devicelog" . $logfilename[$i];
        $filename = "/var/www/devicesadmin/yii-app/web/devicelog/"  . $logfilename[$i];
        $pdf->Output('F',$filename);
        unset($pdf);
    } catch(Exception $e) {

    }
}

If a pdf is generated, I need to give red color to the values which are above 50. But I can't get the values and give color.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题