|
|
|
พอจะมีบทความเกี่ยวกับ php ติดต่อกับ Crystal Report ไหมครับ |
|
|
|
|
|
|
|
http://us2.php.net/manual/en/ref.com.php
เกี่ยวกับ Object COM
ตัวอย่าง Copy มาครับ ไม่รู้ช่วยได้ป่าว
Code (PHP)
$report_source = "";
$report_output = "";
$crapp = new COM ("CrystalRuntime.Application") or die ("Error onload");
$creport = $crapp->OpenReport($report_source, 1);
$creport->EnableParameterPrompting = 0;
$zz= $creport->ParameterFields(1)->SetCurrentValue("Demo"); //เซตค่าให้ Parameter
$creport->ExportOptions->DiskFileName=$report_output";
$creport->ExportOptions->DestinationType=1; // Export to File
$creport->ExportOptions->FormatType=31; // Type: PDF
//$creport->DiscardSavedData(); ต้อง Comment ตัวนี้ไว้ถ้าส่ง Parameter มาด้วย
$creport->Export(false);
$creport = null;
$crapp = null;
|
|
|
|
|
Date :
2009-07-22 12:09:19 |
By :
taobsd |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?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);
?>
------
Guys, I found a way to pass parameters from PHP to Crystal Reports 11 without hanging!!!!
So the problem is the prompt for params dialog:
Code (PHP)
<?php
$ObjectFactory= New COM("CrystalReports11.ObjectFactory.1");
$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application");
$creport = $crapp->OpenReport($my_report, 1);
$creport->Database->Tables->
Item(1)->ConnectionProperties['User ID'] = 'blablabla';
$creport->Database->Tables->
Item(1)->ConnectionProperties['Password'] = 'blablabla';
$creport->FormulaSyntax = 0;
$creport->RecordSelectionFormula= "{TABLENAME.FIELDNAME}='$USRID'";
//This is it, this avoids the hanging!
$creport->EnableParameterPrompting = 0;
$creport->DiscardSavedData;
$creport->ReadRecords();
//it is essential to assign the param values here after the readrecords otherwise you will not pass anything...
$zz= $creport->ParameterFields(1)->SetCurrentValue(500);
$creport->ExportOptions->DiskFileName=$exp_pdf;
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1; $creport->ExportOptions->FormatType=31;
$creport->Export(false);
$creport->ExportOptions->DiskFileName=$exp_xls;
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1; $creport->ExportOptions->FormatType=29;
$creport->Export(false);
$len = filesize($exp_pdf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=reportin.pdf");
readfile("reportin.pdf");
//------ Release the variables
$creport = null;
$crapp = null;
$ObjectFactory = null;
?>
-----
Have fun,
Andras
This function converts the crystal report in file $my_report to a PDF file $my_pdf. Exceptions may raise, so put it in a try..catch block.
I struggled so hard to get this done... any comments, please contact me.
Code (PHP)
<?php
function exportCrystalReportToPDF( $my_report, $my_pdf )
{
// by dfcp/mar/06
$ObjectFactory= New COM("CrystalReports11.ObjectFactory.1");
$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application");
$creport = $crapp->OpenReport($my_report, 1);
$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);
}
?>
|
|
|
|
|
Date :
2009-07-22 13:41:52 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ท่องตามเน้ตไปทั่วอะ
|
|
|
|
|
Date :
2009-07-22 13:42:29 |
By :
danya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ภาษาอังกฤษทั้งนั้น อ่านบ่ออก
ถ้าทำได้ แนะนำมั่งนะครับ
|
|
|
|
|
Date :
2009-07-22 14:04:49 |
By :
panyapol |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมก็กำลังหาเหมือนคุณ ดุ้นยาว เอ้ย ดุนยา เหมือนกันครับ อิอิ
|
|
|
|
|
Date :
2012-11-02 14:07:32 |
By :
nerobenz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-06-11 15:24:33 |
By :
tt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีใครทำได้บ้างไหมครับ หาจนงงไปหมดแล้วครับ
|
|
|
|
|
Date :
2014-07-02 13:50:44 |
By :
aobbie_p |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมมีทางเลือกอื่นให้
Basic -> dompdf สร้างแทก HTML แล้วจับยัดได้เลย
Expert -> Fpdf ต้องมานั่งตีตารางกำหนดจุดการพิมพ์ด้วยตัวเอง
|
|
|
|
|
Date :
2014-07-02 13:54:50 |
By :
soghband |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|