Reading multiple Excel Lines
Posted: Tue Apr 26, 2011 3:41 pm
I have a php file that downloads a csv file from an external website. It prints the first line of the file (header) into a table, then searches through the file for a string match, and prints the line that the match appears on. So essentially, I end up with a 2 row table with a header row and the data I'm looking for.
Now what I need to get is the current row that is being printed and the previous 20 rows in the excel sheet. I'm assuming I need a for loop, however, I don't know how to get the current row that the data was located on.
Thanks in advance for your help.
Tony.
Code: Select all
$fp = fopen($fullFileName,'r') or die("can't open file");
print "<table>\n";
while($csv_line = fgetcsv($fp,1024)) {
if($csv_line[1] == "Target") {
print '<tr>';
for ($i = 1, $j = count($csv_line); $i < $j; $i++) {
print '<td>'.$csv_line[$i].'</td>';
}
print "</tr>\n";
}
if ($csv_line[3] == $bandwidthTime) {
print '<tr>';
for ($i = 1, $j = count($csv_line); $i < $j; $i++) {
print '<td>'.$csv_line[$i].'</td>';
}
print "</tr>\n";
}
}
print '</table>';
Thanks in advance for your help.
Tony.