Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to extract data from html page to excel sheet

 
Abhilash Boinapally
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you're not going to be able to send both a text/html stream and a binary Excel sheet back in one response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic