- Tables¶
- Text in cells¶
- Cell formatting¶
- Cell font¶
- Cell alignment¶
- Cell padding¶
- Background color¶
- Border formatting¶
- Rotate text in cells¶
- Images¶
- Merging a cell range¶
- Nested tables¶
- php — Align table items to the right using td colspan? (HTML)
- Tables¶
- Text in cells¶
- Cell formatting¶
- Cell font¶
- Cell alignment¶
- Cell padding¶
- Background color¶
- Border formatting¶
- Rotate text in cells¶
- Images¶
- Merging a cell range¶
- Nested tables¶
- php — TCPDF — HTML table align right inside writeHTMLCell does not work
- Share solution ↓
- Additional Information:
- Didn’t find the answer?
- Similar questions
- Write quick answer
- About the technologies asked in this question
- PHP
- HTML
- Welcome to programmierfrage.com
- Get answers to specific questions
- Help Others Solve Their Issues
Tables¶
Cells can contain images, texts, paragraphs and (nested) tables as well.
Text in cells¶
Please mind that row and column indexes are starting with 1.
// writing text to a cell for row 1 and column 2 $table->writeToCell(1, 2, 'text'); // writing text via cell object for row 1 and column 3 $cell = $table->getCell(1, 3); $cell->writeText('text');
Cell formatting¶
Cell font¶
Setting the font for a cell or a cell, cell range, column or row.
// set "Arial" with red color to a single cell $fontRed = new PHPRtfLite_Font(12, 'Arial', '#f00'); $cell = $table->getCell(1, 3); $cell->setFont($fontRed); // set "Times New Roman" with green color to a cell range $fontGreen = new PHPRtfLite_Font(12, 'Times New Roman', '#0f0'); $table->setFontForCellRange($fontGreen, 1, 1, 4, 2); // set "Times New Roman" with blue color to a column $fontBlue = new PHPRtfLite_Font(12, 'Times New Roman', '#00f'); $table->getColumn(1)->setFont($fontBlue); // set "Tahoma" with yellow color to a row $fontYellow = new PHPRtfLite_Font(12, 'Tahoma', '#ff0'); $table->getRow(1)->setFont($fontYellow);
Cell alignment¶
Cells can be aligned horizontal and vertical.
Horizontal alignment is also called text alignment. These types are availble as class constants:
Vertical alignment types available via class constants are:
$cell = $table->getCell(1, 3); $cell->setTextAlignment();
Cell padding¶
Using Microsoft Word top and bottom cell paddings are applied to all cells in a row.
$cell = $table->getCell(1, 3); // cell padding left: 0.2cm $cell->setCellPaddingLeft(0.2); // cell padding right: 0.2cm $cell->setCellPaddingRight(0.2); // cell padding left: 0.4cm $cell->setCellPaddingTop(0.4); // cell padding left: 0.4cm $cell->setCellPaddingBottom(0.4); // or the same in a shorter way $cell->setCellPaddings(0.2, 0.4, 0.2, 0.4);
Background color¶
The background color can be set for a single cell or for a range of cells.
$cell = $table->getCell(1, 3); // set background color of cell to red $cell->setBackgroundColor('#FF0000'); // set background color for a cell range (from row 1 column 1 to row 4 column 4) to blue $table->setBackgroundForCellRange('#0000FF', 1, 1, 4, 2);
Border formatting¶
Cell borders can be set for a single cell or for a range of cells.
$border = new PHPRtfLite_Border( $rtf, // PHPRtfLite instance new PHPRtfLite_Border_Format(2, '#00FF00'), // left border: 2pt, green color new PHPRtfLite_Border_Format(1, '#FFFF00'), // top border: 1pt, yellow color new PHPRtfLite_Border_Format(2, '#FF0000'), // right border: 2pt, red color new PHPRtfLite_Border_Format(1, '#0000FF') // bottom border: 1pt, blue color ); $cell = $table->getCell(1, 3); // cell with border $cell->setBorder($border); // set border for cell range (from row 1 and column 1 to row 3 and column 2) $table->setBorderForCellRange($border, 1, 1, 3, 2);
Read more about creating borders here: Borders.
Rotate text in cells¶
Cell text can be rotated to left and right.
$cell = $table->getCell(1, 3); // rotate text in cell to left $cell->rotateTo(PHPRtfLite_Container_Cell::ROTATE_LEFT); // rotate text for a cell range (from row 1, column 2 to row 3, column 4) to right $table->rotateCellRange(PHPRtfLite_Container_Cell::ROTATE_RIGHT, 1, 2, 3, 4)
Images¶
Images can be added to a table cell.
// adding image to cell row 1 and column 3 $imageFile = '/path/to/image/example.jpg'; $image = $cell->addImage($imageFile); // image width 3cm and height 3cm $image->setWidth(3); $image->setHeight(3); // the same as short cut $table->addImageToCell(1, 3, $imageFile, new PHPRtfLite_ParFormat, 3, 3);
Adding images to the RTF document is also described in Images.
Merging a cell range¶
Cells can be merged horizontal, vertically and both.
// merge cells from row 1 column 1 to row 2 and column 3 $table->mergeCellRange(1, 1, 2, 3);
Nested tables¶
Nested tables are not supported by OpenOffice 3.2.
$cell = $table->getCell(1, 3); $cell->writeText('Text before nested table'); // nested cell $nestedTable = $cell->addTable(); $nestedTable->addRow(1); $nestedTable->addColumnsList(array(1,2)); $nestedTable->writeToCell(1, 1, 'Text for first nested cell'); $cell->writeText('Text after nested table!');
php — Align table items to the right using td colspan? (HTML)
So basically I created a calendar in PHP and HTML. All of the days are stored in a table. But when I render the calendar in my localhost browser, the colspan function doesn’t appear to work on the first row and it starts from the beginning, although the rest of the calendar lines up nicely.
You can see that the first row of elements doesn’t align to the right, which is what a normal calendar would do, even though I used colspan on it.
$output = 'year . ''; $output .= ''; //new table row //creates days of the week header for each day in the array foreach ( $this->weekdays as $days )< //for every day in the weekdays array, setting each of them AS a day ($day) $output .= ''; > //IF the first day of a month doesnt fall on a sunday then use COLSPAN to fill the BEGINNING SPACE if ($this->dayOfWeek > 0)< $output .= ' '; > //Start the num_days counter $output .= ' '; //space calender BELOW the days $current_day = 1;``` (later code) ``` //Increment counters $current_day++; $this->dayOfWeek++; > // Once num_days counter stops, if day of week counter is not 7, then fill the remaining space on the row uing COLSPAN if ($this->dayOfWeek != 7) < //Resets at 7 $remaining_days = 7 - $this->dayOfWeek; //Amount of remaining days in the week $output .= ' '; //span for the remaining days in the week > //Close final row, close table $output .= ' '; $output .= '
';
Tables¶
Cells can contain images, texts, paragraphs and (nested) tables as well.
Text in cells¶
Please mind that row and column indexes are starting with 1.
// writing text to a cell for row 1 and column 2 $table->writeToCell(1, 2, 'text'); // writing text via cell object for row 1 and column 3 $cell = $table->getCell(1, 3); $cell->writeText('text');
Cell formatting¶
Cell font¶
Setting the font for a cell or a cell, cell range, column or row.
// set "Arial" with red color to a single cell $fontRed = new PHPRtfLite_Font(12, 'Arial', '#f00'); $cell = $table->getCell(1, 3); $cell->setFont($fontRed); // set "Times New Roman" with green color to a cell range $fontGreen = new PHPRtfLite_Font(12, 'Times New Roman', '#0f0'); $table->setFontForCellRange($fontGreen, 1, 1, 4, 2); // set "Times New Roman" with blue color to a column $fontBlue = new PHPRtfLite_Font(12, 'Times New Roman', '#00f'); $table->getColumn(1)->setFont($fontBlue); // set "Tahoma" with yellow color to a row $fontYellow = new PHPRtfLite_Font(12, 'Tahoma', '#ff0'); $table->getRow(1)->setFont($fontYellow);
Cell alignment¶
Cells can be aligned horizontal and vertical.
Horizontal alignment is also called text alignment. These types are availble as class constants:
Vertical alignment types available via class constants are:
$cell = $table->getCell(1, 3); $cell->setTextAlignment();
Cell padding¶
Using Microsoft Word top and bottom cell paddings are applied to all cells in a row.
$cell = $table->getCell(1, 3); // cell padding left: 0.2cm $cell->setCellPaddingLeft(0.2); // cell padding right: 0.2cm $cell->setCellPaddingRight(0.2); // cell padding left: 0.4cm $cell->setCellPaddingTop(0.4); // cell padding left: 0.4cm $cell->setCellPaddingBottom(0.4); // or the same in a shorter way $cell->setCellPaddings(0.2, 0.4, 0.2, 0.4);
Background color¶
The background color can be set for a single cell or for a range of cells.
$cell = $table->getCell(1, 3); // set background color of cell to red $cell->setBackgroundColor('#FF0000'); // set background color for a cell range (from row 1 column 1 to row 4 column 4) to blue $table->setBackgroundForCellRange('#0000FF', 1, 1, 4, 2);
Border formatting¶
Cell borders can be set for a single cell or for a range of cells.
$border = new PHPRtfLite_Border( $rtf, // PHPRtfLite instance new PHPRtfLite_Border_Format(2, '#00FF00'), // left border: 2pt, green color new PHPRtfLite_Border_Format(1, '#FFFF00'), // top border: 1pt, yellow color new PHPRtfLite_Border_Format(2, '#FF0000'), // right border: 2pt, red color new PHPRtfLite_Border_Format(1, '#0000FF') // bottom border: 1pt, blue color ); $cell = $table->getCell(1, 3); // cell with border $cell->setBorder($border); // set border for cell range (from row 1 and column 1 to row 3 and column 2) $table->setBorderForCellRange($border, 1, 1, 3, 2);
Read more about creating borders here: Borders.
Rotate text in cells¶
Cell text can be rotated to left and right.
$cell = $table->getCell(1, 3); // rotate text in cell to left $cell->rotateTo(PHPRtfLite_Container_Cell::ROTATE_LEFT); // rotate text for a cell range (from row 1, column 2 to row 3, column 4) to right $table->rotateCellRange(PHPRtfLite_Container_Cell::ROTATE_RIGHT, 1, 2, 3, 4)
Images¶
Images can be added to a table cell.
$cell = $table->getCell(1, 3); // adding image to cell row 1 and column 3 $imageFile = '/path/to/image/example.jpg'; $image = $cell->addImage($imageFile); // image width 3cm and height 3cm $image->setWidth(3); $image->setHeight(3); // the same as short cut $image->addImageToCell(1, 3, $imageFile, new PHPRtfLite_ParFormat, 3, 3);
Adding images to the RTF document is also described in Images.
Merging a cell range¶
Cells can be merged horizontal, vertically and both.
// merge cells from row 1 column 1 to row 2 and column 3 $table->mergeCellRange(1, 1, 2, 3);
Nested tables¶
Nested tables are not supported by OpenOffice 3.2.
$cell = $table->getCell(1, 3); $cell->writeText('Text before nested table'); // nested cell $nestedTable = $cell->addTable(); $nestedTable->addRow(1); $nestedTable->addColumnsList(array(1,2)); $nestedTable->writeToCell(1, 1, 'Text for first nested cell'); $cell->writeText('Text after nested table!');
php — TCPDF — HTML table align right inside writeHTMLCell does not work
I create a table with HTML to be inserted into TCPDF::writeHTMLCell with this format. The table only contains image.
$html_table ='
';
Here’s the TCPDF code to create HTMLCell
$pdf->writeHTMLCell(100, '', '', $pdf->getY(), $html_table, 1, 0, 0, false, 'R', false);
Even thought the HTML can show the table at the right side of page, TCPDF only shows this table at the left side inside the cell.
What is the right code to put the table in align right, put in the right side of the HTMLCell ?
Share solution ↓
Additional Information:
Didn’t find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
About the technologies asked in this question
PHP
PHP (from the English Hypertext Preprocessor — hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML
HTML (English «hyper text markup language» — hypertext markup language) is a special markup language that is used to create sites on the Internet. Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.