PDF='MAIN' { ATTRIBUTES='*' { PLATFORM='php.txt'; REPTYPE='1'; OBJECTNAME='phptoexcelv2.php'; LIBLOBJ='*FILES'; TITLE='Example 150 - Convert table to XLS with PHP'; WEBPATH='http://esdi.excelsystems.com/wsexmp/'; TARGETPATH='/www/zendcore/htdocs/wsphp/'; FTPSITE='2'; SET='46'; VERSION='4.00'; CRTBNUM='Revision 3506'; CRTTEMPLT='C:\\Program Files\\ESDI\\WebSmart\\Templates v7.0\\PHP Templates\\iSeries SQL\\Idaho\\Record Listing.tpl'; SAVBNUM='Revision 3910'; REPSYSTEM='ESDI_WEBDEMO'; LASTLOC='0'; VHTML='N'; LASTSAVE='10/28/2008 10:28:28'; ATTACHED='0'; PROJECT='36'; OBJLIBRARY='XL_WEBEXMP'; SOURCELIBR='XL_WEBEXMP'; SOURCEFILE='QRPGLESRC'; } FTPREFINFO='*' { URL='192.168.0.100'; INITIALDIR='/www/zendcore/htdocs/examples/'; FTPPORT='21'; PASSIVEMODE='1'; WEBPATH='http://esdi.excelsystems.com/wsexmp/'; } FILES='*' { FILE='MU_ORDDF' { LIBRARY='XL_WEBDEMO'; ALIAS=''; RCDFORMAT='RORDERD '; LEVELID='1071025172820'; RFLEVELID='4A9C7B0FDB041'; EXTDS='0'; } } PANELS='*' { PANEL='ListHeader' { DESC='Page header'; DETAILS=' Example 150 - Convert table to XLS with PHP
Example 150 - Convert table to XLS with PHP
Specify the spreadsheet file name:  
Specify the worksheet title (optional):  
(version 2003 or higher)
'; } PANEL='ListDetails' { DESC='Page body'; ITERATIONS='10'; DETAILS=' '; } PANEL='ListFooter' { DESC='Page footer'; DETAILS='
Order Number Inventory Item Code Order Quantity Unit Price
$ODORD $ODITEM $ODQTY $ODPRIC
'; } PANEL='xlsHeader' { DESC=''; DETAILS=' 7560 12300 360 135 False False Order # Item # Order Quantity Price Price With Tax '; } PANEL='xlsDetail' { DESC=''; DETAILS=' $ODORD $ODITEM $ODQTY $ODPRIC '; } PANEL='xlsFooter' { DESC=''; DETAILS='
False False
'; } } PREVIEWS='*' { PREVIEW='Main List' { SEG='ListHeader'; SEG='ListDetails' { REPEAT='10'; } SEG='ListFooter'; } } ACTIONS=' // Program Name: phptoexcelv2.php // Program Title: Example 150 - Convert table to XLS with PHP // Created by: FENRIR // Template family: Idaho // Template name: List All Records in File // Purpose: // Program Modifications: // DB Connection code require(\'/esdi/websmart/v7.0/include/xl_functions001.php\'); $options = array(\'i5_naming\' => DB2_I5_NAMING_ON); global $db2conn; $db2conn = xl_db2_connect($options); if(!$db2conn) { die(\'Failed to connect to database!\'); } // Check the cookie if(isset($_COOKIE[\'wsnumbc\'])) { $wsnum = $_COOKIE[\'wsnumbc\']; } else { setcookie(\'wsnumbc\', $wsnum); } // Global variable for calculated fields // Global variables should be defined here global $title; global $authName; global $fileName; global $rowCount; // As a default task for this program, execute the display function if ($pf_task == \'default\') display(); if ($pf_task == \'toexcel\') toExcel(); // close the database connection db2_close($db2conn); /******************** End of mainline code ********************/ function display() { // Make all global variables available here foreach($GLOBALS as $arraykey=>$arrayvalue) { global $$arraykey; } $query = \'select ODORD, ODITEM, ODQTY, ODPRIC from XL_WEBDEMO/MU_ORDDF where ODORD = 100026\'; // Fetch rows for page: relative to initial cursor if (!($stmt = db2_exec($db2conn, $query))) { // close the database connection db2_close($db2conn); die("Error ".db2_stmt_error() .":".db2_stmt_errormsg(). ""); } // Output header wrtseg("ListHeader"); while ($row = db2_fetch_assoc($stmt)) { // set color of the line xl_set_row_color(\'altcol1\', \'altcol2\'); $ODORD = $row[\'ODORD\']; $ODITEM = $row[\'ODITEM\']; $ODQTY = $row[\'ODQTY\']; $ODPRIC = $row[\'ODPRIC\']; wrtseg("ListDetails"); } wrtseg("ListFooter"); } function toExcel() { // Make all global variables available here foreach($GLOBALS as $arraykey=>$arrayvalue) { global $$arraykey; } $query = \'select ODORD, ODITEM, ODQTY, ODPRIC from XL_WEBDEMO/MU_ORDDF where ODORD = 100026\'; // Fetch rows for page: relative to initial cursor if (!($stmt = db2_exec($db2conn, $query))) { echo "Error ".db2_stmt_error() .":".db2_stmt_errormsg(). ""; die; } // Output header wrtHeader(); $rowCount = 0; while ($row = db2_fetch_assoc($stmt)) { $ODORD = $row[\'ODORD\']; $ODITEM = $row[\'ODITEM\']; $ODQTY = $row[\'ODQTY\']; $ODPRIC = $row[\'ODPRIC\']; $rowCount++; // Output details wrtseg("xlsDetail"); } // Output footer wrtseg("xlsFooter"); } function wrtHeader() { // Make all global variables available here foreach($GLOBALS as $arraykey=>$arrayvalue) { if($arraykey[0]!=\'_\' && $arraykey != \'GLOBALS\') global $$arraykey; } // Set worksheet title if(isset($_REQUEST[\'xlsTitle\'])) { $title = htmlspecialchars($_REQUEST[\'xlsTitle\']); } else { $title = "Worksheet 1"; } // strip out special chars first $title = preg_replace ("/[\\\\\\|:|\\/|\\?|\\*|\\[|\\]]/", "", $title); // Substring it to the allowed length $title = substr ($title, 0, 31); // Set author name $authName = "Author\'s Name"; // Strip out special characters $authName = preg_replace ("/[\\\\\\|:|\\/|\\?|\\*|\\[|\\]]/", "", $authName); // Set XLS file name if(isset($_REQUEST[\'xlsName\'])) { $fileName = htmlspecialchars($_REQUEST[\'xlsName\']); } else { $fileName = "Excel1"; } // Set content headers header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); header("Content-Disposition: inline; filename=\\"" . $fileName . ".xls\\""); header("Cache-Control: private"); // Output Header XML wrtseg("xlsHeader"); }'; }