Next page | Contents page |

Exercise 11 - CSV to HTML

Write class CSV2HTML, to read a comma-separated value (CSV) file and convert it to HTML. The file profits.csv has been saved from a rectangular table in Excel. Output the values as HTML in file profits.html:

	<html><head><title>title</title></head>
	<body>
	<table border="1">
	<tr><td>value</td><td>value</td>... </tr>     Row 1
	<tr><td>value</td><td>value</td>... </tr>     Row 2
	...						etc
	</table>
	</body>
	</html>

Then display this HTML page in a browser.

The file profits.csv contains:

Profit after tax (£M),,,,,
Year,Q1,Q2,Q3,Q4,
2001,200,104,54,23,
2002,-10,3,49,30,
2003,120,98,67,40,
2004,134,105,74,52,
2005,202,107,69,61,
2006,197,163,94,58,

Make your application flexible enough that the number of columns and rows in the table could be different, to work with any CSV file.

Hint: String.split () could be useful

Next page | Contents page |