[英]Pass Date Parameter From PHP to Crystal Report
I am having substantial trouble passing a date parameter to the Crystal Reports 11 component from PHP5 on Windows. 我在将日期参数从Windows上的PHP5传递给Crystal Reports 11组件时遇到了很大的麻烦。 It should be easy, of course, but the various commented-out items don't seem to work:
当然,这应该很容易,但是各种注释掉的项目似乎不起作用:
<?php
$my_report = "C:\\xampp\htdocs\wincare\laporan\adm_JumlahPasienPoli.rpt"; // rpt source file
$my_pdf = "C:\\xampp\htdocs\wincare\laporan\adm_JumlahPasienPoli.pdf"; // RPT export to pdf file
//-Create new COM object-depends on your Crystal Report version
$ObjectFactory= new COM("CrystalReports115.ObjectFactory.1") or die ("Error on load"); // call COM port
$crapp = $ObjectFactory-> CreateObject("CrystalDesignRunTime.Application.11"); // create an instance for Crystal
$creport = $crapp->OpenReport($my_report,1); // call rpt report
// to refresh data before
//- Set database logon info - must have
$creport->Database->Tables(1)->SetLogOnInfo("localhost", "db_wincare", "sa", "sa");
//- field prompt or else report will hang - to get through
$creport->EnableParameterPrompting = 0;
// this is the error
$zz = $creport->ParameterFields(1)->SetCurrentValue("2011-01-01 00:00:00");
//export to PDF process
$creport->ExportOptions->DiskFileName=$my_pdf; //export to pdf
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1; // export to file
$creport->ExportOptions->FormatType=31; // PDF type
$creport->Export(false);
//------ Release the variables ------
$creport = null;
$crapp = null;
$ObjectFactory = null;
//------ Embed the report in the webpage ------
print "<embed src=\"adm_JumlahPasienPoli.pdf\" width=\"100%\" height=\"100%\">"
?>
and the messege : 和消息:
Fatal error: Uncaught exception 'com_exception' with message '
Source:
致命错误:消息“未捕获的异常'com_exception' 来源:
Description: ' in C:\\xampp\\htdocs\\wincare\\laporan\\pakai.php:36 Stack trace: #0 C:\\xampp\\htdocs\\wincare\\laporan\\pakai.php(36): variant->SetCurrentValue('2011-01-01 00:0...') #1 {main} thrown in C:\\xampp\\htdocs\\wincare\\laporan\\pakai.php on line 36
描述: '在C:\\ xampp \\ htdocs \\ wincare \\ laporan \\ pakai.php:36中堆栈跟踪:#0 C:\\ xampp \\ htdocs \\ wincare \\ laporan \\ pakai.php(36):variant-> SetCurrentValue('2011 -01-01 00:0 ...')#1 {main}在第36行的C:\\ xampp \\ htdocs \\ wincare \\ laporan \\ pakai.php中引发
I remember spending a long time on this question some five years ago, and eventually finding a hacky but working answer: 我记得大约五年前在这个问题上花了很长时间,最终找到了一个狡猾但可行的答案:
// This block is strictly guesswork
$application = new COM("CrystalRuntime.Application.9"); // Change to your version
$report = $application->OpenReport($my_report,1); // From OP's code
$rptParams = $report.ParameterFields
$rptParam = $rptParams->Item(2); // From my SitePoint post;
// obviously you need to use
// the right index
// Check that $rptParam->ValueType evaluates to 10 - if it does not
// then modify the type in Crystal Reports itself. Again, see my
// original solution
// This bit should be fine
$oScript = new COM("MSScriptControl.ScriptControl");
$oScript->Language = "VBScript";
$oScript->AllowUI = false;
$oScript->AddObject('rptParam', $rptParam, true);
$oScript->AddCode('Function SetDateParameter(strDate)
rptParam.AddCurrentValue(CDate(strDate))
End Function');
$oScript->Run("SetDateParameter", "25 April 2006");
This worked fine, but it's not very elegant! 效果很好,但不是很优雅! Worked on CR9 with Windows Server 2003, I think.
我认为,在Windows Server 2003的CR9上工作。 Copied from here - was prior to the birth of StackExchange
:)
. 从这里复制-在StackExchange
:)
诞生之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.