PHPPowerpoint set Hyperlink in table cell - hyperlink

I want to set an Hyperlink in a table cell:
/* ADD TABLE ROW */
foreach ($entries as $entry) {
$row = $tableShape->createRow();
$row->getFill()->setFillType(Fill::FILL_SOLID)
->setStartColor(new Color('FFFFFFFF'))
->setEndColor(new Color('FFFFFFFF'));
$row->nextCell()->createTextRun(date_format($entry->getDate(), "d.m.Y"));
$row->nextCell()->createTextRun($entry->getTonality()->getName());
$row->nextCell()->createTextRun($entry->getAccountname());
$row->nextCell()->createTextRun($entry->getContent());
$row->nextCell()->createTextRun($entry->getFollower());
$row->nextCell()->createTextRun($entry->getLink());
}
This code doesn't work:
$row->nextCell()->createTextRun('Link')->setUrl($entry->getLink())
->setTooltip('Link');;

I'm doing it now by adding a shape on the right position.
/* SET HYPERLINK WITH SHAPE */
$shape = $slide->createRichTextShape();
$shape->setWidth($this->cell_link_width)
->setHeight($this->cell_height)
->setOffsetX($this->cell_link_offsetX)
>setOffsetY($this->tableOffsetY + $height);
$textLink = $shape->createTextRun('Link');
$textLink->getHyperlink()->setUrl('http://' . $entry->getLink())
>setTooltip('http://' . $entry->getLink());
I have write an algorithmus and define a variable line_height to set the link on the right position.
Here is my complete function:
public function createTableSlide($objPHPPowerPoint, $pathLogo, $user, $entries) {
$slide = $this->createTemplatedSlide($objPHPPowerPoint, $pathLogo, $user);
/* CREATE TABLE WITH COLUMNS */
$tableShape = $this->getTable($slide, 6);
$this->setTableSlideHeader($slide, 'Social Media', 'Twitter', $tableShape);
/* ADD TABLE ROW */
$i = 1;
$height = 22;
$height_tmp = 0;
$max_height = 554;
foreach ($entries as $entry) {
$height += $height_tmp;
$modulId = $entry->getModul()->getId();
/* NEW SLIDE IF TABLE HEIGHT AT END OF SLIDE */
if($height >= $max_height){
$slide = $this->createTemplatedSlide($objPHPPowerPoint, $pathLogo, $user);
/* CREATE TABLE WITH COLUMNS */
$tableShape = $this->getTable($slide, 6);
$this->setTableSlideHeader($slide, 'Social Media', 'Twitter', $tableShape);
$i = 1;
$height = 22;
$height_tmp = 0;
}
$row_in_cell = ceil(strlen($entry->getContent()) / $this->char_in_row);
if ($row_in_cell > 2) {
$height_tmp = $row_in_cell * $this->line_height + $this->line_height;
} else {
$height_tmp = $this->line_height * 3 + 0.8;
}
$row = $tableShape->createRow();
$row->setHeight($this->cell_height);
$row->getFill()->setFillType(Fill::FILL_SOLID)
->setStartColor(new Color('FFFFFFFF'))
->setEndColor(new Color('FFFFFFFF'));
$row->nextCell()->createTextRun(date_format($entry->getDate(), "d.m.Y"));
$row->nextCell()->createTextRun($entry->getTonality()->getName());
$row->nextCell()->createTextRun($entry->getAccountname());
$row->nextCell()->createTextRun($entry->getContent());
$row->nextCell()->createTextRun($entry->getFollower());
$row->nextCell()->createTextRun($modulId);
/* SET HYPERLINK WITH SHAPE */
$shape = $slide->createRichTextShape();
$shape->setWidth($this->cell_link_width)
->setHeight($this->cell_height)
->setOffsetX($this->cell_link_offsetX)
->setOffsetY($this->tableOffsetY + $height);
$textLink = $shape->createTextRun('Link');
$textLink->getHyperlink()->setUrl('http://' . $entry->getLink())
->setTooltip('http://' . $entry->getLink());
$i++;
}
}
Hope it can help you if you search for the same solution. If anyone has a better solution he can answer me :)

The issue has been fixed in the develop branch.
Link : https://github.com/PHPOffice/PHPPowerPoint/commit/43bea92220396a3c7178f649afbc961be28828c1

Related

Highcharts Showing Uncaught TypeError: Cannot read properties of undefined (reading 'chart')

I've had this HighCharts spider chart working fine for a while now, but we upgraded to the latest HighCharts code and I noticed that the mouseovers are no longer working. My PHP code looks like this:
// Create a new Highchart
$chart = new Highchart();
$chart->includeExtraScripts();
$chart->chart->renderTo = "control_maturity_spider_chart";
$chart->chart->polar = true;
$chart->chart->type = "line";
$chart->chart->width = 1000;
$chart->chart->height = 1000;
$chart->title->text = "Current vs Desired Maturity by Control Family";
$chart->title->x = -80;
$chart->pane->size = "80%";
$chart->xAxis->categories = $categories;
$chart->xAxis->tickmarkPlacement = "on";
$chart->xAxis->lineWidth = 0;
$chart->yAxis->gridLineInterpolation = "polygon";
$chart->yAxis->lineWidth = 0;
$chart->yAxis->min = 0;
$chart->yAxis->max = 5;
$chart->yAxis->tickInterval = 1;
$chart->tooltip->shared = true;
$chart->tooltip->pointFormat = '<span style="color:{series.color}">{series.name}: <b>{point.y}</b><br/>';
$chart->legend->align = "center";
$chart->legend->verticalAlign = "top";
$chart->legend->layout = "vertical";
// Draw the Current Maturity series
$chart->series[0]->name = $escaper->escapeHtml($lang['CurrentControlMaturity']);
$chart->series[0]->data = empty($categories_current_maturity_average) ? [] : $categories_current_maturity_average;
$chart->series[0]->pointPlacement = "on";
// Draw the Desired Maturity series
$chart->series[1]->name = $escaper->escapeHtml($lang['DesiredControlMaturity']);
$chart->series[1]->data = empty($categories_desired_maturity_average) ? [] : $categories_desired_maturity_average;
$chart->series[1]->pointPlacement = "on";
$chart->credits->enabled = false;
echo "<figure class=\"highcharts-figure\">\n";
echo " <div id=\"control_maturity_spider_chart\"></div>\n";
echo "</figure>\n";
echo "<script type=\"text/javascript\">";
echo $chart->render("control_maturity_spider_chart");
echo "</script>\n";
The actual chart renders just fine, but if you mouse over it, you just get this message in the javascript console over and over again:
HighCharts Error Message
If we comment out these two lines of code, the mouseover works:
$chart->tooltip->shared = true;
$chart->tooltip->pointFormat = '<span style="color:{series.color}">{series.name}: <b>{point.y}</b><br/>';
Any thoughts on what we are doing wrong here, or what changed, would be greatly appreciated. Thank you.
this is the bug which you can track here: https://github.com/highcharts/highcharts/issues/17472
As a temporary workaround, add the following wrap function to your code:
(function(H) {
const isObject = H.isObject;
H.Pointer.prototype.findNearestKDPoint = function(series, shared, e) {
var chart = this.chart;
var hoverPoint = chart.hoverPoint;
var tooltip = chart.tooltip;
if (hoverPoint &&
tooltip &&
tooltip.isStickyOnContact()) {
return hoverPoint;
}
var closest;
/** #private */
function sort(p1, p2) {
var isCloserX = p1.distX - p2.distX,
isCloser = p1.dist - p2.dist,
isAbove = ((p2.series.group && p2.series.group.zIndex) -
(p1.series.group && p1.series.group.zIndex));
var result;
// We have two points which are not in the same place on xAxis
// and shared tooltip:
if (isCloserX !== 0 && shared) { // #5721
result = isCloserX;
// Points are not exactly in the same place on x/yAxis:
} else if (isCloser !== 0) {
result = isCloser;
// The same xAxis and yAxis position, sort by z-index:
} else if (isAbove !== 0) {
result = isAbove;
// The same zIndex, sort by array index:
} else {
result =
p1.series.index > p2.series.index ?
-1 :
1;
}
return result;
}
series.forEach(function(s) {
var noSharedTooltip = s.noSharedTooltip && shared,
compareX = (!noSharedTooltip &&
s.options.findNearestPointBy.indexOf('y') < 0),
point = s.searchPoint.call(s.polar, e, compareX);
if ( // Check that we actually found a point on the series.
isObject(point, true) && point.series &&
// Use the new point if it is closer.
(!isObject(closest, true) ||
(sort(closest, point) > 0))) {
closest = point;
}
});
return closest;
};
}(Highcharts))
Demo:
https://jsfiddle.net/BlackLabel/8b2mhqf0/

phpspreadsheet read and getting values using header (1st row value)

How can i get all values from excel using 1st row value
It's working for me using this commande $spreadSheetAry[$i][0], but i need it $spreadSheetAry[$i]["Tracking_Number"]
it's possible?
This is code example:
<?php
use Phppot\DataSource;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
require_once 'DataSource.php';
$db = new DataSource();
$conn = $db->getConnection();
require_once ('./vendor/autoload.php');
$allowedFileType = [
'application/vnd.ms-excel',
'text/xls',
'text/xlsx',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
];
$targetPath = 'uploads/test.xlsx';
$Reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$header = ["Tracking_Number", "Referance"];
$spreadSheet = $Reader->load($targetPath);
$excelSheet = $spreadSheet->getActiveSheet();
$spreadSheetAry = $excelSheet->toArray();
$sheetCount = count($spreadSheetAry);
for ($i = 0; $i <= $sheetCount; $i ++) {
$TN = "";
if (isset($spreadSheetAry[$i][0])) {
$TN = mysqli_real_escape_string($conn, $spreadSheetAry[$i][0]);
}
$RF = "";
if (isset($spreadSheetAry[$i][1])) {
$RF = mysqli_real_escape_string($conn, $spreadSheetAry[$i][1]);
}
echo $TN." - ".$RF."<br/>";
}
?>
Excel example:
enter image description here

tcpdf position adding white block at bottom of page

As you can see from this screenshot, there a white area about 100 px tall being added to the bottom of the page that is also pushing the whole page up and off the top of the page. I'm trying to get the text to be on the blue area of the page footer, in white text. I've tried several related suggestions and cant get them to work. Any assistance is greatly appreciated!
Screenshot: http://screencast.com/t/lt3J1Wle76Dm
CODE:
function downloadFile($rid,$count,$userid,$orderid,$email,$user_password,$owner_password) {
global $wpdb;
$rid = intval($rid);
$query = "
SELECT
filehash,filename,filesize,productid
FROM {$this->dbtable}_product
WHERE rid = {$rid}
";
$res = $wpdb->get_results($query);
$r = $res[0];
$file_location = $this->getplugindir()."uploads/".$r->filehash.".file";
if (!file_exists($file_location)) { exit('File does not exist.'); }
if ($count === true) {
$res = $wpdb->query("UPDATE {$this->dbtable}_product SET download_count = download_count+1 WHERE rid = {$rid}");
$this->auditLog($r->productid, $rid, $userid, 'Downloaded');
}
$filename = str_replace(' ', '_', $r->filename);
require_once($this->getplugindir() . 'fpdf/tcpdf/tcpdf.php');
require_once($this->getplugindir() . 'fpdf/tcpdf/tcpdi.php');
//require_once($this->getplugindir() . 'fpdf/tcpdf/wpds.php');
if ($orderid === false) { $orderid = '12345'; }
$pdf = new TCPDI();
$pagecount = $pdf->setSourceFile($file_location);
$pdf->SetAutoPageBreak(false);
for ($i = 1; $i <= $pagecount; $i++){
$pdf->addPage();
$tplidx = $pdf->importPage($i);
$pdf->useTemplate($tplidx);
$pdf->SetAlpha(0.5);
$pdf->SetFont('Courier', 'I', 6);
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(5, -5);
/*
$pdf->StartTransform();
$pdf->Rotate(5);
*/
$pdf->Write(0, "This guide individually licensed to $email ($orderid)");
/*
$pdf->Rotate(0);
$pdf->StopTransform();
*/
$pdf->SetAlpha(1);
}
$pdf->SetProtection(array(
'modify','copy','annot-forms','fill-forms','extract','assemble'
),$user_password,$owner_password,3);
$pdf->Output($filename,'D');
exit();
}
To move your text, change his position with setXY()
Replace :
$pdf->SetXY(5, -5);
By :
$pdf->SetXY(5, -100); // change Y value to be on blue area

Want several font colors in my cell

Im creating a new cell = new XRTableCell();
I'll show a sample of my code.
I always ending up with the same color in my cell, even if I change it in my "If".
foreach (TaskTime tt in di.TaskTimes[i])
{
.....
TimeToAdd = ClassLibrary.Utils.GetTimeStringFromSec(tt.FromSec % 86400) + " - " + ClassLibrary.Utils.GetTimeStringFromSec(tt.UntilSec % 86400) + " (" + tt.Abbreviation+ ")";
if (taskTimeTextBox.Text.Length > 0)
taskTimeTextBox.Text += "\n";
taskTimeTextBox.Text += TimeToAdd;
if (tt.OnOtherCostDivision)
{
taskTimeTextBox.SelectionStart = taskTimeTextBox.Find(TimeToAdd);
taskTimeTextBox.SelectionFont = new Font("Calibri", 9, FontStyle.Italic);
taskTimeTextBox.SelectionColor = Color.Gray;
}
else
{
taskTimeTextBox.SelectionStart = taskTimeTextBox.Find(TimeToAdd);
taskTimeTextBox.SelectionFont = new Font("Calibri", 9, FontStyle.Italic);
taskTimeTextBox.SelectionColor = Color.Blue;
}
richTxtObject.Rtf = taskTimeTextBox.Rtf;
cell.Controls.Add(richTxtObject);
}
row.Cells.Add(cell);
Soulved it! Didn't worked when I had it this way "taskTimeTextBox.Text += xxxxxxxx ". So I made a list of string, saved my text in if it were "onOtherCostDivision". Later on I hade to loop true my list and see if the final taskTimeTextBox.Text had the text in it and in that cause I added the color.
foreach (var task in taskCostDivList)
{
if (taskTimeTextBox.Text.Contains(task))
{
taskTimeTextBox.SelectionStart = taskTimeTextBox.Find(task);
taskTimeTextBox.Font = new Font("Calibri", 9, FontStyle.Italic);
taskTimeTextBox.SelectionColor = Color.Gray;
}
else
{
taskTimeTextBox.Font = new Font("Calibri", 9, FontStyle.Regular);
taskTimeTextBox.SelectionColor = Color.Black;
}
}

Swarming in AS2

Hi I keep getting the error: expecting identifier before greater than.
on line 13.
Any help would be nice please and Thank you.
fly = function () {
this.animate = function() {
// Capture mouse positions and distance from mouse
this.targetX = _root._xmouse;
this.targetY = _root._ymouse;
this.distX = this.targetX-this.meX+this.flockX;
this.distY = this.targetY-this.meY+this.flockY;
//
if ((this.targetX == this.oldTargetX) && Math.random()>0.9) {
// add small scale random darting if mouse is still
this.flockX = (Math.random()*100)-50;
this.flockY = (Math.random()*100)-50;
} else if ((this.targetX<>this.oldTargetX) && Math.random()>0.8) {
// add large scale random darting if mouse is moving
this.flockX = (Math.random()*400)-200;
this.flockY = (Math.random()*400)-200;
}
// Apply inertia equation
this.meX = Math.round(this.meX+(this.distX)/20);
this.meY = Math.round(this.meY+(this.distY)/20);
// perform animation
this._x = this.meX;
this._y = this.meY;
// remember the current mouse pos so we can tell if
// it has moved next time around
this.oldTargetX = this.targetX;
};
this.initialize = function() {
this.targetX = 0;
this.targetY = 0;
this.distX = 0;
this.distY = 0;
this.meX = this._x;
this.meY = this._y;
this.oldTargetX = 0;
this.flockX = (Math.random()*200)-100;
this.flockY = (Math.random()*200)-100;
};
// set up onEnterFrame script to animate _parent...
this.initialize();
this.onEnterFrame = this.animate;
};
//
//
var i:Number = 0;
var bugClip:MovieClip;
for (i=0; i<30; i++) {
bugClip = this.attachMovie("bug", "bug"+i, i);
fly.apply(bugClip);
}
I don't know about Actionscript, but by looking at your code I would recomend doing like this:
randomValue = Math.random()
if ((this.targetX == this.oldTargetX) && randomValue>0.9) {
The <> operator for not equals has been deprecated since Flash Player 5 Doc reference here
You should use != for the same functionality.
Although i tested this on Flash Player 10.2 and it will still compile and run with no errors. I guess you are compiling to a later version.

Resources