I have two rpt files which I need to read, store into excel and mysql database. Also, I need to create a report that is the result of a join on two rpt files by referring to a unique column common in both of them. I have read Excel, Exported Excel and Exported pdf before but this time I have no idea how to even start. I tried googling and found the following solution but it converts rpt to pdf:
//- Variables - for your RPT and PDF
//echo "Print Report Test";
$my_report = "D:\\Program Fiels\\xampp\\htdocs\\RPT\\RPT-list.rpt"; //
//rpt source file
$my_pdf = "D:\\Program Fiels\\xampp\\htdocs\\RPT\\RPT-list.pdf"; // RPT export to pdf file
//-Create new COM object-depends on your Crystal Report version
$ObjectFactory= new COM("CrystalReports10.ObjectFactory.1") or die ("Error on load"); // call COM port
$crapp = $ObjectFactory-> CreateObject("CrystalRuntime.Application.10"); // 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("servername", "username", "password", "databasename");
//- field prompt or else report will hang - to get through
$creport->EnableParameterPrompting = 0;
//- DiscardSavedData - to refresh then read records
$creport->DiscardSavedData;
$creport->ReadRecords();
//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;
Also the above code is looking for a COM component: CrystalReports10.ObjectFactory.1
I need to deploy this application on a Linux server so I am not sure whether this COM component will be available there or not.
Kindly tell me how can I read rpt using Codeigniter and store data into database and excel.
Related
I have a blob which we receive from a Firebird 3.0 database.
if($dbh = ibase_connect($db,$username,$password, 'UTF-8')){
echo "Connecton steht zur Firebird DB steht! <br>";
$sql = "SELECT MEMO FROM DMS where ID = '44'";
// Execute query
$rc = ibase_query($dbh, $sql);
// Get the result row by row as object
$data = ibase_fetch_object($rc);
$blob_data = ibase_blob_info($data->MEMO);
$blob_hndl = ibase_blob_open($data->MEMO);
$inhalt = ibase_blob_get($blob_hndl, $blob_data[0]);
With
ibase_blob_echo($data->MEMO)
there comes a lot of signs in browser, so the SQL query works. Now I'd like to write the content (its a PDF) in a pdf file on disk.
Every try didn't succeed:
file_put_contents('test.pdf', $inhalt);
file_put_contents('test.pdf', ibase_blob_echo($data->MEMO));
and much more.
When we try to open the PDF File with Acrobat Reader, there comes an error message: no PDF File / File-type is not supported
How can we fix this?
thank you for your answers ... We interpreted them in a way, that the code above is basicly correct. After a while, we found out, that the error apears because we changed the charset in the DB Connect to UTF8 for the varchar Fields. For the blob we connect now without Charset change and the readout work properly. Thank you again.
$dbh = ibase_connect($db,$username,$password)
I am new to Crystal Reports, and I am using version Crystal Reports 11.5.
My requirement is as below:
Programming Environment is PHP .
Database is MySQL.
I want to generate PDF reports using Crystal Report + PHP + MySQL.
Currently, I am using COM object to connect to Crystal Report using PHP, and I am able to generate a sample static PDF report.
My main task is to do all processing in PHP by fetching values from MySQL and pass the values to Crystal Reports and generate a PDF. I need assistance to achieve this task. If anybody can provide sample code then it will be much better.
This is what I have so far:
$my_report = "E:\\xampp\\htdocs\\crystal\\Test1.rpt";
$my_pdf = "E:\\xampp\\htdocs\\crystal\\test.pdf";
$o_CrObjectFactory = new COM('CrystalReports11.ObjectFactory.1');
// Create the Crystal Reports Runtime Application.
$o_CrApplication =$o_CrObjectFactory->CreateObject("CrystalDesignRunTime.Application");
//------ Open your rpt file ------
$creport = $o_CrApplication->OpenReport($my_report, 1);
//------ Connect to DB2 DataBase ------
**this is the hard part where I am not able to complete connection to mysql**
$o_CrApplication->LogOnServer('which library','mlims','root','');
//------ Put the values that you want --------
$creport->RecordSelectionFormula="{parameter.id}='1'";
//------ This is very important. DiscardSavedData make a
// Refresh in your data -------
$creport->DiscardSavedData;
//------ Read the records :-P -------
$creport->ReadRecords();
//------ Export to PDF -------
$creport->ExportOptions->DiskFileName=$my_pdf;
$creport->ExportOptions->FormatType=31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
//------ Release the variables
$creport = null;
$crapp = null;
$ObjectFactory = null;
As you see In the above code, I need to connect the Mysql server which I have been trying to do for the last few days. I have tried many examples on the net, but most of them are for SQL Server, not MySQL.
Please follow the steps:
Download the MySQL Connector J jar file. That download should contain a jar file that looks something like:
mysql-connector-java-3.1.14-bin.jar
Add the location of your newly downloaded jar file to the Classpath, as defined in CrystalReports CRConfig.xml file. On a Windows machine, the config file will be located somewhere like:
C:\Program Files\Business Objects\Common\3.5\java\CRConfig.xml
Once you have altered your CRConfig.xml, close and reopen Crystal Reports.
From the menu: File -> New -> Standard Report
In the “Available Data Sources” list, double-click to expand “Create New Connection”
Double-click to expand “JDBC (JNDI)”
Double-click “Make New Connection”
Connection URL: “jdbc:mysql://db.example.com/dbname” (Use your own database host name and db name).
Database Classname: “com.mysql.jdbc.Driver”
Click “Next”
Enter a database user/password combination when prompted.
You should now be able to inspect the tables/columns in the database to begin reporting.
See reference
I have a file in xls format that I need to refresh (use 'refresh all' button in Excel) once a day and then retrieve the data from the pivot table and inset them into the database (MySQL). The file gets data from an external source (retrieve data from sharepoint 2007).
How is the easiest way to do this?
I'm thinking abaout PHP but do I not quite know how you go about it. From what I read PHPExcel does not support this operations.
When you try to use COM I get an error:
Fatal error: in D:\xampp\htdocs\sp\xls\index.php on line 11
And here is a php code:
<?php
// Start Excel
$excel = new COM("Excel.Application") or die ("Could not load Excel.Application");
// Make Excel visible.
$excel->Application->Visible = 1;
// Open workbook
$Workbook = $excel->Workbooks->Open('D:/xampp/htdocs/sp/xls/emails.xls', 'r+') ;
// Refresh all
$Workbook->RefreshAll();
// Save updated excel file out to disk somewhere
$Workbook->SaveAs('D:/xampp/htdocs/sp/xls/emails.xls');
// Close all instances of excel:
$Workbook->Close(false);
unset($Workbook);
$excel->Workbooks->Close();
$excel->Quit();
unset($excel);
?>
I'm using windows 7 and xampp with php 5.5.6
In php.ini I've added this line:
extension=php_com_dotnet.dll
Alternate: is it possible to run *.iqy file generated by sharepoint in php?
I found a workaround to my problem.
Instead, refresh the data by PHP pointed out in a query that collects data during the re-launch of the sheet. To this I added this VBA script save changes and close file.
At the end of the added task scheduler to run the sheet once per day.
The rest of downloading data from Excel using PHPExcel.
I have a database table to store my templates(.docx file). I am using openTbs to work on that templates.My need is that to take out the template and store it in thee server itself, and edit using openTbs.
My question is that how I can retrieve .docx file from database and store that in the server side.? (The storing may be temporary but i want to edit it using openTbs.)
Thanks in advance.......
It is bad practice to save binary data in the database, mostly when this data are intend to be processed by a file server, such as pictures or your DOCX.
Anyway, since OpenTBS 1.8.1, you can open an DOCX (or any Ms Office, LibreOffie or zip archive) from a PHP file handle.
You can use this feature to easily merge your template from the database :
// retrieve binary data of the file
$rs = mysql_query($dbc, "SELECT data FROM files WHERE id=$id");
$rec= mysql_fetch_array($rs, MYSQLI_ASSOC);
mysql_free($rs);
// create a temporary file
$temp = tmpfile();
fwrite($temp, $rec['file']);
unset($rec); // free PHP memory
// Open the file with OpenTBS
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate($temp);
...
Im trying the following code:
<?php
$workbook = "D:\b2\\test.XLS";
$sheet = "Sheet1";
#Instantiate the spreadsheet component.
$ex = new COM("Excel.sheet") or Die ("Did not connect");
#Get the application name and version
print "Application name:{$ex->Application->value}<BR>" ;
print "Loaded version: {$ex->Application->version}<BR>";
#Open the workbook that we want to use.
$wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open");
#Create a copy of the workbook, so the original workbook will be preserved.
$ex->Application->ActiveWorkbook->SaveAs("D:\b2\Ourtest.xml");
#$ex->Application->Visible = 1; #Uncomment to make Excel visible.
#Optionally, save the modified workbook
$ex->Application->ActiveWorkbook->SaveAs("D:\Ourtest.xml");
#Close all workbooks without questioning
$ex->application->ActiveWorkbook->Close("False");
unset ($ex);
?>
This actually works and creates the Ourtest.xml file. But im getting characters like:
ÐÏࡱá > þÿ þÿÿÿ
I have tried with SaveAs("D:\Ourtest.pdf") and it says the file has been corrupted or incorrectly decoded.
Can anyone help me please?Thanks
That is because you are saving it as Excel Format. Check the Excel documentation for how to save it as an XML document - it might be a separate paramter to SaveAs or a different method alltogether (Export*).
EDIT: It seems SaveAs is the right method to use. Check the msdn documentation here. You probably want to specify the second parameter FileFormat. Maybe setting it to the XlFileFormat.xlXMLSpreadsheet value?
Problem solved by using
$ex->Application->ActiveWorkbook->SaveAs("D:\Ourtest.xml",46);
46 is the value for xlXMLSpreadsheet
Thanks everyone