even spacing of cell and multicell next to each other in fpdf - php

I am generating a pdf (using fpdf) based on user input coming via an html form. The pdf has two columns, the left side has the label of the variable and the right side has the value entered by the user. The problem I am facing is when I have a user input that spans multiple lines. For example, the value of the address can span from 1 line (default address) to up to 4 lines (address input by the user).
Right now I am using multicell to allow user entered address to wrap around the cell, as seen below:
$fpdf->Cell(65,28,"Address:",1,0);
$fpdf->Multicell(125,7,$address,1,'L',false);
For the "Cell", I have set the height as 28, because I know that the neighboring multicell can span a maximum of 4 lines. But since only the "multicell" expands and not the "cell", in the above code, my output looks like this:
fpdf output 1
If I change the height and width values of the "cell" and "multicell" like below:
$fpdf->Cell(65,7,"Address:",1,0);
$fpdf->Multicell(125,7,$address,1,'L',false);
I get an output like this when the address is more than 1 line:
fpdf output 2
Is there any solution to ensure that the bot the cells are always the same height and look more even?
Thank you!

Related

Get calculated height of a PHPSpreadsheet row

I'm trying to get the calculated height of a row in PHPSpreadsheet but whenever I do something like
$spreadsheet->getActiveSheet()->getRowDimension($row)->getRowHeight();
I always get a -1 value which is correct based on their documentation as that is the default value. I need to get the calculated height in pt though as I need to do some calculations. I have a cell that is set to wrap text, and spans multiple lines. Anyone knows how to get the calculated height of a row?
-1 is the value of auto height. Means the value will calculated automatically. If you need a number of height. I would suggest to calc the height over the value of the cell. You must do following: Find newlines in the content and multiply them with 12.75 pts (standard height). Some informations you can find here to.

User input a number of series as x and y in php/html

I am new to HTML and PHP and I need to design an HTML/PHP user input that can accept a series of numbers like this:
input your x: then there is a box to enter the numbers. User should input numbers separated by commas like 1,2,3,4 (all at once can be typed in the box and submitted)
I know that I can use GET or POST in method attribute. But I do not know how to define number series. The next step is to separate individual numbers so I can not define it as text unless I find a trick that can separate text by, and convert to numbers (so input is text but there is a code that separate and convert text to individual numbers like 1 and 2 and 3 and 4).
You can use explode() function like this;
$numbers = explode(',', $_GET['numbers']);
$numbers is array of the numbers that user entered.

dollar sign is shown in before any integer value rather than actual value when setcellvalue phpexcel?

I am using the below code to set the cell value, but it shows the output in the cell which is different than the original:
$excel2->getActiveSheet()->setCellValue("F2",'1234567890');
Output
$1,234,567,890.00
The actual output which I expect is 1234567890, but I don't know why it is showing like this, any help would be appreciated.
you should add number format to your cell
$excel2->getActiveSheet()->getStyle('F2') ->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberForm‌​at::FORMAT_NUMBER);
For more information of cell styling have look here and look Style classes on left navigation links.
Use number format and set format code as per your requirement.
Try below code.
$excel2->getActiveSheet()->setCellValue("F2",'1234567890')->getNumberFormat()->SetFormatCode('#,##0');

Break table if height is greater than value

I'm working on a script that generates a PHP table containing some values from a MySQL database. The script will be displayed on a TV, so I need to break it if its height is greater than 1280 (I've got this value by completing it with values 'till it fits perfect, then I've used jQuery alert to display its height) and I will use jquery.cycle.all plugin to create a slideshow from the tables.
My solution was to use a PHP variable and increment it on each generated then if I have let's say 13 rows, it echoes </table><table>, but the cells must have an exact width so it may add a new line of text (if I have a longer text) on a cell and the table will have more than 1280px height.
Does anybody have any idea about how I can solve this?
Possible solutions:
Use the css overflow: hidden to prevent content going to the next line and just hide it
Use javascript to iterate over each row, calculate the height of the row and remove rows if the total height exceeds 1280px.
Use PHP to calculate the length of the text in actual px and how many rows would be used, but that is quite complex.

merge adjacent html table cells based on class or value

I have a html table with a variable number of cells.
For the sake of this example i will say 20x20 (although it's quite bigger).
This is generated via php and the dataset to populate the table has been pulled from mysql.
Each one of these cells has a numeric value, and it needs to specifically be placed where is is. So if cell A(10,15) has a value of 100, that 100 needs to specifically be on 10,15-
And while the table is being generated i have no way to analyze the positioning.
Now, many of these cells, have other adjacent cells with the same value. Either horizontally or vertically.
What i need to do is merge adjacent cells of a this table that have the same value.
This could be horizontal, vertical, or both, but still keeping it a rectangle- Nothing too funky.
For example if i have
0 1 1 1 0
2 2 5 0 4
5 5 5 1 4
i need to modify the colspan and/or rowspan based on value-
To be noted is that upon generation i can actually define classes or ids for each one
of these cells. Also during generation i can identify wether there will be more than one in a series in a row, but i have no way of knowing wether there will be one on the row below.
ps: i did do a bit a research and found this thread.
Complex table merging javascript & jquery algorithm
modified the jsfiddle example to affect both colspan and rowspan of the cell but it seems to flip out when it needs to merge more that two cells-
What could be a suggested approach on the matter?
Thank you in advance
Do it in two passes (O(n2)), first traverse your array in the width and detect the number of adjacent cells (and set zero for a cell after the same one) :
0(1) 1(3) 1(0) 1(0) 0(1)
2(2) 2(0) 5(1) 0(1) 4(1)
5(3) 5(0) 5(0) 1(1) 4(1)
Then, traverse it vertically, and find cells where both numbers are the same (and the count > 0), you'll get :
0(1,1) 1(3,1) 1(0,0) 1(0,0) 0(1,1)
2(2,1) 2(0,0) 5(1,0) 0(1,1) 4(1,2)
5(3,1) 5(0,0) 5(0,0) 1(1,1) 4(1,0)
Now, the first number of the pair is the colspan, the second is the rowspan. If one of the number is 0, don't output it.
0 1---- 0
2-- 5 0 4
5---- 1 |

Categories