File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Reading Excel file from Client side using servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Reading Excel file from Client side using servlet" Watch "Reading Excel file from Client side using servlet" New topic
Author

Reading Excel file from Client side using servlet

Radheshyam Yadav
Greenhorn

Joined: Dec 31, 2010
Posts: 1
When I run this code from client or another computer, It gives "java.io.FileNotFound Exception". And It says, "The system can not find the file specified".
Please provide me appropriate code to do this.


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxl.*;
import jxl.read.biff.BiffException;
import java.io.*;

@WebServlet(name = "UploadFile", urlPatterns = {"/UploadFile"})
public class UploadFile extends HttpServlet {




public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
OutputStream out = null;
PrintWriter out1 = response.getWriter();
String filename = request.getParameter("file");
out1.println("Filename [" + filename + "]");
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(new File(filename));
} catch (BiffException e) {

// TODO Auto-generated catch block
e.printStackTrace();
}

Sheet[] sheet = workbook.getSheets();
int rows = sheet[0].getRows() + 1;

NextRow:
for (int row = 1; row < rows - 1; row++) {

//Cell colcell = sheet[0].getCell(1, rw);
String column = sheet[0].getCell(1, row).getContents().trim();
// this is all you had to add lol!!

out1.println(column);
}
}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41499
    
  53
What do you mean by "run this code from client or another computer"? It's a servlet, so it runs on the server.

While it's not clear what you mean by "this" in "to do this", if you're trying to access files on the client computer then that is impossible - imagine the security implications if it were!


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading Excel file from Client side using servlet