PHP的Excel阅读器 – 写作表

嘿家伙我是新来的PHP,并试图自我学习这种语言。 现在我正在尝试使用纯PHP来实现Excel文档到浏览器上的显示。 我正在使用PHP Excel Reader来阅读文件,但不知何故,他们没有显示。

虽然我可以做我自己的debugging和研究,如果有错误消息,告诉我哪一行导致错误,但没有,我现在面临的问题是

  1. 表格没有显示出来
  2. 没有来自Apache的任何types的错误消息

我正在努力实现的是:

  • 使用PHP Excel Reader在浏览器上以表格格式显示Excel电子表格
  • 检查.xls文档中有多less张表,获取表名并相应地显示button数量
  • 这些button必须能够允许用户在一个文档的不同页面之间进行遍历

现在我能够得到代码来计算页数,并正确显示它的名称和button,但仍然无法显示相应的表。

我已经尝试了许多方法来解决这个问题的基础上的文件,但无济于事。

这是我目前的代码:

使用example.php

<?php error_reporting(E_ALL ^ E_NOTICE); require_once 'reader.php'; $data = new Spreadsheet_Excel_Reader("test.xls"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" src="scripts/excel.js"></script> <style> table.excel { border-style:ridge; border-width:1; border-collapse:collapse; font-family:sans-serif; font-size:12px; } table.excel thead th, table.excel tbody th { background:#CCCCCC; border-style:ridge; border-width:1; text-align: center; vertical-align:bottom; } table.excel tbody th { text-align:center; width:20px; } table.excel tbody td { vertical-align:bottom; } .clearfloat { clear: both; } table.excel tbody td { padding: 0 3px; border: 1px solid #EEEEEE; } table.excel tname { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #000000; padding-right: 10px; padding-left: 10px; } .sheetnames { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; text-transform: uppercase; color: #000000; padding-right: 20px; float: left; padding-bottom: 20px; } </style> </head> <body onLoad="changeSheet(0)"> <form action="<?php echo $editFormAction; ?>" method="post" name="worksheet"> <?php $i = -1; for($s=0; $s<count($data->sheets)-1; $s++) { $i++; ?> <div class="sheetnames"> <input name="sheet" type="button" value="<?php echo $data->boundsheets[$i]['name'];?>" onClick="changeSheet(<?php echo $i ?>)"> </div> <?php } ?> <div class="clearfloat"></div> <div id="test"></div> </form> </body> </html> 

excel.js

 // JavaScript Document var xmlHttp function changeSheet(n) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="script pages/changeSheet.php" url=url+"?q="+n xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("test").innerHTML=xmlHttp.responseText } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } 

changeSheet.php

 <?php error_reporting(E_ALL ^ E_NOTICE); require_once 'reader.php'; $data = new Spreadsheet_Excel_Reader("test.xls"); $q = $_GET['q']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo $data->dump(true,false, $sheet=$q); ?> </body> </html> 

附带的代码是PHP Excel Reader的库文件,我不相信是造成这个问题。

再一次,我感谢你们花时间阅读我的问题。 那么出了什么问题? 是什么原因导致表格不显示?

看起来你的Excel_Reader版本不支持“:: dump()”。

看起来你必须自己遍历表单,行和列。

试试var_dump($ data)来看看里面有什么。