/** You may copy this example and use it for any purpose, commercial or otherwise. */ import com.ricebridge.csvman.CsvManager; import java.util.*; import java.io.*; /** Load a CSV file and convert it into a HTML file. */ public class LoadPlays { /** Everything happens in the main method. */ public static void main( String[] args ) throws Exception { // load the csv data directly CsvManager csvman = new CsvManager(); List data = csvman.load( "plays.csv" ); // build the HTML table StringBuffer htmlTable = new StringBuffer("\n"); for( int line = 0; line < data.size(); line++ ) { htmlTable.append( "\n" ); // the CSV data was loaded as List of String[] arrays String[] fields = (String[]) data.get(line); for( int field = 0; field < fields.length; field++ ) { String celltype = (0==line?"th":"td"); htmlTable.append( "<"+celltype+" align=\"left\">"+fields[field]+"\n" ); } htmlTable.append( "\n" ); } htmlTable.append( "
\n" ); // save the HTML file FileWriter htmlFile = new FileWriter( "plays.htm" ); htmlFile.write( htmlTable.toString() ); htmlFile.close(); System.out.println( "converted plays.csv to plays.htm" ); } }