Page 1 of 1
Export to excel by using PHP
Posted: Tue Aug 11, 2009 2:55 am
by hadad.golan
Hi,
I want to export to excel from RPG by using PHP. After click on RPG display, RPG program will call to PHP script and the PHP script will open explorer on my PC and show the excel in the explorer.
The main problem is how to open a connection (with PHP) to computer (my PC) with IP= xxx.xxx.xxx.xxx and open the explorer (on my PC).
I am using emulator (BOSaNOVA or iSeries emulator) to connect to my as400.
There is a way to do that?
Regards,
Golan
Re: Export to excel by using PHP
Posted: Tue Aug 11, 2009 3:02 am
by Mark Baker
hadad.golan wrote:I want to export to excel from RPG by using PHP. After click on RPG display, RPG program will call to PHP script and the PHP script will open explorer on my PC and show the excel in the explorer.
The main problem is how to open a connection (with PHP) to computer (my PC) with IP= xxx.xxx.xxx.xxx and open the explorer (on my PC).
I am using emulator (BOSaNOVA or iSeries emulator) to connect to my as400.
There is a way to do that?
Are you asking how PHP can create an Excel file? or how PHP can open explorer (assuming windows explorer) on your client PC?
Re: Export to excel by using PHP
Posted: Tue Aug 11, 2009 4:11 am
by hadad.golan
I want to know if I can open windows explorer from PHP while I have only the machine IP (the client isn't initiate the session).
This mean I want to run PHP from i5/as400 that will open a session to a client with the IP I have. (The as400 will initiate the session to the client)
Thx,
Golan
Re: Export to excel by using PHP
Posted: Tue Aug 11, 2009 4:12 am
by turbolemon
In my experience, it would be easiest to generate a CSV file on the web server. If you have Excel installed on the PC it should be associated with CSV. If you have MS Office installed on a windows-based web server, you can use the PHP COM library, which is rather server intensive. You can also use Excel XML formatted files to read/write spreadsheets.
http://us.php.net/manual/en/function.fputcsv.php
http://us3.php.net/manual/en/book.com.php
http://us2.php.net/simplexml
http://www.ibm.com/developerworks/opens ... index.html
To connect to your PC you could use FTP or SSH/SCP (if using Mac OS X or Linux, maybe Windows using CYGWIN). This would involve the PC acting as an FTP/SSH server (requiring installation), and the web server as a FTP/SSH client.
http://us3.php.net/manual/en/function.ssh2-scp-send.php
http://us3.php.net/manual/en/book.ftp.php
You would need a static IP from your ISP or use a dynamic DNS resolution service (e.g. dyndns.com). You would also need to configure your network router to allow inbound connection attempts to your PC (assuming you aren't directly connected with a modem!). This would involve placing your PC in the DMZ (open and unprotected by the router's firewall from the internet), or configuring port forwarding/triggering to forward requests to a certain port on the router over to your PC. You may also need to configure your PC with an internal static IP address, as in my experience forwarded ports are assigned to a static internal network address.
http://cygwin.com/ Linux for windows (CLI)
http://x.cygwin.com/ Linux for windows (with window manager, X window system)
If you connect via SSH you could execute command-line applications, but I don't know how CYGWIN would execute a windows application. I guess you could install Nautilus or something in the CYGWIN environment and execute that..?
http://us3.php.net/manual/en/book.ssh2.php
The amount or effort involved in setting up this system is immense, compared to selecting "Open Directory" in your web browser. It would an interesting POC though..
Re: Export to excel by using PHP
Posted: Tue Aug 11, 2009 4:46 am
by Mark Baker
Personally I'd generate Excel files rather than CSV, using the
PHPExcel library.... but generating the file is the easy part of this exercise.
If the client PC was also running Apache/PHP, then you could always send an http request to a php script running on the client, which could use COM to open Windows Explorer on the client, with no need for cygwin, although all of turbolemon's comments about configuring the network to allow access to that client PC still hold true.