2012-08-08 123 views
0

我在将日期参数传递给Windows上的PHP5的Crystal Reports 11组件时遇到很大麻烦。它应该是很容易的,当然,但各注释掉的项目似乎并不工作:从PHP到Crystal Report的传递日期参数

<?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%\">" 



?> 

和messege:

Fatal error: Uncaught exception 'com_exception' with message 'Source:
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

+0

嘿,刚刚在回答你的PM之后发现了这个。 +1 :)(你可能希望超链接SitePoint线程来展示你所做的研究,并且说那些东西对你来说不起作用。) – halfer 2012-08-08 10:23:31

+0

我没有一个解决方案,已经发布。但是,对于它的价值,你传递的数据是** second **参数,对吗?请记住,第一个参数可能是'$ creport-> ParameterFields(0)' – halfer 2012-08-09 08:30:09

+0

(正如我在回答中所讨论的,我已经将最新的OP编辑回来了,编辑问题以询问另一个不是一个好的方法,因为现有的答案被置于背景之外,请问一个新的问题)。 – halfer 2012-08-13 11:20:59

回答

1

我记得在这个问题上花了很长一段时间一些五年前,并最终找到一个hacky但工作的答案:

// 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"); 

这工作得很好,但它不是很优雅!我想,在Windows Server 2003上使用CR9。从here复制 - 在StackExchange :)诞生之前。

+0

OP - 您以前表示这不适合您。如果这是正确的,请向您的问题添加您使用此方法的尝试,并显示您得到的错误。 – halfer 2012-08-09 08:22:48

+0

我得到以下错误: 致命错误:未收集异常'com_exception'与消息'参数1:类型不匹配。 'in C:\ xampp \ htdocs \ cr.php:29 Stack trace:#0 C:\ xampp \ cr.php(29):com-> AddObject('rptParam',NULL,true)#1 {main} thrown在线29:C:\ xampp \ htdocs \ wincare \ laporan \ pakai.php 我应该填充$ rptParam值? – 2012-08-09 08:51:00

+0

啊,是的,'$ rptParam'没有定义 - 你应该打开警告,以便你可以看到这样的事情。我试图帮助添加一个新的部分,这主要是猜测。由于您可以在Windows/CR环境中启动VB编辑器,并使用自动完成功能来计算要使用的方法/属性,所以您处于更强大的工作状态。 – halfer 2012-08-09 19:52:51