unable to write data using phpexcel - phpexcel

$filepath = longdata.xlsx;
#mkdir($filepath, 0777, true);
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($filepath);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue("C4", "12345");
Above is the code I have written in codeigniter. I am trying to write data to a blank xlsx file but unable to do so. When I try to read data I am able to do it which means phpexcel is working fine. Any help is greatly appreciated.

Forgot to add the line
$objWriter->save($filepath);
Now the code is working fine.

Related

Dompdf stream just downloads without dialog prompt

I am using Dompdf in my Symfony 3 project and it's all working fine up until the point where I'm trying to get it to download. At the moment, it just downloads without a dialog prompt which is what I want, and according to the documentation, passing a value of 1 to the Attachment option should do this.
Here is my code:
$html = $this->renderView('pages/invoice_print.html.twig', array(
'invoice' => $invoice_array
));
$dompdf = new Dompdf();
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$output = $dompdf->output();
$dompdf->stream("invoice_" . $invoice->getId(), array('Attachment' => 1));
To be honest, I was under the impression that Attachment was set to 1 by default - so I'm not sure what's going on. I'm using Firefox Quantum.
EDIT:
A screenshot of how the PDF will render in the browser is now attached:
I haven't worked with dompdf in the past, but, just by glancing the code on Github, I believe I see what you need.
When you invoke stream(), you have:
if (!isset($options["compress"])) $options["compress"] = true;
if (!isset($options["Attachment"])) $options["Attachment"] = true;
So, if no Attachment option is present, the option will be set to true
Next, on line 1311, you have:
$attachment = $options["Attachment"] ? "attachment" : "inline";
header(Helpers::buildContentDispositionHeader($attachment, $filename));
which basically boils down to a Content-Disposition header:
$contentDisposition = "Content-Disposition: $dispositionType; filename=\"$fallbackfilename\"";
Finally, according to the standard, if you want to serve a file inside webpage (e.g. no prompt dialog), you need to set disposition to inline
All being said, have you tried setting Attachment to false?
$dompdf->stream("invoice_" . $invoice->getId(), array('Attachment' => false));
Hope this helps...

searchable file content wordpress

I am building a wordpress site and I have many files I need to upload and these files need the content to be searchable for users. Right now they are in pdf format. (format does not matter as long as these files can not be altered)
example: If the user types in a keyword or phrase the file content will be searched and return the file to the user that the keyword matched.
I searched for solutions and came up empty, maybe someone can point me in the right direction.
Its preety simple, you just have to install pdftotext (here is a good tutorial) and then you can search for any text. So if you a have a list of all your documents in an array you can loop and search for a certain string.
I have not tested this code, but i guess it should work fine.
<?php
$files = array('relative-link-to-file1', 'relative-link-to-file2', 'file3');
$text_to_search = 'test';
$found = array();
foreach($files as $file){
$content = shell_exec('/usr/local/bin/pdftotext '.$file.' -');
$found[]['position'] = strpos($content, $text_to_search );
$found[]['file'] = $file;
}
// To echo all the found instances.
foreach($found as $file){
echo 'The text has been found at position '.$file['position'].' within the file '.$file['file'];
}
?>

phpexcel not maintaining charts in read/rewritten spreadsheet

I'm trying to use PHPExcel to produce spreadsheets with charts based on "templates" that non-coders have created and formatted, but with data for the charts injected by my code. I've created a "template" spreadsheet including a chart which is looking at the appropriate data range, so I want to read it in, set cell values (which are the data range for the chart), then write it out again.
In the output that PHPExcel produces, the injection of the data has worked, but the chart is missing. It's Excel2007 (not guessing, i'm getting it to identify) and I'm doing a setIncludeCharts(true) on both the reader and the writer.
Any ideas? (other than getting PHPExcel to create the chart. I can't really do that because I need non programmers to be able to create the templates that my code just puts data into based on them providing the cell reference where the data insert should start).
Many Thanks
Code (that works other than charts disappearing in output):
// Identify the filetype (it returns 'Excel2007')
$filetype = PHPExcel_IOFactory::identify("template.xlsx");
// Create the reader and load the file
$objReader = PHPExcel_IOFactory::createReader($filetype);
$objReader->setIncludeCharts(true);
$objPHPExcel = $objReader->load("template.xlsx");
// Inject the data
$objPHPExcel->setActiveSheetIndex(1)->setCellValue('A3', 'Category 1');
$objPHPExcel->setActiveSheetIndex(1)->setCellValue('B3', '10');
$objPHPExcel->setActiveSheetIndex(1)->setCellValue('A4', 'Category 2');
$objPHPExcel->setActiveSheetIndex(1)->setCellValue('B4', '20');
$objPHPExcel->setActiveSheetIndex(1)->setCellValue('A5', 'Category 3');
$objPHPExcel->setActiveSheetIndex(1)->setCellValue('B5', '30');
// Output headers
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . time() . '.xlsx"');
header('Cache-Control: max-age=0');
// Prepare PCLZIP
define( 'PCLZIP_TEMPORARY_DIR', '/tmp/' );
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
// Create writer and spit file out to browser
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $filetype);
$objWriter->setIncludeCharts(true);
$objWriter->save('php://output');

simplexml_load_file not working to read rss feed at www.thetechjournal.com

When I try to read the rss feed at www.thetechjournal.com I get nothing. They use wordpress to generate the rss, so I assume it has something to do with that.
<?php
$url = 'http://feeds.thetechjournal.com/TheTechJournal';
$rss = simplexml_load_file($url);
print_r($rss);
?>
UPDATE: The offending XML is attached as an image.
Their feed has errors. Check it with this:
$url = 'http://feeds.thetechjournal.com/TheTechJournal';
libxml_use_internal_errors(true);
$sxe = simplexml_load_string($url);
if ($sxe === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
print_r($rss);
I am from TTJ team. When I do run this Validator it shows fine, but as we have some iFrame is marks those issue. And sometime if some post have any weird char that what makes it invalid. Please point out to me any exact issue that we could look into. I do appreciate your concern.
http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Ffeeds.thetechjournal.com%2FTheTechJournal

phpexcel File does not exist

I am trying to read a xlsx document with PHPExcel. My document is in my local and my code shows me this error.
*
Could not open MunicipioPreinscripcion.xlsx for reading! File does not
exist.
*
This is my code (My excel document is my current directory with my controller)
#namespace Backend\AlumnosBundle\Controller
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
$inputFileName = 'MunicipioPreinscripcion.xlsx';
$inputFileNameWithPath = PHPEXCEL_ROOT.$inputFileName;
if(file_exists($inputFileNameWithPath)) {
echo 'exist'; //Allways show exist
echo $inputFileNameWithPath."<br>";
} else {
echo 'dont exist';
}
/** Identify the type of $inputFileName **/
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
/** Create a new Reader of the type that has been identified **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Advise the Reader that we only want to load cell data **/
$objReader->setReadDataOnly(true);
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load($inputFileName); //This is where throw the error
What i am doing wrong?
How can i show the directory where load() method is looking for files? I'm lost
Thanks in advance
SOLVED: I think it didnĀ“t load for permission in this directory (mybundle/controller). I have moved the xlsx file to web/upload directory and this work correctly.
$objPHPExcel = $this->get('xls.load_xls2007')->load($this->get('kernel')->getRootDir() .'/../web/upload/MunicipioPreinscripcion.xlsx');

Resources