PHPExcel Orphan/Widow, getRowDimension - php

I am having an issue with saving a PDF file from PHPExcel and it creating widow/orphans with my data.
I know of the function to create page breaks,
$objPHPExcel->getActiveSheet()->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );
but I would like to know if there is a function to know the current height of a range of cells.
I have found references to "getRowDimension" in functions like
$objPHPExcel->getActiveSheet()->getRowDimension('10')->setRowHeight(100);
but I cannot find any documentation on that function. Does anyone know if it can calculate the height of the chosen row and/or take a range of rows?
Also, is there a function to calculate the usable space between the header and footer of each page? Or should I calculate that from the page margin?
Thank you,
Nick

$objPHPExcel->getActiveSheet()
->getRowDimension('10')
->getRowHeight();
Will return the row height for the specified row. This is the height in "points", where 1 point is the equivalent of about 1/72 of an inch (or about 0.35mm). A value of 0 indicates a hidden row; while a value of -1 is the default value, which is 12.75pt (about 1/6 of an inch).
The PHPExcel_Shared_Drawing class contains a number of functions for converting between points and other units of measure, such as pointsToPixels() and pixelsToPoints(), and pixelsToEMU() and EMUToPixels() (English Metric Units).
The whole issue of Microsoft's units of measure is really a confusing minefield, but there's a useful blog post here discussing the different units of measure use in MS Office

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.

Disabling auto-matching of two or more lines by their max values

I am using amchart (not stock chart) to generate charts of two or more datasets. I noticed that lines with different values are being adjusted by their max values. Please have a look at the attached screenshot:
As you can see for example the amount 1.8k is above the amount 4.2k because of the enabled auto-adjustment. Searching through the amcharts forum gave no result. Thanks you in advance!
UPDATE 1:
I have found one post with the similar problem, but I think it is quite not a good way
to adjust axises in such manner:
UPDATE 2:
Taking into consideration the #zerion's answer I have written some lines in my backend to be sure the synchronization will always be correct. I calculate min and max values for each numeral field that will be used as an axis, then using usort I sort the dataset array by (max - min) condition.
Yes, or you can even tell the axis to synchronize:
valueAxis2.synchronizeWithAxis(valueAxis1);
valueAxis2.synchronizationMultiplier = 1;
So you should only think of which of your axis has the widest range of values, and sync other axes to this one.
After more careful investigations I have found that the needed effect could be achieved by setting valueAxis.maximum (and maybe valueAxis.minimum if there are negative values) to the highest (lowest) value among all dataSets.

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.

Can text be inserted into a fusion chart?

I'm using the Grid component in fusion charts and need a date string to be used in the value place. It will always fail when i do this as it is looking for a number. Is there anyway it can allow text to be used aswell?
Thanks
The ability to have date-time axis values is not yet available in FusionCharts. Nevertheless, the use case for you does not fit right.
Ideally, the grid component's right column should show a number (value). The left column is text showing the labels. For a grid, it makes very less sense to have text on both columns.
Instead of a date, the right column should show how many month's or days or hours, etc.
Excerpts from FusionCharts documentation: http://docs.fusioncharts.com/charts/contents/advanced/number-format/Number_Scaling.html
Say we're plotting a chart which indicates the time taken by a list of automated processes. Each process in the list can take time ranging from a few seconds to few days. And we've the data for each process in seconds itself. Now, if we were to show all the data on the chart in seconds only, it won't appear too legible. What we can do is build a scale indicating time and then specify it to the chart. This scale, in human terms, would look something as under:
60 seconds = 1 minute
60 minute = 1 hr
24 hrs = 1 day
7 days = 1 week
Now, to convert this scale into FusionCharts XML format, you'll have to do it as under:
First you would need to define the unit of the data which you're providing. Like, in this example, you're providing all data in seconds. So, default number scale would be represented in seconds. We can represent it as <chart defaultNumberScale='s' ...>
Next, we define our own scale for the chart as: <chart numberScaleValue='60,60,24,7' numberScaleUnit='min,hr,day,wk' >. If you carefully see this and match it with our range, you'll find that whatever numeric figures are present on the left hand side of the range is put in numberScaleValue and whatever units are present on the right side of the scale has been put under numberScaleUnit - all separated by commas.
Set the chart formatting flags to on as: <chart formatNumber='1' formatNumberScale='1' ...>
The entire XML would look like:
<chart defaultNumberScale='s' numberScaleValue='60,60,24,7' numberScaleUnit='min,hr,day,wk'><set label='A' value='38' /><set label='B' value='150' /><set label='C' value='11050' /><set label='D' value='334345' /><set label='E' value='1334345' /></chart>
A sample grid (not with the above data) would look like this:

Space a series of values so they don't overlap

There have been a couple of questions very close to this topic, but none really helped me.
Ive been programming a graphing library, and I need an algorithm to vertically place labels without overlapping. I've been stuck on this for a couple of days now, and managed to distil it to the most basic function:
If given a series of label positions along the Y axis, say, 1 1 2 3 5 6 9, and an upper and a lower limits 10 and 0 respectively, I need a way to space out the values to output 1 2 3 4 5 6 9
333467 should be 234567 weighted to be close to the original coordinates.
This should also work backwards, if values are bunched up at the upper end of the scale, they should be spread as much as possible (before overflowing)
I'm not looking for a definitive answer, but I'd like some help on how to approach this problem. Im completely stuck.
Last train of thought was to scan all labels for possible collisions and position them as one big block, aligning to the centre of all the Y coordinates. But this will not work if there are multiple sets of collisions.
EDIT: To put this algorithm in a bigger context, have a look at these two google chart API pie charts:
1) Top stacked labels
2) Bottom Stacked Labels
The labels are almost springy, they avoid collisions by joining together and moving their entire mass to the center of their mass.
Make the set of labels unique by inserting into an ordered set. Divide the difference between the y-axis upper and lower bound by the number of elements in the set. This is your spacing increment. Iterate over the set in order and position one label every spacing increment.
You didn't say anything about needing to preserve a scale...
Well, After some thought and advice from other sources i came up with a solution:
Pseudocode:
foreach labels as label
if label->collidesWith(labels->lowerLimit)
label->moveAwayFrom(labels->lowerLimit)
if label->collidesWith(labels->upperLimit)
label->moveAwayFrom(labels->upperLimit)
if label->collidesWith(label->previous)
label->moveAwayFrom(label->previous)
label->previous->moveAwayFrom(label)
if label->collidesWith(label->next)
label->moveAwayFrom(label->next)
label->next->moveAwayFrom(label)
endforeach
MoveAwayFrom moves 1 pixel at a time. When this function is run multiple times it rejiggles the labels until none of them collide. (in reality im calling this loop 100 times, havent figured out a way to do it more inteligently)

Categories