RosettaCodeData/Task/CSV-to-HTML-translation/Maxima/csv-to-html-translation-1.maxima
2015-02-20 00:35:01 -05:00

21 lines
749 B
Text

infile: "input.csv";
outfile: "table.html";
instream: openr(infile);
outstream: openw(outfile);
printf(outstream, "<TABLE border=\"1\">~%");
nr: 0;
while (line: readline(instream))#false do (
nr: nr + 1,
line: ssubst("&lt;", "<", line),
line: ssubst("&gt;", ">", line),
value_list: map(lambda([f], strim(" ", f)), split(line, ",")),
if nr=1 then printf(outstream, " <THEAD bgcolor=\"yellow\">") else printf(outstream, " <TBODY bgcolor=\"orange\">"),
printf(outstream, "<TR>"),
for value in value_list do printf(outstream, "<TD>~a</TD>", value),
printf(outstream, "</TR>"),
if nr=1 then printf(outstream, "</THEAD>~%") else printf(outstream, "</TBODY>~%"));
printf(outstream, "</TABLE>~%");
close(instream);
close(outstream);