Forum Moderators: phranque
Sorry about posting this in this section, wasn't sure which category it fell under. Hopefully the friendly webmaster will move it to where it belongs ;)
I'm very new to web design, and have just designed a site using CSS. It contains a lot of fairly large text filled tables, the information for which comes from one large Excel file. At the moment the tables are hard coded in HTML but I was wondering if there is any way I can create an automated procedure to populate these tables from the Excel file.
Any help would be greatly appreciated, but please keep it simple as I am new to this.
Thanks very much.
edit - I added some notes to show what cell I'm talking about, so you dont type anything between square brackets, like [cell A1] :) Just in case ;)
If you have some programming experience you can use Exel's Macros, which you write in Visual Basic.
Basically I just use the special Excel procedures and functions to navigate the spreadsheet and suck the data off into my own data structure.
You then just build a string with your data structure and html tags, and bingo you have you're code.
The advantage of this method is that (although its a pain to write initially) next month all you have to do is load your Macros and run it on the new sheet and its done.
1) Highlight the cells you want to capture in Excel. Ctrl-C (copy) the cells.
2) Open a blank MS Word doc, and "Edit > Paste Special", and choose "HTML Format".
3) Then go "File > Save as Webpage", and save the file as an .htm file.
Now you have the Excel data as an html file.
Haven't a chance to look at this properly yet. I did try out your suggestion NormalDude, but it creates massive code bloat (I'm talking like 3 pages of code of a 10 row sample table!). Thanks for the suggestion anyway.
Panic: how would I split the lines by tab? I don't have any experience in Perl...
ytswy: Your way is still sounding the best to me.
Still open to suggestions.
Thanks guys!
<?php
$file = file("data.txt");
print "<table>
<tr><td>Field 1</td><td>Field 2</td><td>Field 3</td></tr>";
foreach($file as $line){
$line = trim($line);
$split = split("\t",$line);
print "<tr><td>$split[0]</td><td>$split[1]</td><td>$split[2]</td></tr>";
}
print "</table>";
?>
If it's your first time dealing with programming, consider whether it is really worth learning more than the basics. If you prefer design (as suggested by your comment about CSS), I would recommend finding a programmer to do work-exchanges.