Re: PHP and Crystal Reports

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/4/30 John Messam <johnmess@xxxxxxxxxxx>:
>
> I am trying to write a php program that opens a number of reports written in Crystal 11. From research on the internet, I found that CR would have to be called using COM.  So I did that. From the command line it triggers a dialog box saying that the version of Crystal the reports was written in was later than the one that is being used to open it via the php program.   The other problem is that when it is run from the browser the program hangs on the openReport command
>
>
>
> Can anyone assist me on resolving the hanging issue or the entire thing for that matter.
>
>
>
> Thanks!
>
>
>
> John
>
> _________________________________________________________________
> Show them the way! Add maps and directions to your party invites.
> http://www.microsoft.com/windows/windowslive/products/events.aspx

I use Crystal all day and via PHP also.

Here is the code I use (edited). It might not be perfect, but it works
perfectly.

<?php
// Create an Crystal Object Factory.
$o_CrObjectFactory = new COM('CrystalReports11.ObjectFactory.1');

// Create the Crystal Reports Runtime Application.
$o_CrApplication =
$o_CrObjectFactory->CreateObject("CrystalRunTime.Application.11");

// Register the typelibrary.
com_load_typelib('CrystalDesignRunTime.Application');

// Load the report.
$o_CrReport = $o_CrApplication->OpenReport('C:\Report.rpt', 1); // 1
== crOpenReportByTempCopy.

// Logon to the database.
$o_CrReport->Database->LogOnServer
	(
	'odbc',
	'Accounts',
	registryDatabaseLocations::Database('Accounts'),
	registryDatabaseLocations::Username('Accounts'),
	registryDatabaseLocations::Password('Accounts')
	);

// Don't tell anyone what is going on when running live.
$o_CrReport->DisplayProgressDialog = False;

$s_ExportedReport = 'C:\Report.pdf';

// Run the report and save the PDF to disk.
$o_CrReport->ExportOptions->DiskFileName = $s_ExportedReport;
$o_CrReport->ExportOptions->PDFExportAllPages = True;
$o_CrReport->ExportOptions->DestinationType = 1; // Export to File
$o_CrReport->ExportOptions->FormatType = 31; // 31 = PDF, 36 = XLS, 14 = DOC

// Assign the parameters to the report.
$m_Stuff = new Variant();

$o_CrPeriodsParam =
$o_CrReport->ParameterFields->GetItemByName('PeriodIDs', $m_Stuff);
$o_CrPeriodsParam->ClearCurrentValueAndRange();

foreach($_SESSION['tabRG_PeriodIDs'] as $i_Period)
	{
	$o_CrPeriodsParam->AddCurrentValue(intval($i_Period));
	}

$o_CrReport->ReadRecords();
$o_CrReport->Export(False);
?>



-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux