Export to excel by using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hadad.golan
Forum Newbie
Posts: 2
Joined: Tue Aug 11, 2009 2:51 am

Export to excel by using PHP

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Export to excel by using PHP

Post 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?
hadad.golan
Forum Newbie
Posts: 2
Joined: Tue Aug 11, 2009 2:51 am

Re: Export to excel by using PHP

Post 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
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: Export to excel by using PHP

Post 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..
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Export to excel by using PHP

Post 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.
Post Reply