HI All,
I have write a web enabled page to convert
jsp to excel file using with POI,and successful to do that.
My problem is that when user acess that web page at client computer the file is save at server instead of client machine.
I want to save the file at their machine.
Please help me...I'm failed to solve it. Following is my code.
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFPrintSetup"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
...............................
...............................
<% PreparedStatement ps=null;
Connection con=null;
ResultSet rs=null;
int i=0;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@172.16.90.139:1531:PROD","apps","apps");
String f_date=request.getParameter("f_date");
String t_date=request.getParameter("t_date");
ps=con.prepareStatement("SELECT PV.VENDOR_NAME VNAME,FV.DESCRIPTION STATE,to_char(AIA.GL_DATE,'dd-mon-yyyy') GL_DATE,to_char(AIA.INVOICE_DATE,'dd-mon-yyyy') INV_DATE,AIA.INVOICE_NUM INV_NUM,AID.DISTRIBUTION_LINE_NUMBER LINE_NO,AID.AMOUNT AMOUNT, "+
"SUM(ROUND((NVL(AID.AMOUNT,0)*NVL((JIT.TAX_RATE),0)*0.01),0)) WCT FROM AP_INVOICE_DISTRIBUTIONS_ALL AID,AP_INVOICES_ALL AIA, "+
"JA_IN_TAX_CODES JIT,PO_VENDORS PV,FND_FLEX_VALUES_VL FV,GL_CODE_COMBINATIONS GLCC WHERE AIA.INVOICE_ID=AID.INVOICE_ID "+
"AND AIA.ACCTS_PAY_CODE_COMBINATION_ID=GLCC.CODE_COMBINATION_ID AND GLCC.SEGMENT3=FV.FLEX_VALUE AND FV.FLEX_VALUE_SET_ID='1009606' "+
"AND AID.ATTRIBUTE_CATEGORY='India Distributions' AND AID.ATTRIBUTE2 IS NOT NULL AND AID.ATTRIBUTE2=JIT.TAX_ID AND PV.VENDOR_ID=AIA.VENDOR_ID "+
"AND AIA.GL_DATE >=? AND AIA.GL_DATE <=? "+
"GROUP BY PV.VENDOR_NAME,FV.DESCRIPTION,AID.DISTRIBUTION_LINE_NUMBER,AID.AMOUNT,AIA.GL_DATE, "+
"AIA.INVOICE_DATE,AIA.INVOICE_NUM ORDER BY AIA.GL_DATE,AIA.INVOICE_NUM ");
ps.setString(1,f_date);
ps.setString(2,t_date);
rs=ps.executeQuery();
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFSheet sheet1 = hwb.createSheet("second sheet");
HSSFRow rows = sheet.createRow((short)0);
HSSFCell cells = rows.createCell((short)0); cells.setCellValue("Vendor Name:");
...................
.....................
while(rs.next())
try{
i++;
{
HSSFRow row = sheet.createRow((short)0+i);
HSSFCell cell = row.createCell((short)0); cell.setCellValue(rs.getString(1));
HSSFCell cell1 = row.createCell((short)1); cell1.setCellValue(rs.getString(2));
}
FileOutputStream fileOut = new FileOutputStream("c:\\excel\\wct.xls");
hwb.write(fileOut);
fileOut.close();
}
catch ( Exception ex )
{
}
out.println("Your excel file has been generated,please see C drive:");
%>