0
votes

I am trying to export data to excel using phpexcel but it returns this error yet the specified excel file is in that location its highlighting. The thing is that excel file is in that location but once it returns that error the file is no where to be found, what have i not done correctly?

The error:

Fatal error: Uncaught exception 'Exception' with message 'File zip://workbooks/NDQA201303001/NDQA201303001.xlsx#xl/media/nqcl1.png does not exist' in C:\server\htdocs\NQCL\application\third_party\PHPExcel\Writer\Excel2007\ContentTypes.php:216

The web script code dealing with the proccess

  $objReader = PHPExcel_IOFactory::createReader('Excel2007');           

        $objPHPExcel = $objReader->load("workbooks/" . $labref . "/" . $labref . ".xlsx");
        $objPHPExcel->getActiveSheet(0)
               ->setCellValue('E22', 'Tabs/Capsule Weight')

                ->setCellValue('E23', 'No.')
                ->setCellValue('F23', 'Tabs/Capsule Weights (mg)');
$dir = "workbooks";

        if (is_dir($dir)) {

            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
            $objWriter->save("workbooks/" . $labref . "/" . $labref . ".xlsx");


            echo 'Data exported';
        } else {
            echo 'Dir does not exist';
        }
2
It's not complaining that it can't find the Excel file: it's complaining that it can't find an image that's embedded in that Excel file.... I assume this error is occurring during the load? - Mark Baker
I'm confused by the flow of your procedure. You're checking whether the directory exists before you save the file, but you're assuming that the same file already exists when you read it?! - Phill Sparks

2 Answers

0
votes

If you are using Codeigntier to export data from query to excel that is very easy. you dont need php excel for this. all the resources are available in Codeigniter.

Take a look at this answer of mine this might be helpful to you. It will export data in csv format which you can change with xlsx.

Reports in Codeigniter

-1
votes

Use the bellow code and change it as per your requirements.This works fine.

<?php
include("config.php");
$result = mysql_query("SELECT * FROM recruitment" );

function xlsBOF() { 
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);  
return; 
}
function xlsEOF() { 
echo pack("ss", 0x0A, 0x00); 
return; 
}
function xlsWriteNumber($Row, $Col, $Value) { 
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0); 
echo pack("d", $Value); 
return; 
} 
function xlsWriteLabel($Row, $Col, $Value ) { 
$L = strlen($Value); 
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); 
echo $Value; 
return; 
}
function xlsWriteString( $Row , $Col , $Value )
{
$L = strlen( $Value );
echo pack( "ssssss" , 0x204 , 8 + $L , $Row , $Col , 0x0 , $L );
echo $Value;
return;
}
// Send Header
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=export.xls ");
header("Content-Transfer-Encoding: binary ");

// XLS Data Cell
xlsBOF();
xlsWriteLabel(1,0,"Application No");
xlsWriteLabel(1,1,"Date of Application");


$xlsRow = 2;

while($row = mysql_fetch_array($result))
{
$applicationno=$row['applicationno'];
$dateofapplication=$row['dateofapplication'];

//echo $salarydetails;
xlsWriteNumber($xlsRow,0,"$applicationno");
xlsWriteNumber($xlsRow,1,"$dateofapplication");

$xlsRow++;

}

xlsEOF();
exit();

//}
?>