I am creating forms using phprtf and I would like to set a border on the outer edge of the whole table.
Most of my form templates use tables and I simply insert an extra table row for every form question I wish to insert from the database. The layout of these forms is likely to change significantly over time so I have been trying to find an easy way to set borders only on the outer edges of a table.
My First approach was to create a new border with left, top, right & bottom set and use setBorderForCellRange with the range set to the entire table. This obviously did not work (It added a left, top, right and bottom border to every cell!).
My second approach was to create 4 different borders (left only, top only, right only and bottom) and applied them to each side of the table individually using setBorderForCellRange on the first column, then first row, then last column etc. This does not work either, as the corners of the table have the border set twice and the second border replaces the first (I set the left border on the first column and then set a Top border on the first row which resulted in row1, col1 not having a Left Border).
After some thought I realised I probably want to write a function that will set a border only on the outer edge of a range of cells. It would have to be capable of setting 13 different types of border to cover all possible layouts (listed below) and would probably have to evaluate each cell on the outer edge of the range individually to deduce the required borders from its position within the specified range. If it works well I would be looking to submit it to be included in phprtf as I suspect it would be a useful function to have.
Borders Required for outer edges on a range
- Left, Top, Right, Bottom: For a range that only includes a single cell.
- Left, Top, Right: For the top of a single column range.
- Left, Right, Bottom: For the bottom of a single column range.
- Left, Top, Bottom: For the start of a single row range.
- Top, Right, Bottom: For the end of a single row range.
- Left, Top: For the top left corner of a table with >=2 columns or rows.
- Top, Right: For the top right corner of a table with >=2 column or rows.
- Right, Bottom: For the bottom right corner of a table with >=2 column or rows.
- Left, Bottom: For the bottom left corner of a table with >=2 column.
- Left: For the 2nd to the 2nd last cells in the first column.
- Top: For the 2nd to the 2nd last cells in the first row.
- Right: For the 2nd to the 2nd last cells in the last column.
- Bottom: For the 2nd to the 2nd last cells in the last row.
I was wondering if I am possibly "re-inventing the wheel" and making this much more difficult than it needs to be. Any comments, thoughts or hints on how I can achieve this would be appreciated.
Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a method that works for the moment, but thanks anyway to anyone who read the above.
I gave up trying to do it with ranges (ie applying a top border to all the cells from the top row except the first and last) and just set the borders on each cell individually (based on their coordinates in the table).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am creating forms using phprtf and I would like to set a border on the outer edge of the whole table.
Most of my form templates use tables and I simply insert an extra table row for every form question I wish to insert from the database. The layout of these forms is likely to change significantly over time so I have been trying to find an easy way to set borders only on the outer edges of a table.
My First approach was to create a new border with left, top, right & bottom set and use setBorderForCellRange with the range set to the entire table. This obviously did not work (It added a left, top, right and bottom border to every cell!).
My second approach was to create 4 different borders (left only, top only, right only and bottom) and applied them to each side of the table individually using setBorderForCellRange on the first column, then first row, then last column etc. This does not work either, as the corners of the table have the border set twice and the second border replaces the first (I set the left border on the first column and then set a Top border on the first row which resulted in row1, col1 not having a Left Border).
After some thought I realised I probably want to write a function that will set a border only on the outer edge of a range of cells. It would have to be capable of setting 13 different types of border to cover all possible layouts (listed below) and would probably have to evaluate each cell on the outer edge of the range individually to deduce the required borders from its position within the specified range. If it works well I would be looking to submit it to be included in phprtf as I suspect it would be a useful function to have.
Borders Required for outer edges on a range
- Left, Top, Right, Bottom: For a range that only includes a single cell.
- Left, Top, Right: For the top of a single column range.
- Left, Right, Bottom: For the bottom of a single column range.
- Left, Top, Bottom: For the start of a single row range.
- Top, Right, Bottom: For the end of a single row range.
- Left, Top: For the top left corner of a table with >=2 columns or rows.
- Top, Right: For the top right corner of a table with >=2 column or rows.
- Right, Bottom: For the bottom right corner of a table with >=2 column or rows.
- Left, Bottom: For the bottom left corner of a table with >=2 column.
- Left: For the 2nd to the 2nd last cells in the first column.
- Top: For the 2nd to the 2nd last cells in the first row.
- Right: For the 2nd to the 2nd last cells in the last column.
- Bottom: For the 2nd to the 2nd last cells in the last row.
I was wondering if I am possibly "re-inventing the wheel" and making this much more difficult than it needs to be. Any comments, thoughts or hints on how I can achieve this would be appreciated.
Regards
Hi,
I have a method that works for the moment, but thanks anyway to anyone who read the above.
I gave up trying to do it with ranges (ie applying a top border to all the cells from the top row except the first and last) and just set the borders on each cell individually (based on their coordinates in the table).