2012-08-08 3 views
0

Windows의 PHP5에서 Crystal Reports 11 구성 요소에 날짜 매개 변수를 전달하는 데 심각한 문제가 있습니다. 그것은 물론, 쉽게해야하지만, 다양한 주석 처리 된 항목은 작동하지 않습니다전달 날짜 매개 변수 PHP에서 Crystal 보고서

<?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

ㅎ, 오후에 응답 한 후 발견되었습니다. +1 :) (당신이해온 연구를 보여주기 위해 사이트 포인트 스레드를 하이퍼 링크로 연결하고, 그런 것들이 당신을 위해 작동하지 않는다고 말할 수 있습니다.) – halfer

+0

나는 해결책을 제쳐두고 제쳐두고 있습니다. 이미 게시했습니다. 하지만, 가치가있는 데이터는 ** 초 ** 매개 변수입니다. 맞습니까? 첫 번째 매개 변수는'$ creport-> ParameterFields (0)' – halfer

+0

일 가능성이 있습니다 (내 대답에 대한 토론에 따라 최신 OP 편집을 롤백했습니다. 다른 질문을 편집하는 것은 좋은 방법이 아닙니다. 기존 답변이 문맥을 벗어나기 때문에 새로운 질문을하십시오.) – halfer

답변

1

일부 5 년 전에 해커가되었지만 일하는 대답을 찾았습니다.

// 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

+0

다음과 같은 오류가 발생합니다. 치명적인 오류 : '매개 변수 1 : 유형이 일치하지 않습니다.'라는 메시지와 함께 'com_exception'예외가 잡히지 않았습니다. C : \ xampp \ htdocs \ cr.php : 29 Stack trace : # 0 C : \ xampp \ cr.php (29) : com-> AddObject ('rptParam', NULL, true) # 1 {main} throw C : \ xampp \ htdocs \ wincare \ laporan \ pakai.php 29 행 $ rptParam 값을 채우려면 어떻게해야합니까? –

+0

아, '$ rptParam'은 정의되지 않았습니다. 경고를 켜야 이런 종류의 것을 볼 수 있습니다. 저는 주로 새로운 추측을 추가하는 것을 도와 주려고했습니다. 이것은 주로 추측입니다. Windows/CR 환경에서 VB 편집기를 실행하고 자동 완성을 사용하여 사용할 메소드/속성을 찾아 낼 수 있기 때문에 ** 많은 노력을 기울여야합니다. – halfer

관련 문제