Thursday, September 6, 2012

Excel export With "save as Excel" Prompt from JSP



<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%      
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=\"report.xls\"");

%>
<sql:query var="result" dataSource="jdbcJNDI">
        
        select * FROM 
        X
        WHERE
        X.y = ? and X.z = ?
        
       
        
        <sql:param  value="${param.from}"/>
        <sql:param  value="${param.to}"/>
    </sql:query>
    <table border="1">
        <!-- column headers -->
        <tr>
        <c:forEach var="columnName" items="${result.columnNames}">
            <th><c:out value="${columnName}"/></th>
        </c:forEach>
    </tr>
    <!-- column data -->
    <c:forEach var="row" items="${result.rowsByIndex}">
        <tr>
        <c:forEach var="column" items="${row}">
            <td><c:out value="${column}"/></td>
        </c:forEach>
        </tr>
    </c:forEach>
</table>

Share Article : Excel export With "save as Excel" Prompt from JSP
Share/Save/Bookmark

CSV, how to avoid crappy auto-format in Excel



Output date as a String as following

"=\""+$F{dd/mm/yyyy date}+ "\""   (in jasper)


 "=""01/01/2012"""  (finally following will be generated)

Share Article : CSV, how to avoid crappy auto-format in Excel
Share/Save/Bookmark