如何使用PHP将数据添加到现有的Excel文件中? [英] How to add data to an existing Excel file with PHP?

查看:244
本文介绍了如何使用PHP将数据添加到现有的Excel文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有表单和控件的Excel文件.由于无法使用PHP从头开始创建包含表单,控件和VBA代码的Excel文件,因此我认为我可以将空的Excel文件上传到服务器,进行更新,然后让用户下载.

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 empty Excel file to the server, update it and then let the user download it.

我知道有一些非常好的PHP类,例如PHPExcel,但是我不知道这些类是否可以像上述那样附加数据.以前有人做过吗?

I know there are some very good PHP classes as PHPExcel, but I don't know if these classes may append data as said. Does anybody has already done this before?

推荐答案

从另一个方向思考!

不是将数据从php推送到excel,而是将数据连接添加到excel,它将从php端点taht publish xml检索其数据.

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.

此外,您将完全控制excel文件,保留所有自定义设置,包括VBA.

Moreover, you will have total control on the excel file, keeping all customisations, including VBA.

最后,如果您朝着这个方向发展,您将避免管理所有混乱的COM对象.

And finally, you will avoid all messy COM object managing if you end up in this direction.

此解决方案的步骤:

  1. 构建一个发布XML数据的php端点(我实际上没有php知识.只需确保调用yourdata.php会以XML生成数据).
  2. 在excel中,使用数据连接,插入以下XML文件的内容:转到数据TAB(假定Excel 2010),来自其他来源",来自Xml数据导入".
  3. 让向导完成任务
  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

在那之后,您将在Excel中拥有一个列表,该列表将链接到您的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).

这篇关于如何使用PHP将数据添加到现有的Excel文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆