diff --git a/E06Eric.js b/E06Eric.js new file mode 100644 index 0000000..f649fc6 --- /dev/null +++ b/E06Eric.js @@ -0,0 +1,34 @@ +function geraTabelaHTML() { + + let tabela = document.getElementById("Tabela") + let textoCsvDesformatado = document.getElementById("FormularioRecebeCSV").value + let textoCsvDesformatadoString = textoCsvDesformatado.toString() + let csvDivididoEmLinhas = textoCsvDesformatadoString.split("\n") + let linhaInicial = csvDivididoEmLinhas[0].split(",") + let todosElementosString = csvDivididoEmLinhas.toString() + let todosElementosSeparados = todosElementosString.split(",") + let numeroTotalElementos = todosElementosSeparados.length + let numeroDeColunas = linhaInicial.length + let numerodeLinhas = numeroTotalElementos / numeroDeColunas + let indiceTableRow = 0 + function geraTrs() { + for (let i = 1; i < numerodeLinhas; i++) { + let tabelasSecas = document.createElement("tr") + tabela.append(tabelasSecas) + } + } + function geraTabela() { + for (i = 0; i <= numeroTotalElementos; i++) { + if (i % numeroDeColunas == 0 && i != 0) { + indiceTableRow++ + } + let tableRowAtual = tabela.getElementsByTagName("tr")[indiceTableRow] + let textNodeAtual = document.createTextNode(todosElementosSeparados[i]) + let tableDataAtual = document.createElement("td") + tableDataAtual.append(textNodeAtual) + tableRowAtual.append(tableDataAtual) + } + } + geraTrs() + geraTabela() +} diff --git a/sample1.txt b/sample1.txt new file mode 100644 index 0000000..fac20cc --- /dev/null +++ b/sample1.txt @@ -0,0 +1,8 @@ +nome,idade +ulisses,18 +eric,16 +machado,10 +Amanda,17 +Benvas,89 +claudio,11 +cordeio,19 diff --git "a/site\303\211ric.html" "b/site\303\211ric.html" new file mode 100644 index 0000000..17d7425 --- /dev/null +++ "b/site\303\211ric.html" @@ -0,0 +1,40 @@ + + +
+ + + +Insira a tabela CSV :
+Tabela CSV em HTML:
+ +