如何对齐除第 1 列和第 2 列以外的所有列?

How to align right all columns except the 1st 2?

我有一个有 27 列的 table,我正在使用 fpdf 创建 pdf 文件。

我想知道如何使除第 2 列以外的所有列都正确对齐?

这是我的代码。

#Create the table
    function BasicTable($header,$data) {
        #Create the header.
        foreach ($header as $col)
            $this->Cell(18,5,$col,1);
            $this->Ln();

            #Get the data
            foreach ($data as $row) {
                foreach ($row as $col) 
                    #$this->Cell(18,5,$col,1,'R');
                    $this->Cell(18,5, $col, 1, 0); 
                $this->Ln();
            }
        }
    }

更新代码(有效)

 #Create the table
    function BasicTable($header,$data) {
        #Create the header.
        foreach ($header as $col)
            $this->Cell(18,5,$col,1);
            $this->Ln();

            #Get the data
    foreach ($data as $row) {
        $cnt = 0;
        foreach ($row as $col) {
            if($cnt < 2){
              $this->Cell(18,5,$col,1);
            }
            else {
              $this->Cell(18,5, $col, 1, 0,'R'); 
            }
            $cnt++;
        }
     $this->Ln();   
     }
        }
    }

您应该检查每一行的列值,

#Create the table

function BasicTable($header,$data) {
    #Create the header.
    foreach ($header as $col)
        $this->Cell(18,5,$col,1);
    $this->Ln();

    #Get the data
    foreach ($data as $row) {
        $cnt = 0;
        foreach ($row as $col) {
            if($cnt < 2){
              $this->Cell(18,5,$col,1,'R');
            }
            else {
              $this->Cell(18,5, $col, 1, 0); 
            }
            $cnt++;
        }
     $this->Ln();   
     }
}

我还在你的函数中发现了额外的“}”。

根据上面的post更新了代码

#Create the table
    function BasicTable($header,$data) {
        #Create the header.
        foreach ($header as $col)
            $this->Cell(18,5,$col,1);
            $this->Ln();

            #Get the data
    foreach ($data as $row) {
        $cnt = 0;
        foreach ($row as $col) {
            if($cnt < 2){
              $this->Cell(18,5,$col,1);
            }
            else {
              $this->Cell(18,5, $col, 1, 0,'R'); 
            }
            $cnt++;
        }
     $this->Ln();   
     }
        }
    }