Gerando .doc com java

13 respostas
W

PESSOAL to com um problema muiiiiiiiiiitoooooooooo grade, é assim:

Primeiro :

Tenho duas tabela, uma com o campo chamado time1 e outra time2 (time1 = hora de entra e time2 = hora de saida) queria saber como subtraiu os dois campos onde o BD é Mysql e são do tipo datatime.

Segundo:

o resultado dessa pesquisa queria gerar um arquivo .doc.

Sei que isso é complicado mas se alguem tiver uma idéia de como fazer issu já me ajudaria d+ no meu projeto que é para ontem… :grin:

Valeus…

13 Respostas

A

olha, num entendi bem o q vc quer com relação ao tempo, mais ve c isto ajuda…

criei a tabela datas:

depiois q a tabela estiver povoada, faz o seguinte

isto vai te retornar a diferença entre os tempos em segundo…

espero q isto de de uma luz…Inté Mais

A

cara eu nunca fiz nada relacionado a doc… masi c te interessar eu sei como gerar o pdf (serve???)

A

e para vc q esta fazendo em tabelas diferente pode ficar assim...

[code]CREATE table tabela1 (idtabela1 int , tempo1 TIME)[code]

[code]CREATE table tabela2 (idtabela2 int , tempo2 TIME)[/code]

e a busca funcionaria assim:

[code]SELECT TIME_TO_SEC(t2.tempo2 - t1.tempo1) as tempoFinal from tabela1 t1, tabela2 t2 WHERE t1.idtabela1 = t2.idtabela2[/code]

onde o tempoFinal é a diferença entre os tempos em segundo

Inté +

W

pode ser PDF sim, quero algo que fique em docs

A

eo a parte do tempo serviu??? depois eu te passo os dados parta gerar o PDF… agra tenho uma reunião… mais tarde eu volto… inté +

A

bom, rapidão q ainda estou oculpado… faz o seguinte, vamos usar o itext (uma biblioteca Java para criação de arquivos *.pdf)… vê c vc consegue baixar-lo … c vc num conseguir me passe teu email q eu te passo… depois eu passo mais detales (é só me desoculpar um pouco…) …

Inté +

W

me passa no e-mail

[email removido]

A

bom, eu ja te enviei o itext

A

ai esta uma aplicação q esta gerando um arquivo pdf....

eu crie uma tabela como mais ou menos vc quer....

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document; 
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfWriter;


public class pdfTeste {

	    public static void main(String[] args) { 
	        System.out.println("Gerei o Arquivo PDF"); 
	        Document document = new Document(); 

	        try { 
	        	PdfWriter.getInstance(document, new FileOutputStream("relatório.pdf")); 
	            document.open(); 
	            Paragraph par = new Paragraph(new Chunk("Relatório de Horário",FontFactory.getFont(FontFactory.TIMES_ROMAN,18,Font.BOLD)));
	            par.setAlignment("center");
	            document.add(par);
	            Table table = new Table(6,2); 
			    table.setBorderWidth(1);
			    table.setWidth(100);
			    table.setBorderColor(new Color(0, 0, 0)); 
			    
			    Cell cell = new Cell(new Chunk("Horário de entrada", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2);
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("Horário de Saida", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("Tempo de Trabalho", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
			    
			    
			    cell = new Cell(new Chunk("16:00", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2);
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("18:00", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("14400", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
	            
			    document.add(table);
			    document.add(new Paragraph("Ai esta um artquivo gerado em PDF")); 
	        } 
	        catch(DocumentException de) { 
	            System.err.println(de.getMessage()); 
	        } 
	        catch(IOException ioe) { 
	            System.err.println(ioe.getMessage()); 
	        } 
	        document.close(); 
	    } 



}
[/code]
A

ai esta uma aplicação q esta gerando um arquivo pdf…

eu crie uma tabela como mais ou menos vc quer…

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document; 
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfWriter;


public class pdfTeste {

	    public static void main(String[] args) { 
	        System.out.println("Gerei o Arquivo PDF"); 
	        Document document = new Document(); 

	        try { 
	        	PdfWriter.getInstance(document, new FileOutputStream("relatório.pdf")); 
	            document.open(); 
	            Paragraph par = new Paragraph(new Chunk("Relatório de Horário",FontFactory.getFont(FontFactory.TIMES_ROMAN,18,Font.BOLD)));
	            par.setAlignment("center");
	            document.add(par);
	            Table table = new Table(6,2); 
			    table.setBorderWidth(1);
			    table.setWidth(100);
			    table.setBorderColor(new Color(0, 0, 0)); 
			    
			    Cell cell = new Cell(new Chunk("Horário de entrada", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2);
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("Horário de Saida", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("Tempo de Trabalho", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
			    
			    
			    cell = new Cell(new Chunk("16:00", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2);
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("18:00", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
			    
			    cell = new Cell(new Chunk("14400", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD, new Color(0, 0, 0))));
			    cell.setColspan(2); 
			    table.addCell(cell);
	            
			    document.add(table);
			    document.add(new Paragraph("Ai esta um artquivo gerado em PDF")); 
	        } 
	        catch(DocumentException de) { 
	            System.err.println(de.getMessage()); 
	        } 
	        catch(IOException ioe) { 
	            System.err.println(ioe.getMessage()); 
	        } 
	        document.close(); 
	    } 



}
A

c tiver uma duvida é só perguntar… falou???

Inté mais.,

A

só, um aperguntinha, vc esta usando Servlet??? c cv estiver usando, da para vc abrir diretamente no browser o arquvo pdf… falou???

Inté +

T

Me manda esse pacote de criar PDF tambem???

[email removido]

valeu

Criado 15 de setembro de 2004
Ultima resposta 9 de mar. de 2005
Respostas 13
Participantes 3