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
654 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 250 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

623 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