I have a Excel file with forms and controls. As it is not possible to create a Excel file with forms, controls and VBA code from scratch using PHP, I thought I could upload my e
It's pretty easy to add with PHPExcel - load file, add data after last row, save file... unfortunately, forms and VBA code aren't supported.
To retain those, you'll need to use COM, which restricts you to a Windows server with MS Excel installed.
Think in the other direction!
Instead of pushing data to excel from php, add a data connection to excel that will retrieve its data from a php endpoint taht publish xml.
Don't know if it applies, but it's far more easier to implement.
Moreover, you will have total control on the excel file, keeping all customisations, including VBA.
And finally, you will avoid all messy COM object managing if you end up in this direction.
[Edit] Steps for this solution :
yourdata.php
will produce the data in XML).After that, you will have a list in Excel, than is linked to your xml source. SImply right lick the list / refresh to get the latest data (or configure the data connection to auto refresh at opening).
I don't think you can actually append
data to an existing excel file.
This will simulate append action.
@SteveB Further to my comment and your response earlier.. pls read below.
@SteveB Looks like an excellent idea.. but why use xml? i try to use xml but i don't know what format to write the xml in text file? can you explain. can we also just use .csv? as it looks easy to write a simple .csv file. How will the whole solution work.. say i am the user.. who clicks and opens a php page.. and where should the excel template be stored.. and how it will pop to user.. what happens when another user connected to same page, etc. I want to keep pivot tables, excel macros and vba, images and charts in the template file. – ihightower
@ihightower: xml is easier to produces than CSV (at least using .Net and C#, which is my primary programming language), but this can works with CSV too I think. Providing the Excel template is easy... simply serve it as a static content, as the excel file is not dynamically generated. – Steve B
My finidings..
CSV format for import is only good if Excel Table format is NOT required. You cannot have the alternate rows highlighting, column headers available during scroll, etc. in summary, for what i found you cannot have external data and table format at the same time.
The error you will get converting the data connection table to "Format as table" is this:
Your selection overlaps one or more external data ranges.
Do you want to convert the selection to a table and remove
all external connection?
Of course, I do not want that.. but using xml format for import data connection... the table format can stay like this screenshot:
And, when you scroll past one screen full.. the screen will look like this.. you can see the column headers A, B, C is automatically converted to the data header (ISBN, date, Title, ...)
So, we should go for an xml solution.. which we are figuring out how using php. But, using CSV for testing purposes with about 10 columns x 20,000 rows data.. it works very nicely. The refresh from web server also works very well.
I have had an internal discussion with my team and we think this will really work for us. Now, we are brainstorming on the delivery and flow of user actions to deliver the Excel template reports with data which he generated from php.
Here is the Excel Template with sample data.. in this screenshot... you can see
We can basicially use everything Excel has available for us. The resulting xml file can be left on the webserver.. and also data connection can be an URL also or as a file.
sourceFile="http://xxxxx/test_data3.csv" or
sourceFile="C:\Users\Fiaz\Documents\Magic Briefcase\Learn\excel\test_data3.csv"
The part that are yet to be figured out is how to connect this all together with seamless user experience.. that is the user should not be forced to save the file at first or manually connecting the xml etc.. The excel template must just open right there with the required data and all the analysis available. If user need to save it he will use save as and copy to local machine.
The idea we have for this seamless user experience is like this:
I tried it manually step by step and it really worked.
Will be much appreciated for any ideas on this to make it really better and still keep it simple.
Feedback required from PHPExcel author @MarkBaker:
@MarkBaker: From reading through your comments in other posts for PHPExcel, I understand that we CANNOT do the same using PHPExcel (that is to use the original excel template as it is). So, the solution suggested by SteveB and elaborated by me above seems to be much more powerful for this purpose. We can keep the original excel template file in tact with ALL THE ASSETS (pivot table, vba, etc.) with in it as it is. The server need not have Excel as well.
So, can we expect this feature to be available with PHPExcel itself sometime in the future. Then we can be more confident in using the standard technique from the PHPExcel guru himself.
in my opinion PHPExcel is very useful for invoice type of reports and many others but not for business intelligence type of analysis... which requires the use of pivot tables and complicated charts and code, etc.
Please make your comments.. I will be very interested to see it from your view on how it can be made better.
Make everything as simple as possible, but not simpler. Albert Einstein
OpenTBS is a PHP class PHP, that enables you to build an XLSX (or XLSM, that is XLSX with VBA macros) documents with the technical of templates.
It's very easy to populate a worksheet. You can also edit forms and VBA since you know their XML structure.
By the way OpenTBS also supports DOCX, PPTX, ODT, ODS, ODP, ...