public static String makeHTMLTable(String[][] table, String[] rowLabels, String[] colLabels) {
    StringBuilder buff = new StringBuilder();
    buff.append("<table class=\"auto\" border=\"1\" cellspacing=\"0\">\n");
    // top row
    buff.append("<tr>\n");
    buff.append("<td></td>\n"); // the top left cell
    for (int j = 0; j < table[0].length; j++) { // assume table is a rectangular matrix
      buff.append("<td class=\"label\">").append(colLabels[j]).append("</td>\n");
    }
    buff.append("</tr>\n");
    // all other rows
    for (int i = 0; i < table.length; i++) {
      // one row
      buff.append("<tr>\n");
      buff.append("<td class=\"label\">").append(rowLabels[i]).append("</td>\n");
      for (int j = 0; j < table[i].length; j++) {
        buff.append("<td class=\"data\">");
        buff.append(((table[i][j] != null) ? table[i][j] : ""));
        buff.append("</td>\n");
      }
      buff.append("</tr>\n");
    }
    buff.append("</table>");
    return buff.toString();
  }
public static String makeHTMLTable ( String [ ] [ ] table , String [ ] rowLabels , String [ ] colLabels ) { StringBuilder buff = new StringBuilder ( ) ; buff . append ( "<table class=\"auto\" border=\"1\" cellspacing=\"0\">\n" ) ; buff . append ( "<tr>\n" ) ; buff . append ( "<td></td>\n" ) ; for ( int j = 0 ; j < table [ 0 ] . length ; j ++ ) { buff . append ( "<td class=\"label\">" ) . append ( colLabels [ j ] ) . append ( "</td>\n" ) ; } buff . append ( "</tr>\n" ) ; for ( int i = 0 ; i < table . length ; i ++ ) { buff . append ( "<tr>\n" ) ; buff . append ( "<td class=\"label\">" ) . append ( rowLabels [ i ] ) . append ( "</td>\n" ) ; for ( int j = 0 ; j < table [ i ] . length ; j ++ ) { buff . append ( "<td class=\"data\">" ) ; buff . append ( ( ( table [ i ] [ j ] != null ) ? table [ i ] [ j ] : "" ) ) ; buff . append ( "</td>\n" ) ; } buff . append ( "</tr>\n" ) ; } buff . append ( "</table>" ) ; return buff . toString ( ) ; }
Returns an HTML table containing the matrix of Strings passed in.
The first dimension of the matrix should represent the rows, and the
second dimension the columns.