0

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';
        }
alphy
  • 931
  • 4
  • 13
  • 23
  • 1
    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 Apr 18 '13 at 08:12
  • 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 Apr 18 '13 at 10:04

2 Answers2

0

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

Community
  • 1
  • 1
Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103
  • Thank you raheel shan, but i am exporting from php $_POST values for input fields on the html forms – alphy Apr 18 '13 at 09:06
-1

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();

//}
?>
Atanu
  • 77
  • 6
  • -1 - I doubt if this code does what the OP wants... he's reading an xlsx file, modifying it and saving it. Your code only writes a basic xls file - different file format, no reading, no styles or Excel features (such as the image that is causing the problem) – Mark Baker Apr 18 '13 at 08:11
  • My system its working absolutely fine when i am exporting.Its reading accurately with formatting.same as OP wants to export. – Atanu Apr 18 '13 at 08:16
  • You haven't shown any code to read the OP's original spreadsheet file at all; you're writing a file in a different format to that of the original poster (you're writing an xls file, OP is writing an xlsx file); your code makes no allowance for the fact that the OP's file contains images.... your system doesn't do what the OP wants – Mark Baker Apr 18 '13 at 08:19
  • Hello Mark, I applaud your well versed knowledge on phpExcel, it seems to be giving me problems, make me understand it. This is what i am trying to do. I have a workbook, the workbook can have a lot of sheets. The data exported is from html page (several inputs). What i want is that when i click my export button for the first time, data is exported to sheet at index 0, when i click export again on the same page, a new sheet is created and data is exported at the sheet at index 1, the next time a sheet at index 2 and so on, i have tried creatSheet method but my file keeps going missing. Thanks – alphy Apr 18 '13 at 08:55
  • @alphy - Start by narrowing down the problem with some basic debugging: are you getting an error during the file load, during the calls to set cell values, or during the save? – Mark Baker Apr 18 '13 at 10:52