codigo JAVA -> criar tabela HTML.

p!nk.

Power Member
bons dias malta, é o seguinte ... tou a fazer um programa, que lendo de um .txt atraves de programaçao JAVA, crie um file uma tabela com os resultados em .html

o codigo do metodo é este:

Código:
 private static void escreverHTML(int x, String[] nomecidades, int[][] pluviosidade) throws FileNotFoundException {
        String msg = "";
        msg += "<html><head><title>Mapa Pluviosidade 2007</title></head><body>";
        msg += "Mapa da Pluviosidade em 2007<br>";
        msg += "Cidade     Janeiro    Fevereiro    Marco    Abril    Maio    Junho    Julho    Agosto    Setembro    Outubro    Novembro    Dezembro<br>";
        for (int l = 0; l < nomecidades.length; l++) {
            msg += nomecidades[l] + "    ";
            for (int c = 0; c < 12; c++) {
                msg += pluviosidade[l][c] + "    ";
            }
            msg += "<br>";
        }
        msg += "<br></body>\n</html>";
        Formatter fOut;
        fOut = new Formatter(new File("pluviosidade.html"));
        fOut.format("%s", msg);
        fOut.close();
    }

mas assim, ele cria um .html deste genero:



podem dar uma ajuda???
 
ya ... eu sei que tenho que criar uma tabela em html, mas ,tipo:

eu vou mecher com uma matriz com colunas a serem MESES e linhas a serem VALORES
e queria criar uma tabela do genero:

JANEIRO FEVEREIRO MARÇO (etc...)
xxx xxx xx
xxx xxxx xxxx
 
Tenta algo assim:
Código:
#include <stdio.h>

int main() {
    char* meses[12] = {"Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"};
    FILE *fp;
    int i,j;
    fp = fopen("pluviosidade.html","w");
    if (!fp)
       exit(1);
    fprintf(fp,"<html><head><title>Mapa Pluviosidade 2007</title></head><body>");
    fprintf(fp,"<table><tr>");
    fprintf(fp,"<th>Cidade</th>");
    for (i=0;i<12;i++)
        fprintf(fp,"<th>%s</th>",meses[i]);
    fprintf(fp",</tr><tr>");
    //para cada cidade do array com as cidades
        //percorres todos os valores de pluviosidade dessa cidade
           fprintf(fp,"<td>%s</td><td>%d</td>",nome_da_cidade,valor_pluviosidade);
    fprintf(fp,"</tr></table></body></html>");
    return 0;
}

Isto está em C, mas é parecido com Java. Não sei se dá direito mas experimenta.
 
Back
Topo