473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Excel Upload

Hi am trying to upload a excel sheet and parse the every columns and needs to save the columns in different tables for that am using jsp and servlet coding,in servlet coding am using apache POI for uploading, and i can able to upload the excel sheet but i cant parse the column values because encrypted values only i can able to get,

Here is my JSP code,
Expand|Select|Wrap|Line Numbers
  1. <TITLE>Display file upload form to the user</TITLE></HEAD> 
  2. <BODY> <FORM ENCTYPE="multipart/form-data" ACTION="uploadExcel" METHOD=POST>
  3. <br><br><br>
  4. <tr><td colspan="2" align="center"> </td></tr>
  5. <tr><td colspan="2" align="center"><input type="submit" value="Send File"> </td></tr>
  6. <table>
and my servlet code,

Expand|Select|Wrap|Line Numbers
  1. DiskFileItemFactory factory = new DiskFileItemFactory();
  2.         ServletContext servletContext = this.getServletConfig().getServletContext();
  3. File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
  4. factory.setRepository(repository);
  5. ServletFileUpload upload = new ServletFileUpload(factory);        
  6. try {
  7. @SuppressWarnings("unchecked")
  8. List<FileItem> items = upload.parseRequest(request);
  9. Iterator<FileItem> iter = items.iterator();
  10. while (iter.hasNext()) {
  11. FileItem item = iter.next();
  12. }
  13. } catch (FileUploadException e) {
  14. // TODO Auto-generated catch block
  15. e.printStackTrace();
  16. } catch (Exception e) {
  17. // TODO Auto-generated catch block
  18. e.printStackTrace();
  19. }
  20. }
Please give me suggestions ASAP.
Thanks in advance.

Regards,
Suganth A
Mar 13 '14 #1
3 2198
chaarmann
785 Expert 512MB
Maybe the excel-sheet is protected or the cell values are calculated by VB-macros?
please create a simple excel sheet yourself and try parsing that first!

And "ASAP" (quotation), really very "ASAP", show us here what the input is, what values you expected to get and what values you really got, else we can't help you "ASAP". Thanks in advance, too.
Mar 13 '14 #2
Thanks for a help Dear chaarmann,

The Excel file is not protected. and am attached the excel sheet in this reply.


While executing this method in servlet

Expand|Select|Wrap|Line Numbers
  1. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  2.         /*String XLFile=session.getAttribute("theName").toString();*/
  3. /*        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
  4. */        DiskFileItemFactory factory = new DiskFileItemFactory();
  5.         ServletContext servletContext = this.getServletConfig().getServletContext();
  6.         File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
  7.         factory.setRepository(repository);
  8.         ServletFileUpload upload = new ServletFileUpload(factory);        
  9.         try {
  10.             @SuppressWarnings("unchecked")
  11.             List<FileItem> items = upload.parseRequest(request);
  12.             Iterator<FileItem> iter = items.iterator();
  13.             while (iter.hasNext()) {
  14.                 FileItem item = iter.next();
  15.                 String root = getServletContext().getRealPath("/");
  16.                 File path = new File(root + "/fileuploads");
  17.                 System.out.println("EXACT PATH------------------------>>"+item);
  18.                 processFormField(item);
  19.                 /*if (item.isFormField()) {
  20.  
  21.                 } else {
  22.                     processUploadedFile(item);
  23.                 }*/
  24.             }
  25.         } catch (FileUploadException e) {
  26.             // TODO Auto-generated catch block
  27.             e.printStackTrace();
  28.         } catch (Exception e) {
  29.             // TODO Auto-generated catch block
  30.             e.printStackTrace();
  31.         }
  32. }
  33.  

am getting the following details in console:

name=SFD.xls, StoreLocation=C:\Users\css92421\workspace\.metadat a\.plugins\org.eclipse.wst.server.core\tmp0\work\C atalina\localhost\TestCAF\upload_2e9eae35_144bf06d 095__8000_00000000.tmp, size=57856bytes, isFormField=false, FieldName=file



Instead of this details i need every column values presented in the uploaded excel sheet.

in the sout i have printed the System.out.println(item.getString();)

am getting the following output in the console,

see the image i have attached.

Thanks in advance chaarmann.
Attached Images
File Type: jpg Console.jpg (57.5 KB, 154 views)
Attached Files
File Type: xls SFD.xls (56.5 KB, 386 views)
Mar 14 '14 #3
chaarmann
785 Expert 512MB
The code above only uploads the file. I can't see any console-output-commands (except the file info) or processing of the uploaded file! Maybe it is contained in "processFormField(item)"? Please list this method here ASAP. Thanks in advance. :-)

The strange thing is that the console output should start with "EXACT PATH------------------------>>", but the console output you listed does not. Please post the correct console output here ASAP. Thanks in advance.

The screenshot shows the binary data of the Excel-file. You should save it on disk (or hold it in a byte-array in memory) and then compare the original file with the uploaded one ASAP. Thanks in advance. If they are both the same, your upload works perfect!
Now you need to use the POI library to parse the Excel file and extract the info. I suggest you first try to read an Excel-file from disk (instead of using the uploaded data) and use the POI library to parse it.
I want to see sourcecode containing POI commands like:
Expand|Select|Wrap|Line Numbers
  1. FileInputStream file = new FileInputStream(new File("C:\\temp\SFD.xls"));
  2. HSSFWorkbook workbook = new HSSFWorkbook(file);
  3. HSSFSheet sheet = workbook.getSheetAt(0);
  4. Iterator<Row> rows = sheet.iterator();
  5. for (row: rows) ... {
  6.    Iterator<Cell> cells = row.cellIterator(); {
  7.    for (cell: cells) ... {
  8.       // print content of cell
If each of these 2 separate tasks work (file uploading and excel parsing), and are well tested, then you can put both of them together ASAP. Thanks in advance.
Mar 14 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roz Lee | last post by:
I want to cut and paste an Excel spreadsheet into a web page and then update my SQLServer database - it's basically an import function but using cut and paste rather than reading the file from a...
3
by: Prakash | last post by:
Hi, We face problems uploading excel (with macros) documents using HTML File Upload. The file contents are corrupted while viewing the same. However, we are able to upload excel (w/o. macros)...
1
by: Jake | last post by:
Good Day All, Sorry if I am posting in the wrong forum, hopefully someone will be able to push me in the right direction. What I am trying to accomplish is allowing a client to upload an Excel...
6
by: Daniel | last post by:
Hi all, Can i open and edit the excel sheet on web page after downloading? After editing, i close the web page and the excel file auto upload to the server. Is it possible? I really struggling...
1
by: Tlholo | last post by:
Here are the requirements for the project. I have also included the other project that I am working on and is also giving me some problems. i need code examples. Project 1 This program actually...
1
by: =?Utf-8?B?TGFtaXM=?= | last post by:
HI, I am doing an aspx application and need to let my users be able to edit the information in my database by the page. My first Idea was to let them export the information to an excel file at...
0
by: jayce | last post by:
Hi I am using an ADODB connection to link up an Access database to my core spreadsheet tool. I have created a loop to repeatedly: - download data from Access - analyse it in Excel, with data...
0
by: haroldburgess | last post by:
I'm using the Jet provider to connect to an excel spreadsheet to load into a dataset. the problem is when i use the hdr=no extended property, the provider auto adds f1, f2, f3... as new first row. ...
1
by: codexxx | last post by:
Hi All, We have setup an Amazon webstore and we anticipate uploading 10,000+ products, and therefore to avoid unnecessary manual labor we wish to automate as much of the process of adding and...
1
by: helplakshmi | last post by:
Hi All, I wish you a Happy new year!!!.. My requirement is to upload an excel file using PHP and to update the data in MSSQL. For which i have designed a screen so that the user can browse 2...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.