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
648 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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