我正在尝试使用excel spreasheet中的数据来使用php填充html表。我是PHP的初学者。我试图使用其他问题的代码,它们很接近,但不是我需要的。 excel文档将由另一个人定期更新。
以下是我使用的代码示例:
$file = file("/calendar.txt");
print "<table>
<tr><td>Date</td><td>Start Time</td><td>Venue</td><td>Description</td></tr>";
foreach($file as $line){
$line = trim($line);
$split = mb_split("\t",$line);
print "<tr><td>$split[3]</td><td>$split[4]</td><td>$split[5]</td><td>$split[6]</td></tr>";
}
print "</table>";
?>
但上面的例子不允许自动填充。所以我尝试了这个:
<table>
<?php
if (($handle = fopen("/calendar.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
print "<tr><td> $data[$c] </td></tr>";
}
}
fclose($handle);
}
?>
</table>
但我无法得到我想要的专栏。另外两个示例都不允许在源文件的最后一列末尾创建新的行/列(即第一行中最后一列的数据与第二行的第一列组合)。
我还想回应一句话,“目前没有即将到来的日期。请尽快回来查看!”如果没有信息要显示。有没有办法在PHP中做一个colspan?以下是我失败的尝试:http://www.tonejones.com/calendar3.php
我希望表格看起来像这样:http://www.tonejones.com/calendar.php
答案 0 :(得分:1)
将数据从Excel填充到表格。首先我们需要将所有数据检索到Array然后我们将所有Array值呈现到table.Get引用以将数据检索到数组中。 https://www.studytutorial.in/how-to-upload-or-import-an-excel-file-into-mysql-database-using-spout-library-using-php。如果你得到数组,那么使用下面的代码
<table>
<?php foreach($rows as $value){ ?>
<tr>
<td><?php echo $value; ?></td>
</tr>
<?php } ?>
</table>
答案 1 :(得分:0)
你的区块应该绕过细胞集合,而不是每个单独的细胞:
print "<table>
<tr><td>Date</td><td>Start Time</td><td>Venue</td><td>Description</td></tr>";
<?php
if (($handle = fopen("/calendar.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
$num = count($data);
print "<tr>";
for ($c=3; $c < $num; $c++) {
print "<td> $data[$c] </td>";
}
print "<tr>";
}
fclose($handle);
} else {
print "<tr><tdcolspan="4">
There are no upcoming dates currently. Please check back soon!
</td></tr>";
}
?>
</table>