Olá tudo bom?
Tenho esse método para gerar um arquivo excel, queria dar uma melhorada nele só que não sei como...
alguém poderia me dar um help? Eu fiz assim pq mudam direto o que mandam para montar o arquivo, então fiz campo a campo
public void CriarPlanilhaGeraRelatorio(String id_v_sp,
String id_engine, String id_f_input, String id_ult_mensagem, String cod_dispositivo, String dt_hora_dispositivo, String grama, String login, HttpServletResponse response) throws Exception,
IOException, BiffException, ClassNotFoundException, SQLException {
// TÍTULO
// Adicionando formato de fonte no título..."
WritableFont bold0 = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.BOLD);
bold0.setColour(Colour.WHITE);
WritableCellFormat arial10fontVeic = new WritableCellFormat(bold0);
arial10fontVeic.setBackground(Colour.GREEN);
arial10fontVeic.setAlignment(Alignment.CENTRE);
arial10fontVeic.setBorder(Border.ALL, BorderLineStyle.MEDIUM, Colour.WHITE);
// SUBTÍTULOS
// Adicionando formato de fonte no subtítulo..."
WritableFont bold1 = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.BOLD);
bold1.setColour(Colour.WHITE);
WritableCellFormat arial10font = new WritableCellFormat(bold1);
arial10font.setBackground(Colour.BLUE);
arial10font.setAlignment(Alignment.CENTRE);
arial10font.setBorder(Border.ALL, BorderLineStyle.MEDIUM, Colour.BLACK);
// RESULTADO
// Adicionando formato de fonte resultados..."
WritableFont bold2 = new WritableFont(WritableFont.ARIAL, 10);
WritableCellFormat arial10fontResult = new WritableCellFormat(bold2);
arial10fontResult.setAlignment(Alignment.CENTRE);
arial10fontResult.setBorder(Border.ALL, BorderLineStyle.THIN,
Colour.BLACK);
NomeArquivoExcel arquivoExcelRelatorio = new NomeArquivoExcel();
File filename = arquivoExcelRelatorio.NomeExcelRelatorio(login);
File filename2 = new File(filename.toString());
if (!filename2.exists()) {
// Instanciando a classe q gera o novo arquivo do Excel
WritableWorkbook workbook = Workbook.createWorkbook(new File(
filename.toString()));
// Criando uma nova planilha
WritableSheet sheet = workbook.createSheet("Resultado 0", 0);
// TAMANHO DA COLUNA (col , tam)
sheet.setColumnView(0, 16);
sheet.setColumnView(1, 15);
sheet.setColumnView(2, 19);
sheet.setColumnView(3, 19);
sheet.setColumnView(4, 14);
sheet.setColumnView(5, 19);
// MERGE col - lin to col - lin
sheet.mergeCells(0, 0, 2, 0);
// col, lin
Label labelTitulo = new Label(0, 0, "GRAMA: " + grama, arial10fontVeic);
sheet.addCell(labelTitulo);
Label labelTitulo0 = new Label(0, 2, "V inst", arial10font);
sheet.addCell(labelTitulo0);
Label labelTitulo1 = new Label(1, 2, "Rot.", arial10font);
sheet.addCell(labelTitulo1);
Label labelTitulo2 = new Label(2, 2, "Nvl", arial10font);
sheet.addCell(labelTitulo2);
Label labelTituloUltMsg = new Label(3, 2, "Última Mensagem", arial10font);
sheet.addCell(labelTituloUltMsg);
Label labelTituloDisp = new Label(4, 2, "Dispositivo", arial10font);
sheet.addCell(labelTituloDisp);
Label labelTituloDt = new Label(5, 2, "Data Dispositivo", arial10font);
sheet.addCell(labelTituloDt);
int i = sheet.getRows();
// col, lin
Label label0 = new Label(0, i, id_v_sp, arial10fontResult);
sheet.addCell(label0);
Label label1 = new Label(1, i, id_engine, arial10fontResult);
sheet.addCell(label1);
Label label2 = new Label(2, i, id_f_input, arial10fontResult);
sheet.addCell(label2);
Label labelUltMsg = new Label(3, i, id_ult_mensagem, arial10fontResult);
sheet.addCell(labelUltMsg);
Label labelDisp = new Label(4, i, cod_dispositivo, arial10fontResult);
sheet.addCell(labelDisp);
Label labelDt = new Label(5, i, dt_hora_dispositivo, arial10fontResult);
sheet.addCell(labelDt);
// Escrevedo o arquivo em disco
workbook.write();
// Fechando a IO
workbook.close();
} else {
Workbook rw = Workbook.getWorkbook(new File(filename2.toString()));
WritableWorkbook wwb = Workbook.createWorkbook(
new File(filename2.toString()), rw);
WritableSheet sheet = wwb.getSheet(wwb.getNumberOfSheets() - 1);
int i = sheet.getRows();
int a = wwb.getNumberOfSheets();
if (i > 29999) {
sheet = wwb.createSheet("Resultado " + a, a + 1);
sheet = wwb.getSheet(a);
i = 1;
// col, lin
Label labelTitulo0 = new Label(0, 0, "V inst", arial10font);
sheet.addCell(labelTitulo0);
Label labelTitulo1 = new Label(1, 0, "Rot.", arial10font);
sheet.addCell(labelTitulo1);
Label labelTitulo2 = new Label(2, 0, "Nvl", arial10font);
sheet.addCell(labelTitulo2);
Label labelTituloUltMsg = new Label(3, 2, "Última Mensagem", arial10font);
sheet.addCell(labelTituloUltMsg);
Label labelTituloDisp = new Label(4, 2, "Dispositivo", arial10font);
sheet.addCell(labelTituloDisp);
Label labelTituloDt = new Label(5, 2, "Data Dispositivo", arial10font);
sheet.addCell(labelTituloDt);
}
// col, lin
Label label = new Label(0, i, id_v_sp, arial10fontResult);
sheet.addCell(label);
Label label1 = new Label(1, i, id_engine, arial10fontResult);
sheet.addCell(label1);
Label label2 = new Label(2, i, id_f_input, arial10fontResult);
sheet.addCell(label2);
Label labelUltMsg = new Label(3, i, id_ult_mensagem, arial10fontResult);
sheet.addCell(labelUltMsg);
Label labelDisp = new Label(4, i, cod_dispositivo, arial10fontResult);
sheet.addCell(labelDisp);
Label labelDt = new Label(5, i, dt_hora_dispositivo, arial10fontResult);
sheet.addCell(labelDt);
// Escrevedo o arquivo em disco
wwb.write();
// Fechando a IO
wwb.close();
}
}
