Descargar y dar formato a un excel Buenos dias tengo un codigo que genera un excel pero lo genera sin formato sin titulos de los campos y se genera en el servidor, entonces yo quiero remediar eso haciendo que tenga titulos de los campos, que tenga un buen formato de autoajustar al texto y que se descargue a la pc de quien lo genere mi codigo es asi
Código Java:
Ver originalFile file = new File("//home//juridico//Generado.xls"); public Generar_Consulta(){ this.url = "jdbc:mysql://localhost/"+this.db; try{ Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager. getConnection( this. url, this. user , this. password ); if ( conn!=null ){ System. out. println("Conexión a la base de datos "+this. db+"...... Listo "); } System. err. println( e. getMessage() ); System. err. println( e. getMessage() ); } } public void WriteExcel (String anhos ){ int row=0; WritableFont wf = new WritableFont( WritableFont.ARIAL, 12, WritableFont.NO_BOLD ); WritableCellFormat cf = new WritableCellFormat(wf); //Interfaz para una hoja de cálculo WritableSheet excelSheet = null; WritableWorkbook workbook = null; //Establece la configuración regional para generar la hoja de cálculo WorkbookSettings wbSettings = new WorkbookSettings(); wbSettings. setLocale(new Locale("en", "EN")); try { workbook = Workbook.createWorkbook( file, wbSettings ); //hoja con nombre de la tabla workbook.createSheet( "convenios", 0 ); excelSheet = workbook.getSheet(0); System. out. println( "creando hoja excel.....Listo" ); System. err. println( ex. getMessage() ); } //Consulta SQL String sql = ("select convenios.folio, convenios.contra_pa, convenios.desc_ser, convenios.total_civa, convenios.total_siva, convenios.f_ini, convenios.f_conclu, convenios.f_rec, convenios.f_vobo, convenios.f_ent_catn, convenios.reg_res, convenios.entre_a, convenios.rubx, convenios.obs, convenios.orig, convenios.anhos, res_contra.nombre, res_contra.cargo, res_contra.direccion, res_contra.tel, tipo_doc.tipo_doc, subcoord.nomb_subc, tipo_rec.tipo_recu, clasif_recu.clasi, clasif_recu.tipo_clasi, fianza.fianza, coord.nomb_coord, nacionalidad.nacionalidad from convenios join res_contra on res_contra.id_resp=convenios.id_resp join tipo_doc on tipo_doc.id_tipo_doc=convenios.id_tipo_doc join subcoord on subcoord.id_subc=convenios.id_subc join tipo_rec on tipo_rec.id_recu=convenios.id_recu join clasif_recu on clasif_recu.id_clasi=convenios.id_clasi join fianza on fianza.id_fian=convenios.id_fian join coord on coord.id_coord=convenios.id_coord join nacionalidad on nacionalidad.id_nac=convenios.id_nac where convenios.anhos = "+anhos +""); try{ System. out. println( "obteniendo registros.....Listo" ); while(res.next()){ jxl. write. Label ci = new jxl. write. Label(27, row, res. getString("anhos"), cf ); Label folio = new Label(1, row, res. getString("folio") , cf ); Label tipo_rec = new Label (2, row, res. getString("tipo_recu") , cf ); Label clasi = new Label(3, row, res. getString("clasi") , cf ); Label nomb_coord = new Label(4, row, res. getString("nomb_coord") , cf ); Label contra_pa = new Label (5, row, res. getString("contra_pa") , cf ); Label nomb_subc = new Label(6, row, res. getString("nomb_subc") , cf ); Label nombre = new Label (7, row, res. getString("nombre") , cf ); Label cargo = new Label (8, row, res. getString("cargo") , cf ); Label direccion = new Label (9, row, res. getString("direccion") , cf ); Label tel = new Label (10, row, res. getString("tel") , cf ); Label tipo_doc = new Label (11, row, res. getString("tipo_doc") , cf ); Label desc_ser = new Label (12, row, res. getString("desc_ser") , cf ); Label total_civa = new Label (13, row, res. getString("total_civa") , cf ); Label total_siva = new Label (14, row, res. getString("total_siva") , cf ); Label f_ini = new Label (15, row, res. getString("f_ini") , cf ); Label f_conclu = new Label (16, row, res. getString("f_conclu") , cf ); Label f_rec = new Label (17, row, res. getString("f_rec") , cf ); Label f_vobo = new Label (18, row, res. getString("f_vobo"), cf ); Label f_ent_catn = new Label (19, row, res. getString("f_ent_catn") , cf ); Label reg_res = new Label (20, row, res. getString("reg_res") , cf ); Label nacionalidad = new Label(21, row, res. getString("nacionalidad") , cf ); Label fianza = new Label (22, row, res. getString("fianza") , cf ); Label entre_a = new Label (23, row, res. getString("entre_a"), cf ); Label rubx = new Label(24, row, res. getString("rubx") , cf ); Label obs = new Label(25, row, res. getString("obs") , cf ); Label orig = new Label (26, row, res. getString("orig") , cf ); row++; try{ excelSheet.addCell(ci); excelSheet.addCell(folio); excelSheet.addCell(tipo_rec); excelSheet.addCell(clasi); excelSheet.addCell(nomb_coord); excelSheet.addCell(contra_pa); excelSheet.addCell(nomb_subc); excelSheet.addCell(nombre); excelSheet.addCell(cargo); excelSheet.addCell(direccion); excelSheet.addCell(tel); excelSheet.addCell(tipo_doc); excelSheet.addCell(desc_ser); excelSheet.addCell(total_civa); excelSheet.addCell(total_siva); excelSheet.addCell(f_ini); excelSheet.addCell(f_conclu); excelSheet.addCell(f_rec); excelSheet.addCell(f_vobo); excelSheet.addCell(f_ent_catn); excelSheet.addCell(reg_res); excelSheet.addCell(nacionalidad); excelSheet.addCell(fianza); excelSheet.addCell(entre_a); excelSheet.addCell(rubx); excelSheet.addCell(obs); excelSheet.addCell(orig); } catch (WriteException ex) { System. err. println( ex. getMessage() ); } } res.close(); System. err. println( e. getMessage() ); } //Escribe el archivo excel en disco try { workbook.write(); workbook.close(); System. out. println( "Escribiendo en disco....Listo" ); System. err. println( ex. getMessage() ); } catch (WriteException ex) { System. err. println( ex. getMessage() ); } System. out. println( "Proceso completado...." ); }
__________________ "Las piedras me las quito caminando y las pedradas tambien" |