PHPExcel - Excel5 - Create Line Chart - Chart Missing - php

Reject? I am sure I am not the first that has ran into this issue.
I am trying to create a chart using PHPExcel and the Excel5 library to produce an .xls file of the '95 format.
All goes well except for the creation/save of the chart itself. The file is saved/downloaded/opened without any errors alerted by either, PHPExcel during creation/save, or by Excel during opening the file.
The only real issue is, there is no chart visible within the Excel '95 .xls file created.
I have checked to be sure the MIME type is being set to the '95 .xls format application/vnd.ms-excel. It is.
Here is the code relating to the chart creation, its a little messy currently, but like I said, works like a charm for the 2007 version:
//ADD THE REPORT SUMMARY CHART
$labels = array(
new PHPExcel_Chart_DataSeriesValues('String', "'Report Summary'!C1", null, 1),
new PHPExcel_Chart_DataSeriesValues('String', "'Report Summary'!D1", null, 1)
);
$chrtCols = "'Report Summary'!B2:B$rowNum";
$chrtVals = "'Report Summary'!C2:C$rowNum";
$chrtVals2 = "'Report Summary'!D2:D$rowNum";
$periods = new PHPExcel_Chart_DataSeriesValues('String', $chrtCols, null, $rowNum-1);
$values = new PHPExcel_Chart_DataSeriesValues('Number', $chrtVals, null, $rowNum-1);
$values2 = new PHPExcel_Chart_DataSeriesValues('Number', $chrtVals2, null, $rowNum-1);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART,
PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
array(0,1),
$labels,
array($periods,$periods),
array($values,$values2)
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$layout = new PHPExcel_Chart_Layout();
$plotarea = new PHPExcel_Chart_PlotArea($layout, array($series));
$chart = new PHPExcel_Chart('sample', null, null, $plotarea);
$chart->setTopLeftPosition('A1', 24, 24);
$chart->setBottomRightPosition('B18', -24);
$actSheet->addChart($chart);
The issue seems to be with the '95 version only as the exact same code works to create a valid 2007 version of the file (using the Excel_2007 class rather than Excel5).
Any thoughts? Are line-charts constructed differently (or labels defined differently) in Excel_07 as compared to Excel_95? Any other declarations in the $series array I should add/modify/delete to get the chart to appear Excel_95?
Yes, I am including $objWriter->setIncludeCharts(TRUE); prior to writing the file.
$rowNum is the last row of data.

PHPExcel only supports charts for the Excel2007 Reader/Writer; that feature has not been written for the Excel5 Reader/Writer

Related

PhpPresentation not showing Charts (using CodeIgniter on PHP 5.6)

With my Laravel app, the PHPPresentation library I had is producing fine charts with no errors at all. Now when I'm applying it on a CodeIgniter app, I just copy pasted the code and installed a composer, the chart isn't working anymore
I tried to install the PHPPresentation manually and read the documents, but to no avail, not a single one succeeded
// Create new PHPPresentation object
$objPHPPresentation = new PhpPresentation();
// Set properties
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPresentation Team')
->setTitle('Sample 01 Title')
->setSubject('Sample 01 Subject')
->setDescription('Sample 01 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');
// Point towards the last slide
$currentSlide = $objPHPPresentation->getActiveSlide();
//Data
$seriesData = array(
'Monday' => 12,
'Tuesday' => 15,
'Wednesday' => 13,
'Thursday' => 17,
'Friday' => 14,
'Saturday' => 9,
'Sunday' => 7
);
// Set Style
$oFill = new Fill();
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('ffe6e6'));
$oShadow = new Shadow();
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);
//Define Line Chart lines
$oOutline = new Outline();
$oOutline->getFill()->setFillType(Fill::FILL_SOLID);
$oOutline->getFill()->setStartColor(new Color(Color::COLOR_BLACK));
$oOutline->setWidth(1);
// Create a line chart (that should be inserted in a shape)
$lineChart = new Line();
$series = new Series('Views', $seriesData);
$series->setShowSeriesName(false);
$series->setShowValue(true);
$series->getFont()->setSize(12);
$series->setOutline($oOutline);
$lineChart->addSeries($series);
Back in my Laravel app this PHPPresentation sample works perfectly fine, but when I placed it in my CodeIgniter app, it shows a blank image
Here's a sample output:

Prestashop 1.7.4.2 - TCDPF Generate Barcode in Invoice Error

I am using TCDPF to generate barcode in invoice. Thus, when I download invoice by clicking "View Invoice" from Orders page, it should download with a barcode generated. At the moment, I am just testing a random number.
In HTMLTemplateInvoice.php, I added the following codes:
// Random number for testing
$barcodeobj = new TCPDFBarcode('1234567890123', 'C39');
// Assign to template
// All other unnecessary variables not displayed
'barcode' => base64_encode($barcodeobj->getBarcodePNG(1, 30, array(255,255,255))),
);
For testing purpose, I added the following codes in invoice.addresses.tab.tpl
<img src="data:image/png;base64,{$barcode}>">
The barcode is displayed. Unfortunately, it is dislaying as a page and it is not generated in the invoice. The invoice will not download too.
I am using Prestashop 1.7.4.2 and upgraded to PHP 7.2.
I've tried this code
$barcodeobj = new TCPDFBarcode("123456789123", 'C39');
$Barcode = $barcodeobj->getBarcodePngData(2, 40, array(0,0,0));
and then i created a new pdf :
$Barcode_pdf = new TCPDF('P', 'mm', 'A5', true, 'UTF-8', false);
$Barcode_pdf->SetMargins(7, 10.4, 8);
$Barcode_pdf->setImageScale(0.5);
$Barcode_pdf->AddPage();
$Barcode_pdf->Image('#'.$Barcode,'10','20','60' );
$Barcode_pdf->Output('Barcode.pdf', 'I')
you can attach it to email if you want but change the output type to 'S':
$Barcode_attachment = array();
$Barcode_attachment['content'] = $Barcode_pdf->Output('Barcode.pdf', 'S');
$Barcode_attachment['name'] = 'Barcode.pdf'; // getting pdf file name
$Barcode_attachment['invoice']['mime'] = 'application/pdf';
$Barcode_attachment['mime'] = 'application/pdf';
and then just add $Barcode_attachment to your email .

How can i change the style of the line chart generated with phpexcel?

I am generating a line chart using the example from Github library.
What i want to have is the option to set few custom styles for each of the lines in the chart, as we do manually in the excel sheet like:
Select Line in the chart, Format Data Series, then:
Marker Options > None
Line Style > Width > 2.5pt (1pt is default)
Line Style > Smoothed line
How can i set the above three options for the lines generated in the line chart?
So far, here is my code to set the layout and data series for the chart:
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART,
PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
range(0, count($dataSeriesValues)-1),
$dataseriesLabels,
$xAxisTickValues,
$dataSeriesValues
);
$layout1 = new PHPExcel_Chart_Layout();
$layout1->setShowVal(TRUE);
$plotarea = new PHPExcel_Chart_PlotArea($layout1, array($series));
Can someone provide a hint, as i can't find it in the example.
For your first question to get Marker Options > None:
In the file PHPExcel/Chart/Renderer/jpgraph.php on line 287:
$marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
Change this into
$marker = 'none';
To get rid of the markers, note that this is a bit hacky fix, normally it loops trough all markers and there is no functionality made in the tool to set the marker yourself. (that is why you cannot find it in the examples)
You can also remove or edit the code at Excel2007/Chart.php line 792, here you can see the if ($plotSeriesMarker) code, change it to "none" or just delete this part.
For your second question: Line Style > Width > 2.5pt (1pt is default)
In the file PHPExcel/Writer/Excel2007/Chart.php
At line 781 in function _writePlotGroup you can see the line plotting code
if ($groupType == PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
$objWriter->startElement('c:spPr');
$objWriter->startElement('a:ln');
$objWriter->writeAttribute('w', 12700);
$objWriter->endElement();
$objWriter->endElement();
}
Here you can change the width by using for example:
$objWriter->writeAttribute('w', '40000');
For your third question: Line Style > Smoothed line
The construct function of PHPExcel_Chart_DataSeries is
/**
* Create a new PHPExcel_Chart_DataSeries
*/
public function __construct($plotType = null, $plotGrouping = null, $plotOrder = array(), $plotLabel = array(), $plotCategory = array(), $plotValues = array(), $smoothLine = null, $plotStyle = null)
So after your $dataSeriesValues you can define a smoothline and a plotStyle value.
Passing true to the smoothline parameter gives you a smooth line style.
If for some reason that does not work, in the Chart.php you can find on line 272
$objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() );
Change this to
$objWriter->writeAttribute('val', 1 );
And it should work for sure.
At the time of this response the solution to your first question; Marker Options > None is simple and doesn't involve modifying base code. When creating $dataSeriesValues objects(line 86) you can define which type of marker you want or 'none'.
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4, array(), 'none'),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4, array(), 'none'),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4, array(), 'none'),
);

Some Questions about PHPExcel Charts

I am using PHPExcel for generating charts in Excel Files. I have some question whoes answer I couldn't find even after lot of R&D those are
How can I show data labels to chart?
How can I control the width of bar charts?
How can I customize colors of bar charts?
I tried to show labels with layout class like :
$layout = new PHPExcel_Chart_Layout();
$layout->setShowVal(TRUE);
But no success.
I have also explored DataSeries class and Chart Class but couldn't find any solution. Any body here who have already done such tasks, Please guide.
Best Regards.
With this:
$dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1),
);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues)-1), // plotOrder
$dataseriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
you can define the dataseriesLabels to use in your chart
PHPExcel set default Column Width
PhpExcel Bar Chart
Read my answer there may be it will help with charts
and yes better to create what you need and than use it with load and save(as template)
PHPExcel removes chart style when template is loaded

OpenTBS - Content from MySQL as HTML

I have setup OpenTBS to generate dynamically from my contacts database. Now I want to setup the actual content of the email to come from a MySQL table created using CKeditor or another WYSISYG JS editor.
I have been able to get the content to display on the outputted docx file but it is coming this as a straing with the html tags, I somehow need this to format so it comes though as it was put in by the client. I am only going to allow them to use the basics, paragrahs, bold, italics and maybe a few other tags.
Is this someway I can convert this html string to word copy / text? Or somehow have a different WYSIWYG editor to save it in MySQL as word code rather then html code.
Thanks
It's not really relevant but below is the function that generates the OpenTBS document from a template and the database (I am using CakePHP) MailMerge.description is the body with the html code at the moment.
// FUNCTION EXPORT MAIL MERGE
// -------------------------------------------------------------->
function mail_merge()
{
Configure::write('debug',2);
$this->layout = null;
$this->autoRender = FALSE;
// GET THE CONTACTS
// ------------------------------------------------------------->
$contacts = $this->Contact->find('all', array('limit' => 20, 'contain' => FALSE));
$this->loadModel('MailMerge');
$content = $this->MailMerge->find('first', array(
'conditions' => array('MailMerge.id' => 1),
'fields' => array('MailMerge.description')
));
// Get a new instance of TBS with the OpenTBS plug-in
// ------------------------------------------------------------->
$otbs = $this->Tbs->getOpenTbs();
// Load the template file
// ------------------------------------------------------------->
$otbs->LoadTemplate(APP . DS . WEBROOT_DIR . '/files/data_files/enquiry_letter_sample_redcliffe.docx');
// Merge data in the template
// ------------------------------------------------------------->
$otbs->MergeBlock('r', $contacts);
$otbs->MergeBlock('content', $content);
// End the merge and export
// ------------------------------------------------------------->
$file_name = 'export.docx';
$otbs->Show(OPENTBS_DOWNLOAD, $file_name);
}

Categories