I create 2 style objects in my php source code :
-the 1st style called $style1 is to fill a cell with red color,
-the 2nd style called $style2 is to fill a cell with green color,
But when I apply the 1st style in a cell with duplicateStyle() method,
it's the 2nd style is applied.
Here the php source code (last PHPExcel version : 1.8.0) :
<?php
// Import PHPExcel class:
include("./PHPExcel/Classes/PHPExcel.php");
// Create a workbook :
$workbook = new PHPExcel;
// Create a sheet :
$sheet = $workbook->getActiveSheet();
// Set to A4 page size :
$sheet->getPageSetup()->setPaperSize(9);
// Set to landscape orientation, but it doesn't work :
$sheet->getPageSetup()->setOrientation("landscape");
/*Create style1 for A1 cell :*/
$style1 = $sheet->getStyle('A1');
$style1->applyFromArray(
array(
'fill' => array(
'type' => 'solid',
//Color filling :
'color' => array('rgb' => 'ff0000')
)
)
);
/*Create style2 for B1 cell :*/
$style2 = $sheet->getStyle('B1');
$style2->applyFromArray(
array(
'fill' => array(
'type' => 'solid',
//Green filling :
'color' => array('rgb' => '00ff00')
)
)
);
//Duplicate style1 to A2 :
$sheet->duplicateStyle($style1, "A2");
//Write in A2 cell. Bug : red filling doesn't work :
$sheet->setCellValue("A2", "Must be red");
//Duplicate style2 to B2 :
$sheet->duplicateStyle($style2, "B2");
//Write in B2 cell :
$sheet->setCellValue("B2", "Must be green");
//Output to brower :
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="file.xlsx"');
header('Cache-Control: max-age=0');
$writer = new PHPExcel_Writer_Excel2007($workbook);
//Office 2003 compatibilty :
$writer->setOffice2003Compatibility(true);
$writer->save('php://output');
?>
So what's the problem?
I find the solution :
Use $style1 = new PHPExcel_Style(); instead of $style1 = $sheet->getStyle('A1');
Thak you very much.
Related
In my application I utilize TCPDF to create a PDF that pastes an SVG onto it with the $link being a url that is being provided by the user so the SVG on the PDF is clickable like this
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout, true, 'UTF-8', false);
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set margins
$pdf->SetMargins(0, 0, 0);
$pdf->SetXY(0, 0);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(1);
// add a page
$pdf->AddPage();
$fullPath = "$path".'qr-code/'."$uniqname".'.svg';
// Paste SVG onto page
$pdf->ImageSVG($file=$fullPath, $x=0, $y=0, $w='', $h='', $link=$query, $align='', $palign='', $border=0, $fitonpage=true);
/* Save as File */
$pdf->Output($path.'temp/'.$uniqname.'.pdf', 'F');
I then turn this PDF into a fully black CMYK PDF using Ghostscript
$targetFile = $path.'temp/'.$uniqname.'.pdf';
$iccFile = $this->params->get('ICC_FILE');
$process = new Process(['gs', '-o', $path.'pdf/'.$uniqname.'.pdf', '-sDEVICE=pdfwrite', '-sColorConversionStrategy=Gray', '-dProcessColorModel=/DeviceGray', '-dCompatibilityLevel=1.4', '-dOverrideICC=true', "-sDefaultCMYKProfile=$iccFile", $targetFile]);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
And at the end I merge this PDF with another containing a Logo using FDPI like so
// create second PDF document for pasting logo
$pdf = new \setasign\Fpdi\Tcpdf\Fpdi(PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout, true, 'UTF-8', false);
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set margins
$pdf->SetMargins(0, 0, 0);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(1);
// add a page
$pdf->AddPage();
/* Import fullHeight page */
$pages = $pdf->setSourceFile( $path.'pdf/'.$uniqname.'.pdf', 'F' );
$page = $pdf->ImportPage( 1 );
$pdf->useTemplate( $page, 0, 0 );
if($logoselect == 'eng')
{
$logos = $pdf->setSourceFile( $path.'img/engadin_online_CMYK.pdf', 'F' );
$logo = $pdf->ImportPage( 1 );
$pdf->useTemplate( $logo, 34.25, 33.75, null, 32.5);
}
if($logoselect == 'gam')
{
$logos = $pdf->setSourceFile( $path.'img/gammetermedia_CMYK.pdf', 'F' );
$logo = $pdf->ImportPage( 1 );
$pdf->useTemplate( $logo, 34.25, 33.75, null, 32.5);
}
// Close and output PDF document
$base = $pdf->Output('qrcode.pdf', 'E');
My problem now is that the link I created on the SVG of the first PDF is not in the last PDF anymore. Is there any way I can preserve this link so that it is still clickable in the last PDF or any other way I can achieve the same result?
As requested heres the initial pdf, the ghostscript output, and the final pdf
I am adding custom tick like below
axisX3.addCustomTick()
.setGridStrokeLength(0)
.setTextFormatter(()=> ttstr[0]+":"+ttstr[1])
.setValue(xVal);
How do I change font size / color
change border color / style
remove the rectangle around the ticks and just show the pointer in top.
I tried
.setTitleFont(f => f
.setSize(24)
)
But not working
You can edit the visual style of the created tick with customTick.setMarker() method. This method takes a mutator function as the first and only argument.
To change the font size:
const tick = axisX.addCustomTick()
.setMarker(marker => marker
.setFont(font => font
.setSize(40)
)
)
To style the border:
const tick = axisX.addCustomTick()
.setMarker(marker => marker
.setBackground(background => background
.setStrokeStyle((line) => line
.setFillStyle(style => style
.setColor(ColorHEX('#f00'))
)
)
)
)
Showing just the pointer is not possible.
See below for a snippet of styling the tick.
const {
lightningChart,
emptyLine,
ColorHEX,
} = lcjs
const chart = lightningChart().ChartXY()
const axisX = chart.getDefaultAxisX()
const tick = axisX.addCustomTick()
.setMarker(marker => marker
.setFont(font => font
.setSize(40)
)
.setBackground(background => background
.setStrokeStyle((line) => line
.setFillStyle(style => style
.setColor(ColorHEX('#f00'))
)
)
)
)
.setValue(4)
<script src="https://unpkg.com/#arction/lcjs#1.3.1/dist/lcjs.iife.js"></script>
i would like to implement the tcpdf in my wordpress project. I tried to call below example tcpdf file (it's an example from tcpdf), unfortunately its output are crazy code as below,
%PDF-1.7 %���� 8 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20180829011846+00'00') /Resources 2 0 R /MediaBox.....
I have no idea what's the problem of this, many many thanks if any guidance to me, thank you very much.
<?php
// Include the main TCPDF library (search for installation path).
require_once(dirname(__FILE__).'/tcpdf/examples/tcpdf_include.php');
ob_end_clean();
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 038');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (#file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 20);
// add a page
$pdf->AddPage();
$txt = 'Example of CID-0 CJK unembedded font.
To display extended text you must have CJK fonts installed for your PDF reader:';
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
// set font
$pdf->SetFont('cid0jp', '', 40);
$txt = 'こんにちは世界';
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_038.pdf', 'I');
?>
In the pdf output method, try 'F' as the second argument instead of 'I'.
$pdf->Output('example_038.pdf', 'F');
Im using the following code at functions.php to resize my IFRAMES
function add_youtube_size($youtubehtml) {
if (strpos($youtubehtml, "<iframe" ) !== false) {
$youtubesearch = array( 'width="460"', 'height="310"');
$youtubereplace = array( 'width="600"', 'height="338"');
$youtubehtml = str_replace($youtubesearch, $youtubereplace, $youtubehtml);
return $youtubehtml;
} else {
return $youtubehtml;
}
}
add_filter('the_content', 'add_youtube_size', 10);
But this code only edit the size of iframes with 460 x 310.
There Is any way i can change that line $youtube search = array( 'width="460"', 'height="310"'); to get any possible sizes?
Yes you can change it
$youtubesearch = array( 'width="460"', 'height="310"');
$youtubereplace = array( 'width="600"', 'height="338"');
In those lines change both width and height to what you need but it important that your search video also should available in your written width and height
When creating a Excel 5 file through PHPExcel, I am able to display the background color cell in any color but as soon as I switch to Excel 2007, the background color remains constantly black, is there any fix available to sort it out? Here's the subset of my code where the goal is to display the column header in yellow, any help would be appreciated, thanks in advance:
$styleArrayTableHeader = array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'rotation' => 90,
'startcolor' => array(
'argb' => '#ffff00', // yellow
),
'endcolor' => array(
'argb' => '#ffff00',
),),);
$objPHPExcel->setActiveSheetIndex(0);
$worksheet = $objPHPExcel->getActiveSheet();
$worksheet->getStyle('B6:K6')->applyFromArray($styleArrayTableHeader);
.....
.....
you need check fill type of cell
if ( $pStyle->getFill()->getFillType() == PHPExcel_Style_Fill::FILL_NONE ) {
$color = 'white'
} else {
$color = '#' . $pStyle->getStartColor()->getRGB()
}
Can you retry with the latest develop branch code from github - there's at least one fix in there for the fill styling in Excel 2007...
Also you're using trying to set argb with rgb values. Either use argb values, or set rgb instead