PHP Class PHPRtfLite_Table

Author: Denis Slaveckij ([email protected])
Author: Steffen Zeidler ([email protected])
Show file Open project: phprtflite/phprtflite Class Usage Examples

Protected Properties

Property Type Description
$_alignment string
$_columns PHPRtfLite_Table_Column[] array of PHPRtfLite_Table_Column instances
$_container PHPRtfLite_Container
$_firstRowIsHeader boolean
$_leftPosition integer
$_nestDepth integer .. and so on ..
$_preventEmptyParagraph boolean flag for preventing an empty paragraph after table
$_preventPageBreak boolean
$_repeatFirstRowHeader boolean
$_rows PHPRtfLite_Table_Row[] array of PHPRtfLite_Table_Row instances

Public Methods

Method Description
__construct ( PHPRtfLite_Container_Base $container, string $alignment = self::ALIGN_LEFT, integer $nestDepth = 1 ) constructor
addColumn ( float $width ) : PHPRtfLite_Table_Column adds column
addColumnsList ( $columnWidths ) adds list of columns
addImageFromStringToCell ( integer $rowIndex, integer $columnIndex, string $imageString, string $type, PHPRtfLite_ParFormat $parFormat = null, float $width = null, float $height = null ) : PHPRtfLite_Image adds image to cell
addImageToCell ( integer $rowIndex, integer $columnIndex, string $file, PHPRtfLite_ParFormat $parFormat = null, float $width = null, float $height = null ) : PHPRtfLite_Image adds image to cell
addRow ( float $height = null ) : PHPRtfLite_Table_Row adds row
addRowList ( array $heights ) adds list of rows to a table.
addRows ( integer $rowCnt, float $height = null ) adds rows
checkColumnIndex ( integer $colIndex ) : boolean returns true, if column index is valid
checkIfCellExists ( integer $rowIndex, integer $columnIndex ) : boolean returns true, if rowIndex and columnIndex do exists in table
checkRowIndex ( integer $rowIndex ) : boolean returns true, if row index is valid
free ( )
getAlignment ( ) : string gets alignment
getCell ( integer $rowIndex, integer $columnIndex ) : PHPRtfLite_Table_Cell gets the instance of cell
getColumn ( integer $colIndex ) : PHPRtfLite_Table_Column gets column
getColumns ( ) : PHPRtfLite_Table_Column[] gets table columns
getColumnsCount ( ) : integer gets number of columns in table
getContainer ( ) : PHPRtfLite_Container gets rtf container instance
getLeftPosition ( ) : float gets left position of table
getNestDepth ( ) : integer gets nested depth
getPreventEmptyParagraph ( ) : boolean returns true, if no empty paragraph should be added after table
getRow ( integer $rowIndex ) : PHPRtfLite_Table_Row gets row instance
getRows ( ) : PHPRtfLite_Table_Row[] gets table rows
getRowsCount ( ) : integer gets number of rows in table
getRtf ( ) : PHPRtfLite gets rtf instance
isFirstRowHeader ( ) : boolean Returns true, if first row should be used as header. First row will be repeated at the top of each page.
isNestedTable ( ) : boolean checks, if table is a nested table
isPreventPageBreak ( ) : boolean returns true, if a table should not be splited by a page break
mergeCellRange ( integer $startRow, integer $startColumn, integer $endRow, integer $endColumn ) merges cells of a given cell range
preventEmptyParagraph ( $value = true ) prevents adding an empty paragraph after table
render ( ) : string gets rtf code for table
renderRowDefinition ( PHPRtfLite_Table_Row $row ) renders row definition
rotateCellRange ( string $rotateTo, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null ) rotates cells of a given cell range
setBackgroundForCellRange ( string $backgroundColor, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null ) sets background color of cells of a given cell range
setBorderForCellRange ( PHPRtfLite_Border $border, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null ) sets border to cells of a given cell range
setBordersForCellRange ( PHPRtfLite_Border_Format $borderFormat, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null, boolean $left = true, boolean $top = true, boolean $right = true, boolean $bottom = true )
setFirstRowAsHeader ( ) Sets first row as header row. First row will be repeated at the top of each page.
setFontForCellRange ( PHPRtfLite_Font $font, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null ) sets font to empty cells of a given cell range
setLeftPosition ( float $leftPosition ) sets left position of table
setPreventPageBreak ( ) Sets that table won't be splited by a page break. By default page break splits table.
setTextAlignmentForCellRange ( string $alignment, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null ) sets alignments to empty cells of a given cell range
setVerticalAlignmentForCellRange ( string $verticalAlignment, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null ) sets vertical alignment to cells of a given cell range
writeToCell ( integer $rowIndex, integer $columnIndex, string $text, PHPRtfLite_Font $font = null, PHPRtfLite_ParFormat $parFormat = null, boolean $convertTagsToRtf = true ) : PHPRtfLite_Element writes text to cell

Protected Methods

Method Description
renderRowCells ( PHPRtfLite_Table_Row $row ) renders row cells

Private Methods

Method Description
getCellsByCellRange ( integer $startRow, integer $startColumn, integer $endRow, integer $endColumn ) : PHPRtfLite_Table_Cell[]
getValidCellRange ( integer $startRow, integer $startColumn, integer $endRow, integer $endColumn ) : array corrects cell range to be valid

Method Details

__construct() public method

constructor
public __construct ( PHPRtfLite_Container_Base $container, string $alignment = self::ALIGN_LEFT, integer $nestDepth = 1 )
$container PHPRtfLite_Container_Base
$alignment string
$nestDepth integer

addColumn() public method

adds column
public addColumn ( float $width ) : PHPRtfLite_Table_Column
$width float column width
return PHPRtfLite_Table_Column

addColumnsList() public method

adds list of columns
public addColumnsList ( $columnWidths )

addImageFromStringToCell() public method

adds image to cell
public addImageFromStringToCell ( integer $rowIndex, integer $columnIndex, string $imageString, string $type, PHPRtfLite_ParFormat $parFormat = null, float $width = null, float $height = null ) : PHPRtfLite_Image
$rowIndex integer row index of cell
$columnIndex integer column index of cell
$imageString string image source code
$type string image type (GD, WMF)
$parFormat PHPRtfLite_ParFormat paragraph format
$width float if null image is displayed by it's original height.
$height float if null image is displayed by it's original width. If boths parameters are null, image is displayed as it is.
return PHPRtfLite_Image

addImageToCell() public method

adds image to cell
public addImageToCell ( integer $rowIndex, integer $columnIndex, string $file, PHPRtfLite_ParFormat $parFormat = null, float $width = null, float $height = null ) : PHPRtfLite_Image
$rowIndex integer row index of cell
$columnIndex integer column index of cell
$file string image file.
$parFormat PHPRtfLite_ParFormat paragraph format
$width float if null image is displayed by it's original height.
$height float if null image is displayed by it's original width. If boths parameters are null, image is displayed as it is.
return PHPRtfLite_Image

addRow() public method

adds row
public addRow ( float $height = null ) : PHPRtfLite_Table_Row
$height float row height. When 0, the height is sufficient for all the text in the line; when positive, the height is guaranteed to be at least the specified height; when negative, the absolute value of the height is used, regardless of the height of the text in the line.
return PHPRtfLite_Table_Row

addRowList() public method

adds list of rows to a table.
public addRowList ( array $heights )
$heights array array of heights for each row to add. When height is null, the height is sufficient for all the text in the line; when positive, the height is guaranteed to be at least the specified height; when negative, the absolute value of the height is used, regardless of the height of the text in the line.

addRows() public method

adds rows
public addRows ( integer $rowCnt, float $height = null )
$rowCnt integer
$height float row height. When null, the height is sufficient for all the text in the line; when positive, the height is guaranteed to be at least the specified height; when negative, the absolute value of the height is used, regardless of the height of the text in the line.

checkColumnIndex() public method

returns true, if column index is valid
public checkColumnIndex ( integer $colIndex ) : boolean
$colIndex integer
return boolean

checkIfCellExists() public method

returns true, if rowIndex and columnIndex do exists in table
public checkIfCellExists ( integer $rowIndex, integer $columnIndex ) : boolean
$rowIndex integer
$columnIndex integer
return boolean

checkRowIndex() public method

returns true, if row index is valid
public checkRowIndex ( integer $rowIndex ) : boolean
$rowIndex integer
return boolean

free() public method

public free ( )

getAlignment() public method

gets alignment
public getAlignment ( ) : string
return string

getCell() public method

gets the instance of cell
public getCell ( integer $rowIndex, integer $columnIndex ) : PHPRtfLite_Table_Cell
$rowIndex integer
$columnIndex integer
return PHPRtfLite_Table_Cell

getColumn() public method

gets column
public getColumn ( integer $colIndex ) : PHPRtfLite_Table_Column
$colIndex integer
return PHPRtfLite_Table_Column

getColumns() public method

gets table columns
public getColumns ( ) : PHPRtfLite_Table_Column[]
return PHPRtfLite_Table_Column[]

getColumnsCount() public method

gets number of columns in table
public getColumnsCount ( ) : integer
return integer

getContainer() public method

gets rtf container instance
public getContainer ( ) : PHPRtfLite_Container
return PHPRtfLite_Container

getLeftPosition() public method

gets left position of table
public getLeftPosition ( ) : float
return float

getNestDepth() public method

gets nested depth
public getNestDepth ( ) : integer
return integer

getPreventEmptyParagraph() public method

returns true, if no empty paragraph should be added after table

getRow() public method

gets row instance
public getRow ( integer $rowIndex ) : PHPRtfLite_Table_Row
$rowIndex integer
return PHPRtfLite_Table_Row

getRows() public method

gets table rows
public getRows ( ) : PHPRtfLite_Table_Row[]
return PHPRtfLite_Table_Row[]

getRowsCount() public method

gets number of rows in table
public getRowsCount ( ) : integer
return integer

getRtf() public method

gets rtf instance
public getRtf ( ) : PHPRtfLite
return PHPRtfLite

isFirstRowHeader() public method

Returns true, if first row should be used as header. First row will be repeated at the top of each page.
public isFirstRowHeader ( ) : boolean
return boolean

isNestedTable() public method

checks, if table is a nested table
public isNestedTable ( ) : boolean
return boolean

isPreventPageBreak() public method

returns true, if a table should not be splited by a page break
public isPreventPageBreak ( ) : boolean
return boolean

mergeCellRange() public method

merges cells of a given cell range
public mergeCellRange ( integer $startRow, integer $startColumn, integer $endRow, integer $endColumn )
$startRow integer start row
$startColumn integer start column
$endRow integer end row
$endColumn integer end column

preventEmptyParagraph() public method

prevents adding an empty paragraph after table
public preventEmptyParagraph ( $value = true )

render() public method

gets rtf code for table
public render ( ) : string
return string rtf code

renderRowCells() protected method

renders row cells
protected renderRowCells ( PHPRtfLite_Table_Row $row )
$row PHPRtfLite_Table_Row

renderRowDefinition() public method

renders row definition
public renderRowDefinition ( PHPRtfLite_Table_Row $row )
$row PHPRtfLite_Table_Row

rotateCellRange() public method

rotates cells of a given cell range
public rotateCellRange ( string $rotateTo, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null )
$rotateTo string direction of rotation
Possible values (represented by PHPRtfLite_Table_Cell::ROTATE_*):
PHPRtfLite_Table_Cell::ROTATE_RIGHT => 'right'
PHPRtfLite_Table_Cell::ROTATE_LEFT => 'left'
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then rotation is set only to the row range.
$endColumn integer end column, if null, then rotation is set just to the column range.

setBackgroundForCellRange() public method

sets background color of cells of a given cell range
public setBackgroundForCellRange ( string $backgroundColor, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null )
$backgroundColor string background color
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then rotation is set only to the row range.
$endColumn integer end column, if null, then rotation is set just to the column range.

setBorderForCellRange() public method

sets border to cells of a given cell range
public setBorderForCellRange ( PHPRtfLite_Border $border, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null )
$border PHPRtfLite_Border border
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then border is set only to the row range.
$endColumn integer end column, if null, then border is set just to the column range.

setBordersForCellRange() public method

Deprecation: use setBorderForCellRange() instead
public setBordersForCellRange ( PHPRtfLite_Border_Format $borderFormat, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null, boolean $left = true, boolean $top = true, boolean $right = true, boolean $bottom = true )
$borderFormat PHPRtfLite_Border_Format border format
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then border is set only to the row range.
$endColumn integer end column, if null, then border is set just to the column range.
$left boolean if false, left border is not set (default true)
$top boolean if false, top border is not set (default true)
$right boolean if false, right border is not set (default true)
$bottom boolean if false, bottom border is not set (default true)

setFirstRowAsHeader() public method

Sets first row as header row. First row will be repeated at the top of each page.
public setFirstRowAsHeader ( )

setFontForCellRange() public method

sets font to empty cells of a given cell range
public setFontForCellRange ( PHPRtfLite_Font $font, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null )
$font PHPRtfLite_Font font for empty cells. The method PHPRtfLite_Table_Cell->writeToCell() overrides it with another PHPRtfLite_Font.
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then font is set only to the row range.
$endColumn integer end column, if null, then font is set just to the column range.

setLeftPosition() public method

sets left position of table
public setLeftPosition ( float $leftPosition )
$leftPosition float left position of table.

setPreventPageBreak() public method

Sets that table won't be splited by a page break. By default page break splits table.
public setPreventPageBreak ( )

setTextAlignmentForCellRange() public method

sets alignments to empty cells of a given cell range
public setTextAlignmentForCellRange ( string $alignment, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null )
$alignment string alignment of cell. The method PHPRtfLite_Table_Cell->writeToCell() overrides it with PHPRtfLite_ParFormat alignment.
Alignment is represented by class constants PHPRtfLite_Container::TEXT_ALIGN_*
Possible values:
PHPRtfLite_Container::TEXT_ALIGN_LEFT => 'left' - left alignment
PHPRtfLite_Container::TEXT_ALIGN_RIGHT => 'right' - right alignment
PHPRtfLite_Container::TEXT_ALIGN_CENTER => 'center' - center alignment
PHPRtfLite_Container::TEXT_ALIGN_JUSTIFY => 'justify' - justify alignment
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then text alignment is set only to the row range.
$endColumn integer end column, if null, then text alignment is set just to the column range.

setVerticalAlignmentForCellRange() public method

sets vertical alignment to cells of a given cell range
public setVerticalAlignmentForCellRange ( string $verticalAlignment, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null )
$verticalAlignment string Vertical alignment of cell (default top). Represented by PHPRtfLite_Container::VERTICAL_ALIGN_*
Possible values:
PHPRtfLite_Container::VERTICAL_ALIGN_TOP => 'top' - top alignment;
PHPRtfLite_Container::VERTICAL_ALIGN_CENTER => 'center' - center alignment;
PHPRtfLite_Container::VERTICAL_ALIGN_BOTTOM => 'bottom' - bottom alignment.
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then vertical alignment is set only to the row range.
$endColumn integer end column, if null, then vertical alignment is set just to the column range.

writeToCell() public method

writes text to cell
public writeToCell ( integer $rowIndex, integer $columnIndex, string $text, PHPRtfLite_Font $font = null, PHPRtfLite_ParFormat $parFormat = null, boolean $convertTagsToRtf = true ) : PHPRtfLite_Element
$rowIndex integer row index of cell
$columnIndex integer column index of cell
$text string Text. Also you can use html style tags. @see PHPRtfLite_Container#writeText()
$font PHPRtfLite_Font Font of text
$parFormat PHPRtfLite_ParFormat Paragraph format
$convertTagsToRtf boolean If false, then html style tags are not replaced with rtf code.
return PHPRtfLite_Element

Property Details

$_alignment protected property

protected string $_alignment
return string

$_columns protected property

array of PHPRtfLite_Table_Column instances
protected PHPRtfLite_Table_Column[] $_columns
return PHPRtfLite_Table_Column[]

$_container protected property

protected PHPRtfLite_Container $_container
return PHPRtfLite_Container

$_firstRowIsHeader protected property

protected bool $_firstRowIsHeader
return boolean

$_leftPosition protected property

protected int $_leftPosition
return integer

$_nestDepth protected property

.. and so on ..
protected int $_nestDepth
return integer

$_preventEmptyParagraph protected property

flag for preventing an empty paragraph after table
protected bool $_preventEmptyParagraph
return boolean

$_preventPageBreak protected property

protected bool $_preventPageBreak
return boolean

$_repeatFirstRowHeader protected property

protected bool $_repeatFirstRowHeader
return boolean

$_rows protected property

array of PHPRtfLite_Table_Row instances
protected PHPRtfLite_Table_Row[] $_rows
return PHPRtfLite_Table_Row[]