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

时间:2017-11-21 00:49:04

标签: php fpdf

我有一个包含27列的表,我使用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();   
     }
        }
    }

1 个答案:

答案 0 :(得分:2)

你应该检查每一行的col值,

exit = ""
while(exit != "no"):
    main()
    print("See options again?")
    exit = input()

我还发现了额外的&#34;}&#34;在你的功能。

根据上面的帖子更新了代码

#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();   
     }
}