Skip to content

Novis\Spreadsheet\Style::Valign

Where the text of a cell is placed from top to bottom.

You set it with the style field valign of Style::of. Style::of turns the string into a Style::Valign case:

  • 'top' is Top.
  • 'center' is Center.
  • 'bottom' is Bottom. Excel uses this when a style does not set valign.

Any other string throws a LogicError. The place matters when a row is taller than its text, for example when another cell of the row has wrap: true.

Examples

Text at the top of a tall row

<?nvs
// Shows the `Style::Valign` that each value of the style field `valign` gives.
use Novis\Spreadsheet\Style;
class Places
{
// Returns the name of a place, or "default" when the style does not set one.
public static function name(?Style::Valign $valign): string
{
return match ($valign) {
Style::Valign::Top => 'Top',
Style::Valign::Center => 'Center',
Style::Valign::Bottom => 'Bottom',
null => 'default',
};
}
}
// A note in a tall row is easier to read from the top. This prints "Top".
var $note = Style::of({ wrap: true, valign: 'top' });
echo Places::name($note->fields->valign), "\n";
// A style without `valign` takes it from the row or the column. This prints "default".
echo Places::name(Style::of({ bold: true })->fields->valign), "\n";
Output
Top
default