获取最新的excel文件,并使用php excel reader将其转换为html
你能帮我吗?我不知道该放什么,也不知道该从什么开始解决这个问题 我有一个excel阅读器,它工作正常,将我的excel转换成html,我有一个代码可以检测目录中的最新文件 我的问题是,我应该使用什么代码来显示或获取目录中使用php excel reader的最新excel文件 这是我的密码。请帮帮我获取最新的excel文件,并使用php excel reader将其转换为html,php,html,excel,Php,Html,Excel,你能帮我吗?我不知道该放什么,也不知道该从什么开始解决这个问题 我有一个excel阅读器,它工作正常,将我的excel转换成html,我有一个代码可以检测目录中的最新文件 我的问题是,我应该使用什么代码来显示或获取目录中使用php excel reader的最新excel文件 这是我的密码。请帮帮我 <?php class ReportViewer { public $extension = array ( 'xlsx', 'xls', 'html', 'htm', '
<?php
class ReportViewer
{
public $extension = array ( 'xlsx', 'xls', 'html', 'htm', 'csv' );
public function getLatestReport($report)
{
$reports_directory = preg_split("/[\-]/", $report);
//$latest_files = array();
if (!ctype_alpha($report))
$directory = $reports_directory[0].'/'.$reports_directory[1];
else
$directory = $reports_directory[0];
$dir_contents = new RecursiveDirectoryIterator($directory);
foreach (new RecursiveIteratorIterator($dir_contents) as $filename => $file)
{
if (preg_match("/\.(" . implode("|", $this->extension) . ")*$/i", $file->getFileName()/*, $filename*/))
{
$latest_files[$file->getMTime()] = array($directory, $file->getFileName(), $file->getPath());
//echo $file->getFileName() . "\n";
}
}
krsort($latest_files);
//print_r($latest_files);
// print_r($timeMod);
return $latest_files;
}
}
?>
<html>
<head>
<style type="text/css">
table {
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 0 0.5em;
}
</style>
</head>
<body>
<?php
include 'reader.php';
$excel = new Spreadsheet_Excel_Reader();
$lastest = new ReportViewer();
?>
Sheet 1:<br/><br/>
<table>
<?php
$excel->read('battery-report.xls');
$x=1;
while($x<=$excel->sheets[0]['numRows']) {
echo "\t<tr>\n";
$y=1;
while($y<=$excel->sheets[0]['numCols']) {
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
echo "\t\t<td>$cell</td>\n";
$y++;
}
echo "\t</tr>\n";
$x++;
}
?>
</table><br/>
</body>
</html>
桌子{
边界塌陷:塌陷;
}
运输署{
边框:1px纯黑;
填充:0.5em;
}
第1页:
您将从getLatestReport()
返回一个数组,因此请将列表中的第一个文件用于excel阅读器。如果您可以返回唯一所需的文件名表单getLatestReport()
,则只需使用$excel->read($lastest->getLatestReport('battery-report.xls')代码>
试试这个
<table>
<?php
$latestFiles=$lastest->getLatestReport('battery-report.xls');
$excel->read($latestFiles[0]);
$x=1;
谢谢bansi,真是帮了大忙