Reading contents of uploaded excel file in web dynpro java

Hi All.
I am aware how to provide facility to upload files in web dynpro java. But my requirement is that on uploading a particular file (for eg. an excel file having 10 columns), I need to read the contents of that file and store it in a table in R/3.Can anyone suggest a way how I can read the contents of the uploaded file?
Thanks and Regards,
Saurabh.

Hi.
I am having the following requirement : I have a FileUpload UI element where user clicks Browse button, selects a file from the local system and presses a Upload button. Upon pressing Upload, the name of the selected file and the contents of the file should be shown.
In the View context, I have two value attributes: FileName of type String and FileResource of type binary.
This is the code that I have in the Upload button action handler :
  public void onActionUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
    //@@begin onActionUpload(ServerEvent)
    IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(
             IPrivateReadExcelView.IContextElement.FILE_RESOURCE);
    IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attributeInfo.
             getModifiableSimpleType();
    IPrivateReadExcelView.IContextElement element = wdContext.createContextElement();
    String fname = binaryType.getFileName();
    wdComponentAPI.getMessageManager().reportSuccess("File selected - "+fname);  //Statement 1
     try {
          wdComponentAPI.getMessageManager().reportSuccess("Successful");    // Statement 2
          InputStream in = new FileInputStream(fname);
          HSSFWorkbook wb = new HSSFWorkbook(in);
          wdComponentAPI.getMessageManager().reportSuccess("Successful");    //Statement 3
          int sheetsNo = wb.getNumberOfSheets();
          for (int i=0;i<sheetsNo;i++) {
               HSSFSheet sheet = wb.getSheetAt(i);
               Iterator rowsNo = sheet.rowIterator();
               while(rowsNo.hasNext()) {
                    HSSFRow rows = (HSSFRow)rowsNo.next();
                    Iterator colsNo = rows.cellIterator();
                    while(colsNo.hasNext()) {
                         HSSFCell cell = (HSSFCell)colsNo.next();
                         wdComponentAPI.getMessageManager().reportSuccess("File uploaded" +
                              "successfully");
                         if(cell.getCellType()==1) {
                              wdComponentAPI.getMessageManager().reportSuccess("00000"+
                                   cell.getStringCellValue());
                         else if(cell.getCellType()==0) {
                              String str=""+cell.getNumericCellValue();
                              wdComponentAPI.getMessageManager().reportSuccess("11111"+str);
     catch(Exception e) { wdComponentAPI.getMessageManager().raisePendingException();
    //@@end
On pressing Upload button, name of selected file is being shown(Statement 1). I am also getting Statement 2 in the output. However I am not getting Statement 3 onwards.
Where am I going wrong? Can anyone shed some light on this?

Similar Messages

  • How do we scan for viruses of uploaded excel file in Web Dynpro for JAVA

    Hi All,
    Please let me know "How do we scan for viruses of uploaded excel file in Web Dynpro for JAVA"
    Regards,
    Ganga.

    Hi ,
    pl go through this note "Integrating a virus scan into SAP applications 817623 "
    SAP Virus Scan Interface
    http://help.sap.com/saphelp_nw2004s/helpdata/en/30/42c13a38b44d5e8d1b140794e8e850/frameset.htm
    Sample Application
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6e1c4221-0901-0010-63ba-b1f9459d6e74
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f2681486-0a01-0010-8497-c778eac80da5
    Regards
    Ayyappparaj

  • Uploading excel file in Web Dynpro for ABAP

    Hello Gurus,
                       I need to upload a excel file in my Web Dynpro (ABAP) program. Can anyone please tell me how do i do this. Kindly help.
    Regards,
    Aditya.

    Hi Aditya,
    Please search the forum...
    Please check this link
    Uploading Data from Excel File To Dynpro
    Excel Upload via Web dynpro ABAP
    Upload and Reading Excel File in Web Dynpro
    Best regards,
    raam

  • File Visibility in uploading the file using web DynPro java

    hello,
    i have gone through the tutorial " uploading & downloading the file using web DynPro java".
    the upload functionalty is working fine. but i need to know thw path where these files are getting uploaded ??
    Waiting for the reply..
    Regards,
    Viren Gupta

    Hi Viren,
    Are you are refering to the below tutorial for upload and download:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b0e10426-77ca-2910-7eb5-d7d8982cb83f?QuickLink=index&overridelayout=true
    If yes, then answer is that the file is stored in the context of the application only as "com.sap.ide.webdynpro.uielement-definitions.Resource" object. Please read through the tutorial to understand the full process.
    WD doesn't really upload to server automatically unless there is any explicit code written. All it does is to store the file in a temp context which you can access and write your own code to store it in a particular location.
    Regards,
    Mahesh

  • Regarding Copying of Data From Excel file to Web Dynpro Java Table

    Hi
    Can any body give Suggestions that is how to copy or import Row and Column Values in the Excel file to the Java Web Dynpro Table
    Regards
    Chandran S

    Hi,
    First u should include jxl.jar API in ur classpath.
    ind a Resource variable to FileUpload UI. Then from the Fileupload UI, u can get the Sheet variable as
    InputStream fis=wdContext.currentFileUploadElement().getResource().read(true);
    Workbook wb=Workbook.getWorkbook(fis);
    Sheet sh=wb.getSheet(0);
    This can be easily read to a table by
    for(int i=14;i<34;i++)
         String bId=sh.getCell(2,i).getContents();
         String cId=sh.getCell(3,i).getContents();
         String subj=sh.getCell(4,i).getContents();
                    IPrivate<View>.I<Table>Element el=wdContext.node<Table>().create<Table>Element();
                    wdContext.node<Table>().addElement(el);
                    el.setBID(bid);
                    el.setCID(cid);
                    el.setSUB(subj);
    This example reads the excel from row 13 to 32 and column 3 to 5 and uploaded to a table
    Regards
    Fahad Hamsa

  • Uploading CSV File into Web Dynpro Java Table and Write back to a Database

    Hi Gurus!
    I would like to upload a csv file and read the content into an UI table element.
    Then, I need to write the uploaded file back to a database. I'm using NetWeaver 2004s.
    could you please provide advice for both, uploading and wirting to databse (e.g. maxDB or oracle), since I'm quite new in WDJ.
    thanks in advance.
    farid
    ps. helpfull answers will be rewarded with points!

    Hi ,
    have look at this blog
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6603. [original link is broken] [original link is broken] [original link is broken]
    Have a look at this links.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c0d9336b-b4cf-2910-bdbf-b00d89bd2929.
    Re: Popup Internal Window - data type IWDWindow not available
    Regards,
    krishna.

  • Upload and Reading Excel File in Web Dynpro

    Hi all,
    I have a requirement in my application( in 04s), where in, i need to upload an excel from a client through a web dynpro application(using fileupload UI) and read each and every the content of that excel file in web dynpro and process the data accordingly.
    The format of the excel is fixed and pre-defined.
    I went through a lot of blogs, but could not find a direct and exact solution to this requirement.
    Please help me.
    Looking forward to your contribution
    Thank you,
    Gita KC.

    Reading Excel Sheet from Java without using any Framework
    Enhanced File Upload - Uploading and Processing Excel Sheets
    Reading Multiple Sheets of Excel Sheet from Java
    nikhil

  • Uploading excel files into Web UI

    We are following the blog http://wiki.sdn.sap.com/wiki/display/CRM/CRMWebUI-UploadingdatafromExcelfiles
    to upload excel files into Web UI.
    The  problem which we are facing is that the values are not getting populated in the text are and in the
    event handler EH_ONSERVEREVENT, no values are being populated in lt_items table.
    It would be great if someone could help us with this.

    Hi Nidhi,
    I have tried the blog but due to some reason, could not get it worked out.
    But, If U are ok to use CSV input files, instead of excel, U can use the standard component "GS_FILE_UPLOAD" as a popup and upload the files into the required assignment blocks.

  • Error While uplaoding a EXCEL file in Web dynpro - HR_KR_XSTRING_TO_STRING

    Hi,
        I am getting an error while uploading an excel file in web Dynpro application. i am using the HR_KR_XSTRING_TO_STRING this function. I am getting the following error message 'Unable to interpret    as a number'.

    First of all, are you sure you know what you are working with here.  If this is standard Excel file in the Microsoft binary/propriatery format there is not function module or class in ABAP that can magically just transform this to a character string.  You should search the forums as this has been discussed extensively.  On that topic, please also do not post duplicate threads.  I have already locked your other thread with the same basic question.
    Instead of the binary/propriatery format of Excel, the file should be saved on the client as a text based format - like XML or Text Tab Delimited. You can then use several different options on the server to convert the XSTRING to STRING and process the content (becuase it was text based to begin with).  You could use CL_BCS_CONVERT, the function modules in the function group SCMS_CONV, or the class CL_ABAP_CONV_IN_CE.

  • Problem in Uploading excel file using WebDynpro for Java

    Hi  All
    I have followed for Uploading excel file using WebDynpro for Java added by  Tulasi Palnati
    I done all, but I'm getting 500 Exception please contact u r system admin meag  at run time also  Jxl/Workbook class not found msag  but i downloaded Jxl.jar file and  there is no error signals  in coding part. How can I solve the Problem.
    Thanks
    Polaka

    Please ask the people in the Web Dynpro Java forum for a solution.

  • Reading and displaying Ms.Word document with web dynpro java

    Hi,
    I'm using NetWever developer studio 7..0.21.
    I'm developing web dynpro java application.I'm in difficulty to read and display word document with its original format in web dynpro view. Is it possible?
    If possible , is there a blog etc.?
    Thanks.

    Hello,
    You have to use the Office Integration Library. Please, follow the documentation below:
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/32853febec3c17e10000000a114084/frameset.htm
    I hope this helps you.
    Regards,
    Blanca

  • Error While uploading a EXCEL file in Web dynpro - HR_KR_XSTRING_TO_STRING

    Hi,
       I am getting an error while trying to upload a excel file.  I am using the function HR_KR_XSTRING_TO_STRING for conversion. The error message is  "Unable to interpret    as a number"

    First of all, are you sure you know what you are working with here.  If this is standard Excel file in the Microsoft binary/propriatery format there is not function module or class in ABAP that can magically just transform this to a character string.  You should search the forums as this has been discussed extensively.  On that topic, please also do not post duplicate threads.  I have already locked your other thread with the same basic question.
    Instead of the binary/propriatery format of Excel, the file should be saved on the client as a text based format - like XML or Text Tab Delimited. You can then use several different options on the server to convert the XSTRING to STRING and process the content (becuase it was text based to begin with).  You could use CL_BCS_CONVERT, the function modules in the function group SCMS_CONV, or the class CL_ABAP_CONV_IN_CE.

  • Help on retriving the content from a excel file and web page

    hi,
    i need help on identify the content on a webpage. how to do this ?
    in myproject i need to read an excel file how to read an excel file , in java?
    after reading the excel file ,i have to open a webpage based on the link available in the excel file.
    how to perform this action?
    and from the web page i need to retrive the each individual text
    how to perform these action?
    please help .... urgent
    regards,
    valli

    sales team will enter data in excel file .
    the excel file will have a list of links ,
    i need to access the excel file and open that link.
    from the link i will get some information ,such as
    company name, address, phone no, contact details.
    i need to identify each individual (address, email
    id) from the web page and store that data in the data
    base .
    how to access a excel file from java?
    i found in google jakartha-poi-jar file.
    but ther eare many jar file. which one i have to
    download?
    how to identify from a web page these different
    items?
    thanksPlease answer DrClaps's question from reply #3.

  • How to extract the content of a user uploaded txt file in web dynpro?

    Hi,
    I'm working on a java web dynpro component. This component consists of document upload field, where users should be able to upload .txt documents. These uploaded text documents should then be somehow read, and thir content displayed. I am already able to upload documents using the upload field, and store it in the context, but I'm still not able to extract the content of these text documents for displaying.
    Does anyone have any suggestions of how I could do this?
    Any help will be greatly appreciated!
    Thanks!

    Hi Alain,
        You can do through this document on how to upload/download files in Webdynpro.
    [https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081257f]
    Once you have the uploaded file in your context if you are storing it as a byte array then convert it to a string using the String constructor String(byte[] bytes)  and then you can store this string in an attribute of type String which could be bound to a UI element (TextArea) to display the contents.
    If you are using an IWDResource then you will get an inputstream from which you can read the data and convert it to a string for display as mentioned above.
    Hope this helps.
    Sanyev

  • Download Excel file through Web dynpro with no windows open?

    Can we have a web dynpro application that just returns an Excel file in the response with no open windows? Similar to a java servlet that is used to download a Excel file?
    This basically means that I cannot use wdComponentAPI.getWindowManager().createNonModalExternalWindow()
    Java Servlet Code
    HttpSession session = request.getSession();      // get a handle on the session id
    response.setContentType("application/download");
    response.setHeader("Content-Disposition", "filename=RTIS_Report.xls");
    PrintWriter out = null;
    out = response.getWriter();
    String report = request.getParameter("REPORT");
    JCO.Table lines = download(request, session, report);
    for (int i = 0; i < lines.getNumRows(); i++) {
         lines.setRow(i);
         String content = lines.getString("LINES") + "\n";
         out.write(content);
         out.flush();
    out.flush();
    out.close();

    Hi,
    I think you can use IWD Cached Web Resource to achieve this..
    See the below code FYI..
    public void downloadToExcel( )
        String fileName = "Customer" + ".xls";
         IWDCachedWebResource cachedExcelResource = null;
         try
              File f = new File("Customer.xls");
              WritableWorkbook workbook =   Workbook.createWorkbook(f);
              WritableFont black = new WritableFont(WritableFont.createFont("Trebuchet MS"),WritableFont.DEFAULT_POINT_SIZE,WritableFont.BOLD,false,UnderlineStyle.SINGLE,Colour.BLACK);
              WritableCellFormat blackFormat = new WritableCellFormat(black);
              WritableFont blue = new WritableFont(WritableFont.createFont("Trebuchet MS"),WritableFont.DEFAULT_POINT_SIZE,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
              WritableCellFormat blueFormat = new WritableCellFormat(blue);
              WritableSheet sheet = workbook.createSheet("Customer", 0);
                   Label label;
                   String[] header={"Corporate Code","Batch ID"};
                   for (int i=0;i<2;i++)
                        label = new Label(i,0,header<i>.toString(),blackFormat);
                        sheet.addCell(label);
                   WritableCellFormat integerFormat = new WritableCellFormat(NumberFormats.INTEGER);
                   jxl.write.Number number;
                   // Reading the contents
                   for(int i=0;i<wdContext.nodeVn_DownloadToExcel().size();i++)
                        String strCorpName = wdContext.currentContextElement().getVa_CorpCode();
                        String strBatchID =     wdContext.nodeVn_DownloadToExcel().getVn_DownloadToExcelElementAt(i).getVa_BatchID();
                        label = new Label(0,i+1,strCorpName,blueFormat);
                        sheet.addCell(label);
                        label = new Label(1,i+1,strBatchID,blueFormat);
                        sheet.addCell(label);
                   workbook.setColourRGB(Colour.LIME, 0xff, 0, 0);
                   workbook.write();
                   FileInputStream excelCSVFile = new FileInputStream(f);
                   IWDCachedWebResource cachedWebResource = null;
                   if (excelCSVFile!= null)
                        cachedWebResource = WDWebResource.getWebResource(excelCSVFile, WDWebResourceType.getWebResourceType("xls","application/ms-excel"));
                   cachedWebResource.setResourceName(fileName);
              cachedExcelResource = cachedWebResource;
              wdContext.currentContextElement().setVa_DownloadToExcel(cachedExcelResource.getURL());
              workbook.close();
         catch (Exception ex)
              wdComponentAPI.getMessageManager().reportException("Error in Excel Download"+ex.getMessage(),false);
    Regards,
    Vijay

Maybe you are looking for

  • Generating an XML formated text file

    Hi all I am a PL/SQL programmer and have no idea about XML :-( I am using ORACLE 10g and my application generates atleast 100 text files a day for customers. These files are manipulated using Utl_File package and gets data from the DB.These files are

  • How To Restrict Users To Only Create Purchase Requisitions with Item Catalog?

    Hi, everyone  Please help me,  How To Restrict Users To Only Create Purchase Requisitions with Item Catalog? is it possible?  Regards,   Manuel

  • [Solved]probleme with combobox

    hi, i create a frame using ADF BC in which i drag and drop the departmentVO and i set it a combobox. in my database i have 60 department, when i open the combobox i fond only 10 departments and i want to find it all in the combobox. can any body help

  • Why are my new apps in 'limbo'?

    Whenever I get apps from the iStore, I click on the Install button on my pc, but instead of installing, the button simply changes to Will Install! What gives with this? I want the app to install when I click on it, not at some theoretical time in the

  • Writing data in text file..

    1. check the file name in D:\\temp\\test.txt 2. if it exists, then open file. if there is data, then read data. after the last record, it writes new data. 3. if it does not exist, create text.txt file and write data into text.txt file. so far, I have