File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes problems during creation of excel report Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problems during creation of excel report" Watch "problems during creation of excel report" New topic
Author

problems during creation of excel report

madhavaram mahendra
Greenhorn

Joined: Mar 15, 2013
Posts: 1
<%@ page contentType = "application/vnd.ms-excel" pageEncoding="UTF-8"%>
<% response.setContentType("application/vnd.ms-excel"); %>
<%@ page language="java"%>
<%@ page import="java.sql.*,util.datasource.DAOUtils,javax.sql.DataSource,java.util.*" %>
<%@ page import="net.sf.jasperreports.engine.JasperExportManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperCompileManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperRunManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperPrint" %>
<%@ page import="net.sf.jasperreports.engine.JasperReport" %>
<%@ page import="net.sf.jasperreports.engine.JRResultSetDataSource" %>
<%@ page import="net.sf.jasperreports.engine.export.JRPdfExporter"%>
<%@ page import="net.sf.jasperreports.engine.xml.JRXmlLoader" %>
<%@ page import="net.sf.jasperreports.engine.xml.JRXmlDigesterFactory" %>
<%@ page import="net.sf.jasperreports.view.JasperViewer" %>
<%@ page import="net.sf.jasperreports.engine.util.*"%>
<%@ page import="net.sf.jasperreports.engine.*"%>
<%@ page import="net.sf.jasperreports.engine.design.JasperDesign" %>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*" %>
<%@ page import="java.io.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="net.sf.jasperreports.engine.util.JRLoader.*"%>
<%@ 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"%>
<%

Connection con = null;

try
{
con = DAOUtils.getDBConnectionPost();
System.out.println("---concon---"+con);
String filename="C:/Documents and Settings/Administrator/Desktop/Qualification.xls" ;
HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead=sheet.createRow((short)0);
rowhead.createCell((short)0).setCellValue("Qualification Id");
rowhead.createCell((short)1).setCellValue("Qualification Name");
rowhead.createCell((short)2).setCellValue("Qualification Short Name");
//Class.forName("org.postgresql.Driver");
//Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/aptourism06032013","postgres","postgres");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(" select * from HRMS_QUALIFICATION_MST ");
int i=1;
while(rs.next())
{
HSSFRow row=sheet.createRow((short)i);
row.createCell((short)0).setCellValue(rs.getString("qualification_id"));
row.createCell((short)1).setCellValue(rs.getString("qualification_name"));
row.createCell((short)2).setCellValue(rs.getString("qualification_short_name"));
i++;
}
FileOutputStream fileOut = new FileOutputStream(filename);
hwb.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
byte[] bytes = hwb.getBytes();


ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
//ouputStream.write(fileOut);
//ouputStream.flush();
//ouputStream.close();
try{
Runtime.getRuntime().exec("cmd /c start C:\\Documents and Settings\\Administrator\\Desktop\\Qualification.xls");
}catch(IOException e){
e.printStackTrace();
}
con.commit();
}
catch(Exception e)
{
if(con!=null)
{
con.rollback();
}
out.println("Exception-->"+e);
}
finally
{
DAOUtils.closeConnection(con);
//DAOUtils.closeStatement(st);
//DAOUtils.closeConnection(rs);
}
%>
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Welcome to CodeRanch! I see a block of code, but not what the problem is. What error do you get? See TellTheDetails for more information about what is useful to provide.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems during creation of excel report
 
Similar Threads
Export excel using jsp
How to connect to Open Office Database using JDBC connection in Java
Setting a Variable Cell size dynamically for Excel.
Rendering Excel spreadsheet in JSP OR via CSV File Download
JSP to Excel Conversion