Is it possible to write VBA-Excel code using php? - php

I have been wondering whether or not it is possible to write VBA to an excel file using php? I ask this question for this reason -> I want to generate an excel report every monday when our users log in. The reports will pull data from our sql db, and write the data to an excel file.
My question is multi-part.
1) Is it possible to write data to an excel file and save that data without the user seeing it?
If I can, then I know how to have it attached using php mailer.
2) If it has to open as a result of using headers, can i write a vba script to minimize or make active workbook close. (I'm highly doubtful as it is because I think excel docs open up as csv when writing sql results to them.

Related

AS3 - Exporting data from Flash for use in Microsoft Excel

I'm producing a Flash tutorial project in Flash Professional CS5 using the ActionScript3 programming language, with my SWF optimised for Flash Player 10 (or higher).
My question relates to whether it is possible to write a Mouse Click function in AS3, attached to a button, which when clicked exports numerical/string data held within an array in Flash into a new suitable file format (such as CSV/XML), which my user can then subsequently open, view and edit in Microsoft Excel? This data wouldn't need to be passed back to Flash at any stage.
My tutorial is likely to be embedded within a web page or framework rather than sitting on the desktop. Can Flash conceivably 'package up' array held data and produce new file types? From reading around the CSV and XML file formats look my best options if the user is to study the data exported from Flash within the Excel software package?
If I'm embedding the project on the web, is there any PHP additionally required, which could aid in this re-packaging process and post the CSV or XML to a file location on the server or even better the user's hard-drive? Can Flash 'talk' directly with Microsoft Excel and do a conversion, export and open, or at best would the user be able to just get hold of the CSV/XML text file and open the file themselves manually in Excel?
A number of questions I know, but if any developer who has encountered (and hopefully conquered) this type of problem could provide me with some guidance or even better some example AS3 code which tackles this issue, I'd be extremely grateful.
Kind Regards,
Joel
try this solution Writing to CSV file in AS3 - simple as3 code or csvlib on google code.
I will post an example of this later:
Create a PHP page to output to Excel
Post the data to the PHP page (use JSON for ease of use)
Parse data on PHP side to generate adequate Array structure
Output the Excel sheet from PHP
Export Excel from PHP:
1) http://code.google.com/p/php-excel/
2) Alternative for PHP_excel
3) http://forums.digitalpoint.com/showthread.php?t=60681

Exporting data to excel sheet in php

For my website i want to give the user a new opportunity ,which is to export all user details in a excel file.It is possible to perform in php,if possible than may i get a link to this kind of work.
Simplest way is to use the built-in fputcsv function
PHP Manual - fputcsv

Run excel formula from php

Here's my clients scenario my client wants to put a excel file on server now from a PHP form
sends data to the file runs a formula in this excel file and get the results.
I don't know if this is possible.
If so direct me to a library best was PHP, or some other possible solutions.
It's perfectly possible: take a look at the PHPExcel library which has a built-in calculation engine for handling most Excel formulae
There's an example of populating an Excel file with data (in this case from a form input) then rendering a formula in that Excel file to generate a result an ddisplaying it to a web browser in the /Tests/ directory of the distribution. This simple example /Quadratic.php solves a quadratic equation; but the principle is similar enough
EDIT
See my response to this question for some indication of the limitations of PHPExcel's calculation engine
EDIT 2
The PHPExcel is deprecated, hence now you can use PhpSpreadsheet
You are thinking in the wrong direction. Instead trying to send the data to the excel file, read the excel file in you PHP script and do the math there.
Trying to send dynamic data into a static XLS file wont work.
And you can add a regular cronjob, that checks if the XLS file data has changed, if it has, then run your calculation again.

Share excel data across real-time?

I have developed a VBA spreadsheet that runs locally and with obtain data from other sources continuously.
I want to find a way to extract / access the data inside this spreadsheet through php and then output some processed data using a browser and these data will update accordingly as the spreadsheet updates itself.
Anyone can show me how to achieve this? Both the spreadsheet and the php will run locally on a windows machine if that is easier...
Thanks very much for your help :)
I just developed an application that does this the idea is to use http requests on_change events in the spreadsheet.
vba code for request in excel
Function httpRequest(ByVal path As String) As String
Set HttpReq = CreateObject("MSXML2.ServerXMLHTTP")
HttpReq.Open "GET", path, False
HttpReq.Send
httpRequest = HttpReq.ResponseText
End Function
On your php side you have to develop the part where the data is mapped in the database. And of course the view of the data. As for realtime you have to go for something more elaborate like a table that holds the latest changes and check for such changes every now and then unless there is some mechanism to do so.
In excel there exist timers to acomplish polled checking for updates
for web you should to use ajax for seamless updates have a look at http://datatables.net/
You can use PHP Excel Reader to display the data quite easily from the spreadsheet - I think this is the simplest of the PHP Excel libraries that will do what you want and simply set the page to refresh on a regular basis.
Using this library is pretty much as simple as this:
<?php echo $data->dump(true,true); ?>
Once you have told it where the file is to display the output pretty much as would be expected to see in an Excel Workbook. (Here is a link to an example that they have up and running online)
This means you won't get any locking issues as the read is done rather quickly (assuming a reasonable file size and users won't really ever be more than a few minutes/seconds behind.
You want PHP to just generate HTML from Excel sheets? Excel supports HTML generation natively.
Try Save as Web Page to test the quality of HTML produced by Excel. If it's OK then all you'll have to do is write a small piece of VBA that will be generating HTML from your spreadsheets automatically.
Sort of CMS build in Excel.

PHP make real time stock exchange application

I have a software which give me stock data as excel format , the data is automatically update continuously in every second.i have to show these data in web page such like they are shw in excel (ie the web data should be also update in such manner ) and these data. how it is be done.
Programatically export the data into CSV format and import it into a relational database.
Extract the data with web language and display in webpage. Tutorials for these steps should all be available.
To convert from xls to csv see the question...
converting an Excel (xls) file to a comma separated (csv) file without the GUI
For the second part, you can have a cron job run a PHP script that reads in the csv file contents and inserts this into a database. Plenty of threads on this also.
To display, select from database and format appropriately, can follow any of the basic tuts on the net for this part.
Post your code if you get stuck :)
As you've been told, use PHPExcel to read Excel file.
However, refreshing data every second is gonna make a very heavy load on your server.
I'd recommend you rather use server side push using Comet technologies. Take a look at Meteor server.
You will accomplish 'persistent' connection, so server will push data to the client, and the need to refresh the page or create ajax request every second will be gone.
You've tagged this PHP, so I assume that's your scripting language of choice: use PHPExcel to read the Excel file and write it out as formatted HTML to your web page. PHPExcel's HTML Writer will retain all the style and formatting of the original Excel workbook.
However, an update every second is pretty extreme for a web page, and for a scripting language. Rather than reading the Excel file whenever the page is requested, run this as a background task converting the Excel to a static HTML file whenever an Excel file is received, and serve the latest static HTML.
If this extreme timing is needed, then you might be better looking at a compiled language, or even a non-web solution.

Categories