Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How i do the upload file with struts and POI for read a excel file through the inputstream

Posted on 2006-06-12
3
Medium Priority
?
659 Views
Last Modified: 2012-02-06
Hi,  friends

    i have an aplication web on Struts and i use the FileUpload for read an archive and later i need read the excel file without save the archive on disk.   here i put the code.

This code upload the archive on memory.    Look on "http://www.roseindia.net/struts/strutsfileupload.shtml"

//*****************************************************************
  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    StrutsUploadForm myForm = (StrutsUploadForm)form;

        // Procesar el archivo cargado en el ActionForm
        FormFile myFile = myForm.getTheFile();
        String contentType = myFile.getContentType();
        String fileName    = myFile.getFileName();
        int fileSize       = myFile.getFileSize();
        byte[] fileData    = myFile.getFileData();

    System.out.println("contentType: " + contentType);
    System.out.println("File Name: " + fileName);
    System.out.println("File Size: " + fileSize);
//*****************************************************************



For read the excel archive, this is the code

//*****************************************************************
    POIFSFileSystem fs = new POIFSFileSystem( new FileInputStream("../prueba.xls"));
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    HSSFSheet sheet = wb.getSheetAt(0);

    System.out.println( "Va a iterar por fila ");

    // Iterate over each row in the sheet
    Iterator rows = sheet.rowIterator();
    while( rows.hasNext() ) {          
        HSSFRow row = (HSSFRow) rows.next();
        System.out.println( "Row #" + row.getRowNum() );

        // Iterate over each cell in the row and print out the cell's content
        Iterator cells = row.cellIterator();
        while( cells.hasNext() ) {
            HSSFCell cell = (HSSFCell) cells.next();
            System.out.println( "Cell #" + cell.getCellNum() );
            switch ( cell.getCellType() ) {
                case HSSFCell.CELL_TYPE_NUMERIC:
                    System.out.println( cell.getNumericCellValue() );
                    break;
                case HSSFCell.CELL_TYPE_STRING:
                    System.out.println( cell.getStringCellValue() );
                    break;
                default:
                    System.out.println( "unsuported sell type" );
                    break;
            }
        }
       
    }
//*****************************************************************

How i merge that?  without save the archive,  maybe use the inputstream.  How?


          Thanks a lot.
     
0
Comment
Question by:jlguerra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
suprapto45 earned 1000 total points
ID: 16892401
Hi,

Try
POIFSFileSystem fs = new POIFSFileSystem(myFile .getInputStream());

I hope it works

David
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 16899147
;)

Glad I could help

David
0
 

Expert Comment

by:javadevman
ID: 37556315
Instead of printing to console. How do we send a value back to a jsp using this code example above?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this article, I’ll show how research, determination, and use of modern technology helped me solve a DNA mystery.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question