Skip to Content
avatar image
Former Member

Excel download... and upload?

Hello everyone,

I'm using the web dynpro binary cache, as explained in sap tutorials, to download the content of a UI table to an excel file. Is there any form of doing the opposite? I mean, i would like to upload several columns of data from an excel file to multiple value attributes of a context node.

Is this possible??

Other problem i'm having is that when i download the data to the excel file all columns appear on an order that i don't want. How can i control the order of the columns in the excel file, when downloading it from web dynpro?

thank you everyone,

Nuno

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 12, 2006 at 07:35 AM

    Hi,

    I can give solution to Upload Excel file.

    1)Add jxl jar folder in the lib folder of ur project.

    2)Go to properties of ur project and add jar to ur project.

    3)Using the File upload ui ,browse and upload the file.

    4)Write the read file in to ur server location using fileoutput stream.

    5)then using code u can read the excelfile from the server location itself.

    Here is the code:

    	IWDAttributeInfo attInfo =wdContext.getNodeInfo().getAttribute("upload");
     
    /** get the name of excel file and storing it in the server with the same name and extention****/
    
    binaryType=IWDModifiableBinaryTypeattInfo.getModifiableSimpleType();
    fileuploaded = binaryType.getFileName();
    byte b[] = wdContext.currentContextElement().getUpload();
    File filename =new File("\\<Server name>\<folde name>\" + fileuploaded);
    try {
    FileOutputStream out = new FileOutputStream(filename);
    out.write(b);
    out.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    
    /***Readind from the server***/
    int iRows = 0;
    try {	Workbook wb = null;
    	Sheet sheet = null;
    	wb = Workbook.getWorkbook(filename);
    	sheet = wb.getSheet(0);
    			
    	int iColumns = sheet.getColumns();
          iRows = sheet.getRows();
         int i = 0;
        //get Cell contents by (COLUMN, ROW);
        for (int r = 0; r < iRows; r++) {
       for (int c = 0; c < iColumns; c++) {
    
    	Cell cell = sheet.getCell(c, r);
    
    	characterarray<i> = cell.getContents();
    //wdComponentAPI.getMessageManager().reportSuccess("Row"+r+ characterarray<i>);
    i++;
    	}
    }
    
    wb.close();

    Declare Globally

    //@@begin others

    String fileuploaded;

    IWDModifiableBinaryType binaryType;

    String characterarray[] = new String[1000];

    //@@end

    Regards,

    Vijayakhanna Raman

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 11, 2006 at 05:05 AM

    Hi ,

    Foe excel upload use FileUpload control to upload file .And use POI API to read excel file.

    Go through this blog.

    /people/perumal.kanthan/blog/2005/03/21/reading-excel-data-from-java-using-hssf-api

    Regards,

    Rajeev

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      1.You have to add this jar to lib folder under the root of your project.

      2.right click on your project ,go to properties->Java build path -> Libraries ->add external jars add there the POI JARS.

      Hope this will help you.

      Regards,

      Rajeev

  • avatar image
    Former Member
    Feb 08, 2008 at 07:20 AM

    Hi Vijayakhanna,

    I am working in NW04s . i tried the solution suggested by you:

    for uploading the excel file and then tried to create this excel file on the server and reading data from excel sheet into context. But in NW04s, we have a to set property 'Resource' of type - context attribute(IWDResource) for FileUpload UI Element - Resource which is of the type IWDResouce.

    Upload is successfull.

    I created a object of FileOutputStream

    FileOutputStream fo = new FileOutputStream(l_filename);

    This file gets created successfully on the server.

    Now, i am trying to write contents in this file using the following statement:

    fo.write(wdContext.currentContextElement().getResource().toString().getBytes());

    where Resource is a context attribute of type - IWDResource.

    The problem is: file created on the server doesnot contain the data uploaded by the user. And hence, it gives an error while reading the file.

    Can you help me in extracting the data from context attribute 'Resource' and then writing into the file???

    Thanks for help.

    Regards,

    Rashmi

    Add comment
    10|10000 characters needed characters exceeded