This is a jsp report. When i export the report data to an excel, the parameter values on the html report do not match those in the downloaded spreadsheet, specifically, if the parameter value is ALL, it gets translated to NO in excel.
This is the my jsp code -
<%@ page contentType="text/html;charset=windows-1252"%> <%@ page errorPage="errorPage.jsp" %> <%@ page import="com.dab.dabuilderConstants"%> <jsp:useBean id="paramForm" scope="application" class = "com.dab.dabFormParameter" /> <html> <% dabuilderConstants cConstants = new dabuilderConstants(); %> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <STYLE type="text/css"> .error{ font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: red; font-weight: bold; text-align: left; } .GG {BACKGROUND-COLOR:#FFFFCC;BORDER:1px solid #96965E;PADDING:5px;MARGIN-TOP:12px;MARGIN-BOTTOM:12px} </style> <title><%=cConstants.sHrrchyReport%></title> <script language="javascript"> errorMessages = new Array(); visibleFlag=false; i=0; function doSubmit(){ document.forms[0].submit(); } function addError(erMsg){ errorMessages[i++] = erMsg; } function displayErrors(){ var allMsgs = ''; for(var j=0; j<errorMessages.length; j++){ allMsgs += errorMessages[j]; } document.getElementById("errorBody").style.visibility = 'visible'; visibleFlag=true; document.getElementById("msgs").innerHTML=allMsgs; } function clearErrors(){ if(visibleFlag==false){ document.getElementById("errorBody").style.visibility='hidden'; } } </script> </head> <body onload="javascript:clearErrors();"> <span id="errorBody"> <table width=80% border=0 align="center" cellspacing=0 cellpadding=0 class="GG"> <tr bgcolor="#FFFFCC"><td></td></tr> <tr bgcolor="#FFFFCC"> <td class="error"><span id="msgs"></span></td></tr> </table> </span> <% if(paramForm.getErrorMessage()!=null){ String errs=paramForm.getErrorMessage(); %> <script language="javascript"> addError('<%=errs%>'); displayErrors(); </script> <% } paramForm.setErrorMessage(null); %> <% String permission=null; String path=session.getServletContext().getRealPath("/"); if(request.getSession().getAttribute("eUserName")!=null){ permission=request.getSession().getAttribute("eUserName")+""; paramForm.test(request.getSession().getAttribute("eUserName")+"",request.getSession().getAttribute("ePassword")+""); paramForm.loadObjects(request.getParameter("reportName")+"",path); }else{ response.sendRedirect("check.jsp"); } %> <tr> <td colspan="2"><br><label title="Granted Functions">Display Granted Functions?� � � � </label> <select id="gfns" tabindex="3" property="grantedFns" name="grantedFns"> <option value="All" selected="selected">All</option> <option value="Yes">Yes</option> <option value="No">No</option> </select> <label title="Granted Menu">[Yes = Display only form functions granted to menus]� � � � </label> </td> </tr> <tr> <td colspan="2"><br><label title="Query Functions">Display Query Only Functions?� � � </label> <select id="qfns" tabindex="3" property="QueryFns" name="QueryFns"> <option value="All" selected="selected">All</option> <option value="Yes">Yes</option> <option value="No">No</option> </select> <label title="Query Function"> [Yes = Display only "Query Only" form functions]� � � � </label><br> </td> </tr> <tr> <td colspan="2"><br><label title="Excluded Menus">Display Excluded Menus?� � � </label> <select id="exmns" tabindex="3" property="exMenus" name="exMenus"> <option value="Yes">Yes</option> <option value="No">No</option> <option value="All" selected="selected">All</option> </select> <label title="Excluded Menus"> [Yes = Display only excluded menus and functions]� � � � </label> <br> </td> </tr> <tr align="right"> <td> <button onclick="javascript:doSubmit()"> <LABEL>Submit Query</LABEL> </button>� � <button type="reset"> <LABEL>Reset</LABEL> </button> <input type="HIDDEN" id="selectedValue" value="<%=cConstants.sHrrchyReport%>" name="reportName"> </td> </tr> </table> </div> </form> </body> </html>
1)form.jsp:
<html> <body> <form name="userform" method="post" action="excelFile.jsp"> <table> <tr><td>Enter First Name:</td><td><input type="text" name="firstName"></td></tr> <tr><td>Enter Last Name:</td><td><input type="text" name="lastName"></td></tr> <tr><td>Enter User Name:</td><td><input type="text" name="userName"></td></tr> <tr><td>Enter Address:</td><td><input type="text" name="address"></td></tr> <tr><td>Enter Email ID:</td><td><input type="text" name="email"></td></tr> <tr><td>Enter DOB:</td><td><input type="text" name="dob"></td></tr> <tr><td><input type="submit" value="Export to excel"></td></tr> </table> </form> </body> </html>
2)excelFile.jsp
<%@page import="java.io.*"%> <%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%> <%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%> <%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%> <%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%> <% String value1=request.getParameter("firstName"); String value2=request.getParameter("lastName"); String value3=request.getParameter("userName"); String value4=request.getParameter("address"); String value5=request.getParameter("email"); String value6=request.getParameter("dob"); try{ HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Excel Sheet"); HSSFRow rowhead = sheet.createRow((short)0); rowhead.createCell((short) 0).setCellValue("First Name"); rowhead.createCell((short) 1).setCellValue("Last Name"); rowhead.createCell((short) 2).setCellValue("User Name"); rowhead.createCell((short) 3).setCellValue("Address"); rowhead.createCell((short) 4).setCellValue("E-mail Id"); rowhead.createCell((short) 5).setCellValue("Date Of Birth"); HSSFRow row = sheet.createRow((short)1); row.createCell((short)0).setCellValue(value1); row.createCell((short)1).setCellValue(value2); row.createCell((short)2).setCellValue(value3); row.createCell((short)3).setCellValue(value4); row.createCell((short)4).setCellValue(value5); row.createCell((short)5).setCellValue(value6); FileOutputStream fileOut = new FileOutputStream("c:\\File.xls"); wb.write(fileOut); fileOut.close(); out.println("Data is saved in excel file."); }catch ( Exception ex ){ } %>