PHP loops on columns - php

I'm using PHPExcel to convert Excel file into HTML table.
Since I've added this Jquery function to fix my first top row (because Phpexcel doesn't generate <thead></thead> tags :
I'm using http://mkoryak.github.io/floatThead/ plugin Jquery..
var table = $('#sheet0'); // select the table of interest
var thead = $('<thead/>').prependTo(table); // create <thead></thead>
table.find('tbody tr').eq(0).appendTo(thead);
// Now the table is ready to have your chosen method applied to fix the position of the thead.
$('table#sheet0').floatThead({
position: 'fixed',
index: '8',
overflow: 'auto'
});
I just want to load the first 13 columns, I made a ReadFilter but it doesn't work properly..
Here you can see the code which loops through the cells :
https://github.com/PHPOffice/PHPExcel/blob/master/Classes/PHPExcel/Writer/HTML.php#L356
How can I stop the loop at the 13'th column ?

You'd have to modify the Writer code to limit it, that functionality isn't built into PHPExcel; unless you prevented it reading those extra columns with a read filter

To show only 13 columns i did that in Writer/HTML.php :
public function generateSheetData() {
// CODE HERE
// Get worksheet dimension
$dimension = explode(':', $sheet->calculateWorksheetDimension());
$dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
$dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
$dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
** HERE **
$dimension[1][0] = 13;
it works great , not blank cells !
Since i use "floatThead plugin" like above in my post, blank cells appears only in the :
HTML Output :
How can i access this th.floatThead to remove() him ?
Something like that Jquery ? :
table.find('thead th.floatThead-col:nth-child(8)').remove();
Unable to access th.floatThead-col to remove it..

Related

TeeChart for PHP : Differences between image render and JavaScript Export

I try to use the right axis of TeeChart for PHP. I'm aware that we need to link a valid serie to both vertical axis. In fact, I have tried a simple test with the custom axis demo on the Steema site. I cut and pasted the demo and try to export it to javascript instead of rendering it.
I used this code to export to javascript :
echo $tChart1->getChart()->getExport()->getImage()->getJavaScript()->Render()->toString();
Here is a snapshot of the 2 renders side-by-side (sorry to put it in a link, this forum don't allow me to post pictures yet...)
Is there a way to get the right axis to show with the export?
EDIT:
Here is the code to test on your side :
<?php
//Includes
include "../../../sources/TChart.php";
$chart1 = new TChart(600,450);
$chart1->getChart()->getHeader()->setText("Custom Axes Demo");
$chart1->getAspect()->setView3D(false);
$line1 = new Line($chart1->getChart());
$line2 = new Line($chart1->getChart());
$line1->setColor(Color::RED());
$line2->setColor(Color::GREEN());
$chart1->addSeries($line1);
$chart1->addSeries($line2);
// Speed optimization
$chart1->getChart()->setAutoRepaint(false);
for($t = 0; $t <= 10; ++$t) {
$line1->addXY($t, (10 + $t), Color::RED());
if($t > 1) {
$line2->addXY($t, $t, Color::GREEN());
}
}
$chart1->getAxes()->getLeft()->setStartPosition(0);
$chart1->getAxes()->getLeft()->setEndPosition(50);
$chart1->getAxes()->getLeft()->getAxisPen()->color = Color::RED();
$chart1->getAxes()->getLeft()->getTitle()->getFont()->setColor(Color::RED());
$chart1->getAxes()->getLeft()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getLeft()->getTitle()->setText("1st Left Axis");
$chart1->getAxes()->getTop()->getLabels()->setAngle(45);
$chart1->getAxes()->getTop()->getTitle()->getFont()->setColor(Color::YELLOW());
$chart1->getAxes()->getTop()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getBottom()->getLabels()->setAngle(0);
$chart1->getAxes()->getRight()->getLabels()->setAngle(45);
$chart1->getAxes()->getBottom()->getTitle()->getFont()->setColor(new Color(255,25,25));
$chart1->getAxes()->getBottom()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getRight()->getTitle()->getFont()->setColor(Color::BLUE());
$chart1->getAxes()->getRight()->getTitle()->getFont()->setBold(true);
$chart1->getAxes()->getRight()->getTitle()->setText("OtherSide Axis");
$chart1->getAxes()->getRight()->getLabels()->getFont()->setColor(Color::BLUE());
$chart1->getAxes()->getRight()->getAxisPen()->setColor(Color::BLUE());
$chart1->getAxes()->getTop()->getTitle()->setText("Top Axis");
$chart1->getAxes()->getBottom()->getTitle()->setText("Bottom Axis");
$line1->setHorizontalAxis(HorizontalAxis::$BOTH);
$line1->setVerticalAxis(VerticalAxis::$BOTH);
$axis1 = new Axis(false, false, $chart1->getChart());
$chart1->getAxes()->getCustom()->add($axis1);
$line2->setCustomVertAxis($axis1);
$axis1->setStartPosition(50);
$axis1->setEndPosition(100);
$axis1->getTitle()->getFont()->setColor(Color::GREEN());
$axis1->getTitle()->getFont()->setBold(true);
$axis1->getTitle()->setText("Extra Axis");
$axis1->getTitle()->setAngle(90);
$axis1->setRelativePosition(20);
$axis1->getAxisPen()->setColor(Color::GREEN());
$axis1->getGrid()->setVisible(false);
echo $tChart1->getChart()->getExport()->getImage()->getJavaScript()->Render()->toString();?>
I've modified the end of your test page to show both the HTML5 and the PHP charts at the same page:
echo $chart1->getChart()->getExport()->getImage()->getJavaScript()->Render()->toString();
$chart1->render("chart1.png");
$rand=rand();
print '<img src="chart1.png?rand='.$rand.'">';
Then, I've modified TeeChart PHP sources to also export the custom axes and the assign.
It now looks like this:
Please, send a mail to "info#steema.com" and we'll send you the modified unit (JavaScriptExport.php).

best way to store html in sql using php - display in htmlText in as3

I am having many issues getting html to display correctly in my using a dynamic textField in as3. I am having two main issues.
Either the <br> and <p> are not showing he leaves no line breaks or not the correct formatting with no spaces between some words etc...
there is an error loading because I have it stored in the database wrong, or I am sending the var to flash wrong so flash can't read it or display it correctly.
I understand there are a few levels of complexity to this that could be found in one or all of these 3 codes.
Storing it in the database and using best format.
Pulling it from the database and converting it to a string that can be sent to as3.
Getting the as3 to display the html correctly.
I am not worried about css styles or any other html. I just want it to display the format correctly with the right line breaks etc...
One important note. I am pulling the html from an external page so I don't have control over all the extra html code in this, such as styles etc....
In mySql I am storing the html in a TEXT type as opposed to varchar etc...
Here is the php code that is storing the html text.
<?
// I am only showing what I believe to be the relevant code.
//I am mainly concerned about the Content var.
$content = trim(strip_tags(addslashes($content)));
// Also tried the line below without the strip tags
$content = trim(addslashes($content));
mysqli_query($con,"INSERT INTO myDataBase (Content, Title) VALUES ('$content','$t'");
?>
Here the php code that is getting the content from the sql.
<?
while($row = mysqli_fetch_array($result))
{
$Content[] = stripslashes($row['Content']);
}
/// sending to as3
echo "&Content1=$Content[1]";
?>
Here is the as3 code that is displaying the html. (Not working well)
public function popeContent()
{
var formatT = new TextFormat( );
formatT.bold = false;
formatT.color = 0x454544;
formatT.font = "TradeGothic";
formatT.size = 40;
formatT.leading = 10;
formatT.font = "Arial";
theContent.multiline = true;
theContent.wordWrap = true;
theContent.htmlText = Content1;
theContent.width = 1075;
theContent.y = 0;
theContent.x = 0;
theContent.autoSize = TextFieldAutoSize.LEFT;
theContent.setTextFormat(formatT);
addChild(theContent);
}
Any help to send me in the right direction would be appreciated. Thanks so much.

How to get a php variable in jquery function?

I want to pass a php variable in jquery function. Actually i m generating a dynamic php variable .
$imageslider = "imageslider_".$convertcode;
$imageslider is div of image gallery slider which i want to show on click on an icon.
Icon div is also generated dyanamically by the following code
$paletlyicon = "paletlyicon_".$convertcode;
Now i have a jquery function as follows
jQuery('<?php echo '.'.$paletlyicon ; ?> ').hover(function()
{
jQuery('<?php echo '.'.$imageslider ; ?>').show();
});
This is not working somehow ..i tried to alert the dynamic variables but they r showing nothing..
Plz look into it..
Hey what are the dom you define to ?
a class or a id ?Change to :
$imageslider = ".imageslider_".$convertcode; //Add '.' add first
and
$paletlyicon = ".paletlyicon_".$convertcode; //Add '.' add first
So if you don't add '.' or '#', you define to manipulate the dom named paletlyicon_".$convertcode
Good luck

what is {VARIABLE} in HTML means, and how to initialize it?

I have recently reading someone code. In his code I see a weird html text written like {VARIABLE} . What is that syntax mean? and how to create it? Thanks
In PHP, there's something called "Complex (curly) syntax" (look for this deeper in the page) where you inject variable's values into strings using {} instead of cutting and concatenating the string.
A similar answer can be found here
Another case is that the HTML could contain that text is when it is used as a template, like this one in CodeIgniter.
You don't initialize it. It's part of their templating engine.
Regardless of how they are doing it, the idea is to find/replace "{VAR}" with the actual data you want.
var songTemplate = "<li class=\"track\"><span class=\"num\">{{TRACKNUM}}.</span>" +
"<span class=\"title\">{{TITLE}}</span>" +
"<span class=\"duration\">{{DURATION}}</span></li>";
var songs = [ { tracknum : 1, title : "Speak to Me/Breathe", duration : "4:13" },
{ tracknum : 2, title : "On the Run", duration : "3:36" },
{ tracknum : 3, title : "Time", duration : "7:01" } ];
function makeTrack (song, template) {
var track = "";
track = template.replace("{{TRACKNUM}}", song.tracknum);
track = template.replace("{{TITLE}}"), song.title);
track = template.replace("{{DURATION}}", song.duration);
return track;
}
function trackList (songs, template) {
var list = "<ul class=\"tracklist\">";
songs.forEach(function (song) {
list += makeTrack(song, template);
});
list += "</ul>";
return list;
}
var songlist = trackList(songs, songTemplate);
parentEl.innerHTML = songlist;
The basic idea, regardless of what language is used to template it, is that you start with a string of HTML, pull out what you know you want to replace, and put in the data that you want.
I've shown you an ugly, ugly template (it'd be better if I only had to write in an array of variable names, and it did the rest... ...or if it looked through the string to find {{X}} and then looked through an object for the right value to replace what it found).
This also has security holes, if you don't control both the template and the data (if you allow for end-user input anywhere on your site, then you don't have control).
But this should be enough to show how templates do what they do, and why.

How to create FPDF tables?

I have a problem creating tables with fpdf.
Can anyone help me making this page (or at least tell me how to do it)?
invoice tables
Or can you show how to convert HTML tables to FPDF tables and put the code here?
I also have this (along with the connection to the database):
$person = mysql_fetch_array($result);
I would like this to function when added inside the tables with this = (example)
$pdf->Cell(0,260,''.$person["CA"],'C',0 ,1); --- .$person["CA"]
Can anyone help me?
Well, FPDF works kinda like a typewriter, in that it has a roving X,Y point which it writes to, which you can manually move around or let it do it for you.
I don't know if the huge whitespace at the left is required. If so, you'd have to call $this->SetX($coordinate) before each write.
You should do something like this:
class InvoicePDF extends FPDF //Create a new class to contain the header/footer/etc. which extends FPDF
{
public function Header()
{
//Header stuff goes here, like the big Invoice
$this->SetY(10); //SetY 10 units down from the top, experiment with distance to get appropriate distance
$this->SetFont('Arial','',20); //Set Font to Arial/Helvetica 20 pt font
$this->SetTextColor(0,0,0); //Set Text Color to Black;
$this->Cell(0,9,"INVOICE",0,0,'R'); //Write the word INVOICE Right aligned in a box the width of the page, will put it at the far right of the page
}
public function Footer()
{
//any footer stuff goes here
}
public function FillHeadInfo($info) //$info would be an array of the stuff to fill the small table at the top
{
$this->SetY(0); //reset the Y to the original, since we moved it down to write INVOICE
$this->SetFont('Arial','',12);
$this->SetFillColor(224,224,224); //Set background of the cell to be that grey color
$this->Cell(20,12,"Order #",1,0,'C',true); //Write a cell 20 wide, 12 high, filled and bordered, with Order # centered inside, last argument 'true' tells it to fill the cell with the color specified
$this->Cell(20,12,"Coding",1,0,'C',true);
$this->Cell(20,12,"Sales Code",1,1,'C',true); //the 1 before the 'C' instead of 0 in previous lines tells it to move down by the height of the cell after writing this
$this->Cell(20,12,$info['ordernum'],1,0,'C');
$this->Cell(20,12,$info['coding'],1,0,'C');
$this->Cell(20,12,$info['salescode'],1,1,'C');
$this->Cell(40,12,"Name & Address",1,0,'C',true);
$this->Cell(20,12,"Date",1,1,'C',true);
$y = $this->GetY(); //Need the current Y value to reset it after the next line, as multicell automatically moves down after write
$x = $this->GetX(); // Might need the X too
$this->MultiCell(40,12,$info['customername'] . "\n" . $info['address'] . "\n" . $info['city'] . ', ' . $info['state'] . ' ' . $info['zip'],1,'L',false); //I assume the customer address info is broken up into multiple different pieces
$this->SetY($y); //Reset the write point
$this->SetX($x + 40); //Move X to $x + width of last cell
$this->Cell(20,36,date("format",strtotime($info['date'])),1,1,'C'); //Might be easier to use $this->Rect() to draw rectangles for address and date and then write the address and date into them without borders using SetX and SetY, if the borders don't line up or whatever
}
public function fillItems($items)
{
//You'd build the items list much the same way as above, using a foreach loop or whatever
//Could also easily combine this function and the one above
}
}
Then, when creating the pdf you'd do something like this:
require_once('fpdf.php');
require_once('class.invoicepdf.php');
//Get whatever info you need to fill the pdf
$pdf = new InvoicePDF('P','mm','Letter');
$pdf->AddPage();
$pdf->FillHeadInfo($info); //Could also pass $_POST and rely on the keys of the $_POST array
$pdf->FillItems($items);
$pdf->Output('filename.pdf','I');
By the way, I'd suggest rather than trying to write it from $_POST, you save the order to the DB, then pass the order ID along to the script to write the pdf via a link and $_GET, and have the script retrieve the info from the DB, this way you can select only the info you need.

Categories