require_once not possible?

marcusx 30 Dec, 2008
Hi everyone!

Is it not possible to use require once inside a form?

I have the following code:

<?php

echo "beginn test";

echo JPATH_SITE;

require_once(JPATH_SITE."/libraries/SpreadsheetExcelWriter/writer.php");

echo "required loaded";

?>


But I get only the beginn test and the path on a blank page. The require_once doesn't work. I get no error message in the debug modus. How can I figure out what the problem is?

By the way, the Spreadsheet Excel Writer is for exporting real xls Files and I used it before with breezing forms and it worked quite well. So the library shouldn't be the reason.

Have all a happy new year.
regards
marcus
GreyHead 30 Dec, 2008
Hi Marcus,

Happy New Year to you too.

The path doesn't look right to me. Try
require_once JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_chronocontact'.DS.'excelwriter'.DS.'Writer.php';
that works for me. Or possibly
require_once JPATH_COMPONENT_ADMINISTRATOR.DS.'excelwriter'.DS.'Writer.php';


Bob
marcusx 30 Dec, 2008
Hi Bob!

Great! It works - I didn't know that the writer is already coming with your package. Hopefully it will also work with creating a xls file and send it to me. I will try this out later.

And even greater that you are online today. :-)

cu
marcus
GreyHead 30 Dec, 2008
Hi Marcus,

Yes it works fine - You can export a table using the icon in the Forms Manager.

Bob
marcusx 30 Dec, 2008
I don't get it working writing an file. :-( Any ideas?

<?php

echo "beginn test<br />";

echo JPATH_SITE;

require_once JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_chronocontact'.DS.'excelwriter'.DS.'Writer.php';

echo "<br />required loaded<br />";


// open/create the xls filename

$filename = JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_chronocontact'.DS.'excelwriter'.DS.'export'.DS.'export123.xls';


echo $filename;
echo "<br />";


// We give the path to our file here
$workbook = new Spreadsheet_Excel_Writer($filename);

$worksheet =& $workbook->addWorksheet('My first worksheet');

$worksheet->write(0, 0, 'Name');
$worksheet->write(0, 1, 'Age');
$worksheet->write(1, 0, 'John Smith');
$worksheet->write(1, 1, 30);
$worksheet->write(2, 0, 'Johann Schmidt');
$worksheet->write(2, 1, 31);
$worksheet->write(3, 0, 'Juan Herrera');
$worksheet->write(3, 1, 32);

// We still need to explicitly close the workbook
$workbook->close();




echo "<br />File closed";


?>
GreyHead 30 Dec, 2008
Hi Marcus,

Try this version
<?php
// echo "beginn test<br />";
//echo JPATH_SITE;
require_once JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_chronocontact'.DS.'excelwriter'.DS.'Writer.php';
// echo "<br />required loaded<br />";
// open/create the xls filename

$filename = JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_chronocontact'.DS.'excelwriter'.DS.'export'.DS.'export123.xls';
// echo $filename."<br />";

// We give the path to our file here
$workbook =& new Spreadsheet_Excel_Writer();
$workbook->send('my_excel_file.xls');
$worksheet =& $workbook->addWorksheet('My first worksheet');
$worksheet->writeString(0, 0, 'Name');
$worksheet->writeString(0, 1, 'Age');
$worksheet->writeString(1, 0, 'John Smith');
$worksheet->writeNumber(1, 1, 30);
$worksheet->writeString(2, 0, 'Johann Schmidt');
$worksheet->writeNumber(2, 1, 31);
$worksheet->writeString(3, 0, 'Juan Herrera');
$worksheet->writeNumber(3, 1, 32);
// We still need to explicitly close the workbook
$workbook->close();
//echo "<br />File closed";
?>
I added the $workbook->send('my_excel_file.xls'); line and fixed a few buglets. Note that any echo'd code or error reports will appear in the spreadsheet and mess up the layout!

Bob
This topic is locked and no more replies can be posted.