Tema: excel en jsp
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/03/2013, 11:09
abulon81
 
Fecha de Ingreso: mayo-2010
Mensajes: 99
Antigüedad: 14 años
Puntos: 5
Respuesta: excel en jsp

Wenas, pues yo una vez tuve que hacer algo parecido en Struts 1.x,
en mi jsp ponia

codigo javascript
Código PHP:

jQuery
('a[name=exportar]').click(function (){       
       
            
jQuery('#forma').attr("action",'<%=request.getContextPath()%>/repLevels.do?vinculo=exportarExcel');
            
jQuery"#dialogGraficas").dialog"close" );    
            
jQuery'#forma').submit();  
       
    }); 
en mi jsp tenia
Código PHP:

<div    class="   contSinTab "></div>
                    <
div class="right controles">
                    <
a   class="boton-rojo"  name="exportar" id="exportar"><bean:message key='sistema.createGraphic' /></a>
                   </
div
Y en el action

Código PHP:
public ActionForward exportarExcel(ActionMapping mappingActionForm forma
                        
HttpServletRequest requestHttpServletResponse response) {
        ........
        try {

ArrayList exportList=(ArrayList)request.getSession().getAttribute("nivelesList");
           .................
//mas codigo
             
             
report = new RepLevelsExcel();
            
            
report.process(request,responsetipografexportList,formtemp);
            
            
actionForward "success";
           
            
        } catch (
Exception e) {
            
            
actionForward "error";
        } 
finally {
            return (
mapping.findForward(actionForward));
        }
    } 
Y para el excel yo use plantillas
Código PHP:
..........//mas codigo

/** Excel file used as template  */
    
public static final String EXCEL_FILE_LEVELS "/plantilla_reportes/ReporteNivelesService.xls";
    
    public 
RepLevelsExcel() {
        
    }
    
    
/**Processes requests for both HTTP GET and POST methods.
     * @param request servlet request
     * @param response servlet response
     */
    
public void process(HttpServletRequest requestHttpServletResponse responseString graficasArrayList listaBeanForm formthrows ServletExceptionIOException {
                    
        
String[] abc = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        
        
HttpSession session request.getSession();
        
ServletContext context session.getServletContext();
        
String pathreal context.getRealPath(EXCEL_FILE_LEVELS);
        
        
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(pathreal));

        
HSSFWorkbook libro = new HSSFWorkbook(fs);
        
HSSFCell cel null;
        
hoja libro.getSheetAt(0);
        
        
hoja libro.getSheetAt(3);
        for (
int i1;i<=3;i++){
        
cel setCell(abc[1] + iform.getFechaSinIni()+" al "+form.getFechaSinFin());
        
        }
        
hoja libro.getSheetAt(2);

...............
//mas codigo

 
response.setContentType("application/xls"); 
        
Calendar cal Calendar.getInstance();
        
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy_HH:mm:ss");
        
response.setHeader("Content-disposition""attachment;filename=Services_"+sdf.format(cal.getTime())+".xls");
        
libro.write(response.getOutputStream()); 
Saludos, espero te ayude esto

Última edición por abulon81; 22/03/2013 a las 11:17