How to add data to an existing Excel file with PHP?

后端 未结 5 477
灰色年华
灰色年华 2021-01-22 14:17

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

5条回答
  •  滥情空心
    2021-01-22 14:39

    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 :

    1. Build a php endpoint that publish the XML data (I have actually no php knowledge. Just ensure that calling yourdata.php will produce the data in XML).
    2. In excel, using a Data connection, insert the content of this XML file: Go to Data TAB (assuming Excel 2010), "From other source", "From Xml data import".
    3. let the wizard do the job

    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).

提交回复
热议问题