• Post Reply Bookmark Topic Watch Topic
  • New Topic

problems during creation of excel report  RSS feed

 
madhavaram mahendra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ 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
author & internet detective
Sheriff
Posts: 36453
457
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!