何か書き込みたかろうて^^;

jquery.csv2table.jsのテーブル
http://oshiete.goo.ne.jp/qa/8767107.html

かなり汚い。統一性がない。
こんなんじゃ〜
ダメよ〜ダメダメ。


あっ!
正規表現は、format 側で行えば良かった!

<!DOCTYPE html>
<meta charset="utf-8">
<title>テーブルをn行に?</title>

<style>
th { color: green; width: 6em;}
thead, tfoot { background: #8c8;}
tbody th { background: #efe;}
.num { text-align : right; }
</style>

<body>
<table border="1" id="hoge"></table>

<script>


var D = /^(?:(?:(#)(?:\[(?:(\d+)(?:,(\d+)?)?)?\])?))?(.*)$/;//#[rowSpan,colspan]text


function C (a) {
  var b = D.exec (a), c;

  if (b[1]) {
    c = document.createElement ('th');
    c.textContent = b[4] || '';

    if (b[2])
      c.setAttribute ('rowSpan', b[2]);
    if (b[3])
      c.setAttribute ('colSpan', b[3]);
  }
  else {
    c = document.createElement ('td');
    c.textContent = a;
    if (! isNaN(a))
      c.className = ('num');
  }
  return c;
}


function B (a, b) {
  var c = document.createDocumentFragment ();
  var d = b.map (C);
  var i = 0, j, J, tr, m;
  
  for (i = 0; m = a[i++]; ) {
    tr = c.appendChild (document.createElement ('tr'));
    for (j = 0, J = m.length; j < J; j++) {
      tr.appendChild (d[m[j]])
    }
  }
  return c;
}



function A (a, b, c, d, e) {
  if (3 > arguments.length)
    throw new Error;
  
  var f = document, g;

  while (g = a.firstChild)
    a.removeChild (g);
  
  if (d)
    a.appendChild (f.createElement ('thead'))
     .appendChild (B (b, d));
  
  if (e)
    a.appendChild (f.createElement ('tfoot'))
     .appendChild (B (b, e));

  if (c)
    c.forEach (function (h) {
      a.appendChild (f.createElement ('tbody'))
       .appendChild (B (b, h));
    })
}

//______________

var body = [
  ['#[3]abcd',1,2,3,4,5,6,7,8,9],
  ['#[3]efgg',9,8,7,6,5,4,3,2,1]
];

var format = [
  [0, 1, 4, 7],
  [   2, 5, 8],
  [   3, 6, 9]
];

var head = ['#[3]Name', '#a', 'b', 'c', '#d', 'e', 'f', '#g', 'h', 'i'];
var foot = head;

A (document.getElementById ('hoge'), format, body, head, foot);

</script>