Professional Documents
Culture Documents
ChronoForms Excel Export Extras
ChronoForms Excel Export Extras
net
CHRONO
Forms
Greyhead.net
Greyhead.net
ChronoForms makes hand coding fairly simple and straightforward. But
it does require a fair knowledge of PHP and of the Joomla! code base. It
really isnt suitable for beginners to PHP.
where each of the 'xxx' values needs to be replaced with the appropriate value for the second database.
Greyhead.net
Connecting to a Microsoft Access database
It is possible to use an OBDC connection to link MySQL and Microsoft
Access databases. See, for example, the article from University College
London at http://www.ucl.ac.uk/is/mysql/access/
Greyhead.net
$path = JPATH_BASE.DS.'components'.DS.'com_chronocontact'.DS.'uploads'.DS.'temp'.DS;
$file = "Report.xls";
$file_url = JURI::base().'components/com_chronocontact/uploads/temp/'.$file;
$xls = & new Spreadsheet_Excel_Writer($path.$file);
$xls->setVersion(8);
$format = & $xls->addFormat();
$format->setBold();
$format->setColor("blue");
$sheet = & $xls->addWorksheet('Report at '.date("m-d-Y"));
// write the column headers
$titcol = 0;
foreach ( $table_fields as $table_field ) {
$sheet->writeString(0, $titcol, $table_field, $format);
$titcol ++;
}
$db =& JFactory::getDBO();
$datacol = 0;
$rowcount = 1;
// get the number of records to be processed
$query = "
SELECT COUNT(*)
FROM `#__table_name`
";
$db->setQuery($query);
$count = $db->loadResult();
// the value of $count tells us the total number of records
Greyhead.net
$ceil = ceil($count/1000) - 1;
// create a loop to work in chunks of 1000 records
for ( $k = 0; $k <= $ceil; $k++ ) {
$limitstart = $k*1000;
// get a block of 1000 records
$sql = "
SELECT *
FROM `#__table_name`
LIMIT $limitstart, 1000 ;
";
$db->setQuery($sql);
$datarows = $db->loadObjectList();
$result_array = array();
$i = $k*1000;
foreach ( $datarows as $row ) {
// do any pre-processing of the data here
// putting the required results into $result_array
// write the column entries for this record
foreach ( $table_fields as $table_field ) {
$sheet->writeString($rowcount, $datacol,
$result_array[$table_field], 0);
$datacol ++;
}
$i++;
$datacol = 0;
$rowcount ++;
Greyhead.net
} // loop to the next record
} // loop to the next block of 1000 records
// close the Excel file
$xls->close();
// show the user a link to download the file
echo "<a href='".$file_url."' >
Your file is ready to download</a>";
?>
Bob Janes
24 August 2010
Greyhead.net
Bob Janes is the author of the ChronoForms 1.3 for Joomla!! site Cookbook
published by Packt Publishing. He provides support on the ChronoEngine
forums and works as a developer of custom applications (often using ChronoForms and ChronoConnectivity) for Joomla!! and WordPress.
Bob can be contacted at info@greyhead.net
ChronoConnectivity is a Joomla!! Component that works with ChronoForms
to allow the easy display of lists of records from a database table. ChronoConnectivity and ChronoForms are published by ChronoEngine.com.
This help-sheet was written for ChronoConnectivity 2.0 RC3
ChronoEngine Tutorials by Bob Janes are licensed under a
Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
Disclaimer
To the best of our knowledge and belief the information in this tutorial was
substantially correct at the time of writing. Neither the author, nor ChronoEngine.com shall have neither liability nor responsibility in respect of any loss or
damage caused, or alleged to have been caused, directly or indirectly, by the
information contained in this document.