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
643 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
object methods vs static methods 2 89
gZip compression filter 2 91
caughtSpeeding java challenge 16 132
equalIsNot  challenge 43 117
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now