2017-10-25 38 views
3

Symfony Tableは通常、最初の行を他の行とは異なる色にします。しかし、私は最初の行と最初の列に同じスタイリングを持たせたいと思います。私はTableStyleが存在することを知っていますが、最初の列と最初の行に同じスタイルを与える方法を理解できません。この表の例では、最初の列も緑色(テキスト行A、行Bおよび行C)にします。Symfonyテーブルの最初の列を最初の行と同じ形式にするにはどうすればよいですか?

$table = new Table($output); 
$table 
    ->setHeaders(array('Col A', 'Col B', 'Col C')) 
    ->setRows(array(
     array('Row A', 'Divine Comedy', 'Dante Alighieri'), 
     array('Row B', 'A Tale of Two Cities', 'Charles Dickens'), 
     array('Row C', 'The Lord of the Rings', 'J. R. R. Tolkien'), 
    )) 
; 
$table->render(); 

examplee

乾杯

答えて

2

あなたはTableStyleインスタンスを作成する必要があり、このようcellRowContentFormatを設定します:

<?php 

use Symfony\Component\Console\Helper\Table; 

require_once 'vendor/autoload.php'; 

$output = new Symfony\Component\Console\Output\ConsoleOutput(); 
$table = new Table($output); 
$style = new \Symfony\Component\Console\Helper\TableStyle(); 
$style->setCellRowContentFormat('<info> %s </info>'); 
$table->setColumnStyle(0, $style); 
$table 
    ->setHeaders(array('Col A', 'Col B', 'Col C')) 
    ->setRows(array(
     array('Row A', 'Divine Comedy', 'Dante Alighieri'), 
     array('Row B', 'A Tale of Two Cities', 'Charles Dickens'), 
     array('Row C', 'The Lord of the Rings', 'J. R. R. Tolkien'), 
    )) 
; 
$table->render(); 

この例の表には、次のコードを使用して生成することができます

あなたTableStyle::$cellRowContentFormatTableStyle::$cellHeaderFormatメンバーのデフォルト値を見ることができます。デフォルトでは$cellHeaderFormat'<info>%s</info>'で、この値はセルヘッダーを緑色にします(情報色)。

関連する問題