Note Submitter: tob_filt at hotmail dot com
----
This snippet loads a Crystal Report file, assigns the content of the variable 'dateCT' to an empty formula field in the said report and outputs everything in a PDF... took me forever to find how to do it so I figured I'd share.
$COM_Object = "CrystalRunTime.Application.10";
$my_report = getcwd() . "\\rapports\\report.rpt";
$my_pdf = getcwd() . "\\rapports\\test.pdf";
$crapp= New COM($COM_Object) or die("Unable to Create Object");
//$test = New COM("CrystalDecisions.CrystalReports.Engine");
try
{
$creport = $crapp->OpenReport($my_report, 1);
$creport->DiscardSavedData;
if (!empty($_POST['dateCT']))
{
if (!$estPremier)
{
$formuleSelection .= " AND ";
}
$formuleSelection .= "(";
$formuleSelection .= "{tblcartetempsmain.Date} >= #" . formaterDate($_POST['dateCT']) . "# ";
$formuleSelection .= ")";
$estPremier = false;
//Don't forget the damn single brackets to wrap the
//string!!!
$creport->FormulaFields->GetItemByName('txtDateDebut')->Text = "'" . $_POST['dateCT'] . "'";
}
$creport->RecordSelectionFormula = $formuleSelection;
$creport->ReadRecords();
$creport->ExportOptions->DiskFileName=$my_pdf;
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1; // Export to File
$creport->ExportOptions->FormatType=31; // Type: PDF
$creport->Export(false);
header("Location: rapports/test.pdf");
}
catch (com_exception $error)
{
echo $error->getMessage();
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.