简体   繁体   English

如何使用php刷新Excel中的数据透视表

[英]How to refresh pivot table in excel using php

I have a file in xls format that I need to refresh (use 'refresh all' button in Excel) once a day and then retrieve the data from the pivot table and inset them into the database (MySQL). 我有一个xls格式的文件,我需要每天刷新一次(在Excel中使用“全部刷新”按钮),然后从数据透视表中检索数据并将其插入数据库(MySQL)。 The file gets data from an external source (retrieve data from sharepoint 2007). 该文件从外部源获取数据(从sharepoint 2007检索数据)。

How is the easiest way to do this? 最简单的方法是什么? I'm thinking abaout PHP but do I not quite know how you go about it. 我正在考虑abaout PHP,但我不太了解您如何使用它。 From what I read PHPExcel does not support this operations. 据我了解,PHPExcel不支持此操作。 When you try to use COM I get an error: 当您尝试使用COM时,出现错误消息:

Fatal error: in D:\xampp\htdocs\sp\xls\index.php on line 11

And here is a php code: 这是一个PHP代码:

<?php

// Start Excel
$excel = new COM("Excel.Application") or die ("Could not load Excel.Application");

// Make Excel visible.
$excel->Application->Visible = 1; 

// Open  workbook
$Workbook = $excel->Workbooks->Open('D:/xampp/htdocs/sp/xls/emails.xls', 'r+') ;

// Refresh all
$Workbook->RefreshAll();

// Save updated excel file out to disk somewhere
$Workbook->SaveAs('D:/xampp/htdocs/sp/xls/emails.xls');

// Close all instances of excel:
$Workbook->Close(false);
unset($Workbook);

$excel->Workbooks->Close();
$excel->Quit();
unset($excel);
?>

I'm using windows 7 and xampp with php 5.5.6 我正在将Windows 7和xampp与PHP 5.5.6一起使用

In php.ini I've added this line: 在php.ini中,我添加了以下行:

extension=php_com_dotnet.dll

Alternate: is it possible to run *.iqy file generated by sharepoint in php? 备用:是否可以在PHP中运行sharepoint生成的* .iqy文件?

I found a workaround to my problem. 我找到了解决问题的方法。

Instead, refresh the data by PHP pointed out in a query that collects data during the re-launch of the sheet. 取而代之的是,使用PHP重新刷新查询中指出的数据,该查询在重新启动工作表期间收集数据。 To this I added this VBA script save changes and close file. 为此,我添加了 VBA脚本以保存更改并关闭文件。

At the end of the added task scheduler to run the sheet once per day. 在添加的任务计划程序的末尾,每天运行一次工作表。 The rest of downloading data from Excel using PHPExcel. 使用PHPExcel从Excel下载数据的其余部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM