Results 1 to 13 of 13
  1. #1
    Join Date
    Oct 2004
    Posts
    26

    Unanswered: Running excel macro in PHP

    Hi,

    I've an excel macro written with an interface. Now, i need to put it on the web and PHP is the web programming language that I'm more familiar with. Has been serching for articles to launch excel macro from PHP but to no avail (or I'm just not good at finding it). Was wondering, is there anyone that has similar experience running excel macro written in VBA from PHP? Your help is very much appreciated. Thanks in advance.

    Dniz

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I'm not sure how you were planning on accomplishing this, however I feel I should point out the following :

    PHP is a web language, and thus must be run through a web browser (from a remote server). This means it is UNABLE to access ANY information local to the PC user that is currently on the website. i.e. a website cannot run a local excel macro.

    However, if you were thinking about hosting the macro in the same environment as the web application written in PHP, then how you were expecting to present the macro to the user? Bear in mind you would have to present it inside the web browser to the user. As far as I am aware PHP does NOT have a VB (compiled code) runnable driver/module. Nor does it have the option to run vbscript (i should emphasise i'm not sure whether a macro is VB compiled code or vbscript plain ascii).

    Any further information on your setup and proposed plan may enlighten the question some more with, hopefully, a resolution.

  3. #3
    Join Date
    Oct 2004
    Posts
    26
    Hi, aschk,

    Actually, I am planning to upload the entire excel file. User can directly run from web as if the excel file exists in local without downloading it. However, this does not seems to be a doable solution as most web browser will prompt user to download the file first. My target is to accomplish the same result as I am running the macro in PC locally without having to rewrite the macro. So far, I've been writing some simple vbscript in php, using mixed method in, eg: calling vb function whenever a button is clicked to prompt for a message. I wonder if VBA code is compatible with VB script? Minimal change in code is the ultimate aim here.

    Dniz.

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Vbscript in PHP? Are you sure you're not writing Javascript or ASP? VBScript and PHP are not interchangeable (to my knowledge).
    If you're uploading the excel file straight to the web server you should be able to query is using ODBC almost like querying a MSAccess database. At least i believe this to be possible. I have never personally done it.
    What it means though is that you'll have to write your macros in PHP versions to get them to manipulate the data.

    Something more obvious though. If you're planning on putting the excel spreadsheet onto the host, then why don't you convert your excel spreadsheet to a DB (mysql/access/sql) and use that instead? Forgo the uploading the spreadsheet...

  5. #5
    Join Date
    Oct 2004
    Posts
    26
    Hi, aschk,

    you are right. i am using Javascript, not VBscript. Opppsss... looks like I am really lost The constraint here is actually, the source file for running the excel macro is another excel file which is at the client side. I am just considering different ways of accomplishing my target without massive code migration. I am trying to avoid using ODBC as I am more of a freeware/unix supporter any comment on this?

    Quote Originally Posted by aschk
    Vbscript in PHP? Are you sure you're not writing Javascript or ASP? VBScript and PHP are not interchangeable (to my knowledge).
    If you're uploading the excel file straight to the web server you should be able to query is using ODBC almost like querying a MSAccess database. At least i believe this to be possible. I have never personally done it.
    What it means though is that you'll have to write your macros in PHP versions to get them to manipulate the data.

    Something more obvious though. If you're planning on putting the excel spreadsheet onto the host, then why don't you convert your excel spreadsheet to a DB (mysql/access/sql) and use that instead? Forgo the uploading the spreadsheet...

  6. #6
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    Your latest post states that the excel file is client side. Web servers have no ability to directly access a file on the client side (you would need to upload or other wise place this on the web server for a PHP script to even be able to read the file.) Also, a browser has very limited ability to access a file on the client side as well.

    Lastly, an excel file is not web friendly. Even if the excel file is on the server, a PHP script can basically read and write cells, one at a time... or you can provide a link to the file, in which case it would be served/downloaded to the client and would open in the browser (or could be "saved as" a file), provided excel is installed on the client and is available to the browser as a "helper" application.

    If you describe what functionality the spreadsheet and macros are providing, someone could provide direction on how to best implement this using web based technology. By simply converting this to use the proper web based foundation, you will end up with less code, fewer problems, and a more general purpose and robust solution than what it will take to make it work with the excel file as part of it (if this is even possible.)

    Every time I have seen someone try to mix technology, because they wanted to use part of what they already had, thinking they would save time, has always ended up costing more time to work around the problems of integrating the legacy application, than what it would have taken to just redo the whole application using the proper technology. And a majority of the time I have seen someone do this, after the results were so poor and limited, the application ended up being redone using the proper technology anyway, costing over twice the amount of time it should have.

    Edit: If you were on a Windows server, with Excel installed, and the spreadsheet was on the server, you could access it using the PHP COM functions - http://www.php.net/manual/en/ref.com.php Search on that page for "excel" in the User Contributed Notes for examples of how you would access the excel file.
    Last edited by dbmab; 08-29-07 at 02:00.

  7. #7
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I think you need to set out some project guidelines as to what/where you are doing particular operations.

    For example :
    Are you hosting ONLY ONE excel spreadsheet, and is it on the server?
    OR
    Are you having each local machine (i.e. web user) have a local copy of the spreadsheet?

    Do you require your users to manipulate data on a spreadsheet (directly or using a macro) or via a web GUI?

    What does the "macro" do? Read/write/alter data?

    *You need to understand the difference and limitations of client-side versus server-side.*

    Client-side examples :
    Program on local machine (e.g. Microsoft Word) - this CANNOT be accessed externally, i.e. by a website
    Javascript inside a browser - this CANNOT access local machine information. IE/FF/any other web browser does NOT allow javascript to do anything outside of the browser window without an ActiveX component (and believe me you don't want to go down that route). Thus, you CANNOT use a local (i.e. on the users machine) macro/spreadsheet from a browser.

    Server-side examples :
    PHP/ASP/JSP - These are ALL scripting languages and they are ALL run on the server machine NOT the client machine. A client requests a page from a server and one of these "web languages" inteprets your page request, performs some functions/actions and then return to the client's browser some html. Thus, NONE of these scripting languages can alter/modify or access ANY application/program on the users machine. Hence, it cannot access an excel spreadsheet that exists on the users machine. HOWEVER it CAN access a spreadsheet/excel file that exists on the server (because the script and the file exists on the same physical machine). So it would seem sensible that the hosting machine has the file and page requests from the client utilise PHP/ASP/JSP to manipulate the data held therein.

    note : Please be aware JSP is NOT Javascript. Javascript is a client side language and JSP is a server side (Java based) language. Javascript and Java are NOT the same.

  8. #8
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    dbmab : I was particularly interested to read that stuff on COM, and I recall having seen it before. I liked the spell checking example that was demonstrated by one of the comment poster's and it certainly opens some options for integrating PHP and MS progs, although, of course, they need to be located on the same machine

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by aschk
    dbmab : I was particularly interested to read that stuff on COM, and I recall having seen it before. I liked the spell checking example that was demonstrated by one of the comment poster's and it certainly opens some options for integrating PHP and MS progs, although, of course, they need to be located on the same machine
    php can run on client machines... but it need to be installed on those machiens and properly configured. It looks as if the developers of PHP are trying to push the language into areas that VBScript seems to do on Microsoft OS's.
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Don't even go there... Do you want to install PHP/Apache onto each client machine, and then maintain it? How do they update when you change a form or some backend logic? A web application should be just that, on the web...

    The only people who should be running a web application locally should be developers. Also, whats the point in putting PHP on the client machine? Just give them the excel file + macro to run on their local machine if you're going to do that.

    I think the point is that the excel/data file is supposed to be maintained by EVERYONE at the same time, which is impossible if you have it locally on each machine. It needs to be stored centrally, unless of course you want to spend a LOT of time merging all those changes that every user has made each time they make a change...

  11. #11
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Apologies if the previous post seems like a flame... It wasn't aimed at you healdem, just on the possibility that Dniz might consider it.
    I just want to make sure that DNiz doesn't go down that road.
    Last edited by aschk; 08-30-07 at 07:20.

  12. #12
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by aschk
    Apologies if the previous post seems like a flame... It wasn't aimed at you healdem, just on the possibility that Dniz might consider it.
    I just want to make sure that DNiz doesn't go down that road.

    Id agree its not appropriate for Dniz.. but you can use PHP on a local machine, without a webserver in a similar manner to vbscript.. in some ways its alm,ost like harking back to the old days of the MSDOS batch language
    I'd rather be riding on the Tiger 800 or the Norton

  13. #13
    Join Date
    Oct 2004
    Posts
    26
    Hi, aschk & healdem,

    Thanks for all the recommendations. Yeah, actually i do agree to your points of trying to find a shortcut but end up coming to a long route theory... it's just a pain cycle to go through, so I am seeking for alternatives May be it is just not right to use excel in PHP since PHP processes data in server side. Besides, I'm trying to avoid developing application using MS application as it may not be installed in the client side. This will limit the flexibility in generating the result However, thanks for recommending the COM article, i've never though there's such integration in PHP. It looks useful if an MS application is really required. I've decided to rewrite the code by migrating only the method, but not the entire code. Perhaps this is a more proper way to avoid hassle in the future.

    Dniz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •