Advertisement

12.29.2004 at 05:05AM PST, ID: 21256241
[x]
Attachment Details

Retrieve data from Excel file

Asked by surajguptha in Java Programming Language

Tags: excel, data, from, file, retrieve

i am trying to retrieve data from an Excel file using servlet  
could you please tell me why this code does not work.i dont get any error while i compile,i dont get any output as well.
my code

package mypackage1;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.model.*;
import org.apache.poi.hssf.usermodel.*;
  //org.apache.poi.hssf.usermodel.HSSFCell

import org.apache.poi.hssf.util.*;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import jxl.*;

 public class Test2 extends HttpServlet {
 
  public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
  {
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");
//String path = getServletContext().getRealPath("/Book1.xsl");

try {
//FileReader objFile =new FileReader("C:/Book1.xls");
//POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("C:/Book1.xls"));
     // System.out.println(fs);
//POIFSReader pfr = new POIFSReader();
//InputStream ins = new InputStream(new FileReader("C:/Book1.xls"));


/* myxls = null;
try {
 myxls = new FileInputStream("Book1.xsl");
}*/

//HSSFWorkbook wb  = new HSSFWorkbook(ins);
//HSSFSheet sheet1 = wb.getSheetAt(1);
//HSSFCell sheet=new HSSFCell(wb,sheet1,1,1);
jxl.Workbook workbook = jxl.Workbook.getWorkbook(new File("C:/Book1.xls"));
jxl.Sheet sheet=workbook.getSheet(0);

Cell a1 = sheet.getCell(0,0);
Cell b2 = sheet.getCell(1,1);
Cell c2 = sheet.getCell(2,1);

String stringa1 = a1.getContents();
String stringb2 = b2.getContents();
String stringc2 = c2.getContents();
System.out.print(stringa1);
System.out.print(stringb2);
System.out.print(stringc2);

out.println(stringa1);
out.println(stringb2);
out.println(stringc2);


//pfr.read(ins);


} catch (FileNotFoundException e)
{
  System.out.println("File not found");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
 }Start Free Trial
[+][-]12.29.2004 at 06:47AM PST, ID: 12919093

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2004 at 07:11AM PST, ID: 12919299

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: excel, data, from, file, retrieve
Sign Up Now!
Solution Provided By: rk_radhakrishna
Participating Experts: 3
Solution Grade: A
 
 
[+][-]12.29.2004 at 08:24AM PST, ID: 12919920

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32