This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to extract data from html page to excel sheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to extract data from html page to excel sheet" Watch "how to extract data from html page to excel sheet" New topic
Author

how to extract data from html page to excel sheet

Abhilash Boinapally
Greenhorn

Joined: Jun 13, 2006
Posts: 8
i have written the following code but i am getting an error please tell me the solution

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import org.apache.poi.hssf.usermodel.* ;
import org.apache.poi.hssf.dev.* ;
import org.apache.poi.hssf.util.* ;


public class FirstServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("application/vnd.ms-excel");
res.setHeader("Content-disposition","attachment;filename=Web_Transact_Report.xls");
//res.setContentType("text/html"); //MIME
PrintWriter out = res.getWriter(); //Character Stream to Browser
out.println("<HTML>");
out.println("<body>");
out.println("<H1>Welcome</h1>");
out.println("<table border=1>");
out.println("<tr>");
out.println("<td>slno</td>");
out.println("<td>name</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td>1</td>");
out.println("<td>Abhilash</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td>2</td>");
out.println("<td>Sarvana</td>");
out.println("</tr>");
out.println("</th>");
out.println("</table>");
System.out.println("Going to create Excel file");
int rownum = 0 ;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Transaction Report");
System.out.println("Going to create rows");
HSSFRow row = sheet.createRow((short)rownum);
rownum++;
/*HSSFCellStyle headerStyle = wb.createCellStyle();
HSSFFont headerfont = wb.createFont();
headerfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerfont.setColor((short)9);
headerfont.setFontName("Arial");
headerStyle.setFont(headerfont);
headerStyle.setFillBackgroundColor((short)18);
headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);*/
HSSFCell cel ;
cel = row.createCell((short)0);
cel.setCellValue("Slno");
//cel.setCellStyle(headerStyle);
cel = row.createCell((short)1 );
cel.setCellValue("Name");
//cel.setCellStyle(headerStyle);
System.out.println("writing data to response");
wb.write(res.getOutputStream());
out.println("</body></html>");
}
}

error:
exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.createRow(S)Lorg/apache/poi/hssf/usermodel/HSSFRow;
FirstServlet.doGet(FirstServlet.java:41)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Abhilash Boinapally
Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.



I think this pretty much sums up your problem:


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Also, you're not going to be able to send both a text/html stream and a binary Excel sheet back in one response.
 
jQuery in Action, 2nd edition
 
subject: how to extract data from html page to excel sheet