phpexcel not reading sheet correctly - php

I am using phpexcel 1.8 to read a .xlsx file with 92 rows. But I am getting only one row as the result. Then I opened the file & made some edits using libre office & then I tried to save the file & an option came up "Use Microsoft Excel 2007/2010/2013 XML Format" & I clicked on it & saved the file.
Then onwards I am getting correct results from reading the file using phpexcel. What could be wrong ? Any help would be appreciated.
Code I used is:
$inputFileName = 'test.xlsx';
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch (Exception $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}
$highRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
$highColumn = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
Thanks in advance!

Related

PHP: sort ZIP in alphabetical order

The following PHP file creates a ZIP File and works as it should.
<?php
$zip = new ZipArchive();
$ZIP_name = "./path/Prefix_" .$date . ".zip";
if ($zip->open($ZIP_name, ZipArchive::CREATE)!==TRUE) {
exit("There is a ZIP Error");
}
if ($zip->open($ZIP_name, ZipArchive::CREATE)==TRUE) {
echo "ZIP File can be created" . "<br>";
}
foreach($list as $element) {
$path_and_filename = "../path_to_somewhere/product_"
. $element
. ".csv";
$zip->addFile($path_and_filename, basename($path_and_filename));
}
echo "numfiles: " . $zip->numFiles . "\n"; // number of element files
echo "status:" . $zip->status . "\n"; // Status "0" = okay
$zip->close();
?>
There is only a small blemish:
The above foreach-loop retrieves elements from an array where all elements are sorted in alphabetical order. After the ZIP-File creation, the files within the ZIP are in different order, maybe caused by different file size.
Is there a way to sort the csv files within the ZIP with PHP later on? I'm new to ZIP creation with PHP an I have not found something helpful in the documentation.
You can't do that, better just sort the file list in your program, not in the file system (-;

mPDF not generating PDF in firefox

I am using mPDF library for creating PDF using html data.it works fine in google chrome,but in firefox it displays nothing.No files downloaded and no errors in console.
Here is my code :
require_once( $destination_path."/mpdf/mpdf.php");
$target_path = $destination_path . '/uploads/reports/';
$htmlData='<span>Sample Html Content</span>';
try {
$pdf= new mPDF();
$pdf->debug = true;
$pdf->SetFooter("MyApp" . '|{PAGENO}|' . date(DATE_RFC822));
$pdf->WriteHTML($htmlData);
$pdf->Output($fileOutputPath, 'F');
}catch (Exception $e) {
echo 'Caught exception: ', $e, "\n";
}
i am tried ob_clean() and headers for solve the issue,but it remains same .
Anyone knows how to solve this issue?

Issue with mpdf while attachment

$html = $this->load->view('pdf_output_order_details', $pdf, true);
$pdfFilePath = $pdf['data'][0]->first_name . "_" . $pdf['data'][0]->last_name . ".pdf";
ini_set('error_reporting', E_STRICT);
$this->pdf = $this->m_pdf->load('A4-L');
$this->pdf->WriteHTML($html);
$this->pdf->Output($pdfFilePath, "F");
While the pdf file is creating successfully if i change to "F" to "D"
But when attchment comes into picture then it throws an error....
"mPDF error: Unable to create output file: abc.pdf"....
I have set all permission to mpdf lib folder and n number of things done but still it won't work.... Please help guys....
Thank You....
I think your $pdfFilepath should containg not only filename, but filepath too.
From mPdf documentation:
F: save to a local file with the name given by filename (may include a
path).
Try this
$pdfFilePath = $_SERVER['DOCUMENT_ROOT'] . '/files/' . $pdf['data'][0]->first_name . "_" . $pdf['data'][0]->last_name . ".pdf";
Of course make sure you have write access to the files folder.

Retrieve original uploaded filename using php on OpenShift

I would like to check that a file uploaded to my OpenShift app has a text extension (.txt or .tab). Following some advice given here I wrote the following code, with echoes added to help debug:
$AllowedExts = array('txt','tab');
echo "AllowedExts: " . $AllowedExts[0] . " and " . $AllowedExts[1] . "<br>";
$ThisPath = $_FILES['uploadedfile']['tmp_name'];
echo "ThisPath: " . $ThisPath . "<br>";
$ThisExt = pathinfo($ThisPath, PATHINFO_EXTENSION);
echo "ThisExt: " . $ThisExt . "<br>";
if(!in_array($ThisExt,$AllowedExts) ) {
$error = 'Uploaded file must end in .txt or .tab';
}
echo "error echo: " . $error . "<br>";
On uploading any file, the echoed response was:
AllowedExts: txt and tab
ThisPath: /var/lib/openshift/************/php/tmp/phpSmk2Ew
ThisExt:
error echo: Uploaded file must end in .txt or .tab
Does this mean that OpenShift is renaming the file upon upload? How do I get the original filename and then check its suffix? More generally, is there a better way to check the file type?
$_FILES['uploadedfile']['tmp_name'] contains the name of a temporary file on the server (which can be moved with move_uploaded_file()). If you want to check the original name of the uploaded file on the client machine use $_FILES['uploadedfile']['name'].
That's not an Open Shift issue, it's the standard way of PHP.
For further details see http://php.net/manual/en/features.file-upload.post-method.php
For other ways to detect the file type see http://php.net/manual/en/ref.fileinfo.php

MPDF - fseek error

I am trying to merge files together into one pdf. The files could be pdf, png or jpg files. Images work fine, its only when I try to export the pdf files that I get an error. The error is show below.
Message: fseek(): stream does not support seeking
I thought I found a solution from various forums relating to the path of the file. However, if I change the path it shows this error
mPDF error: Cannot open http://192.168.2.35/marine/certificate_files/a025ad3d40b22ac760ba7af7b6bb259d.pdf
My controller code is below
include('mpdf/mpdf.php');
$mpdf=new mPDF();
$mpdf->SetImportUse();
$mpdf->SetFooter($personnel_data->firstname . ' ' . $personnel_data->lastname . '|{PAGENO}|' . $personnel_data->ID_number );
foreach($certificate_data as $certificates)
{
$certificate_extension['type'] = explode('.',$certificates->certificate_name);
if($certificate_extension['type'][1]==='pdf')
{
$pagecount = #$mpdf->SetSourceFile('http://192.168.2.35/marine/certificate_files/' . $certificates->certificate_name);
$tplId = $mpdf->ImportPage($pagecount);
$mpdf->UseTemplate($tplId);
$mpdf->WriteHTML('<pagebreak>');
}
if($certificate_extension['type'][1]!=='pdf')
{
$mpdf->WriteHTML('<p><img src="' . $this->config->base_url('assets/images/header-logo.png') . ' "></p>');
$mpdf->WriteHTML('<style>body {font-family: arial;}</style>');
$mpdf->WriteHTML('<p> ' . $certificates->certificate . ' - ' . $certificates->expiry_dates . '</p>');
$mpdf->WriteHTML('<p><img src="' . $this->config->base_url('certificate_files/' . $certificates->certificate_name) . ' "></p>');
$mpdf->WriteHTML('<pagebreak>');
}
else
{
$mpdf->WriteHTML('');
}
}
$mpdf->Output();
exit;
If any help or guidance could slide my way form anyone I would be forever grateful! Thanks!
as far as i know mpdf is based on fpdf (fpdi)... from the FPDI website: http://www.setasign.de/products/pdf-php-solutions/fpdi-pdf-parser/
By default FPDI can "only" handle PDF documents up to PDF version 1.4.
Beginning with PDF version 1.5 there were new compression features
introduced which involve internal structure changes how a PDF document
can be created.
Please try it with an PDF Version <= 1.4 for testing...
in my case it was the reason and I bought a developer license for the commercial pfdi pdf parser for 100€

Categories