cancel
Showing results for 
Search instead for 
Did you mean: 

Upload data from an Excel file

Former Member
0 Kudos

Hi

I have to develop a functionality that consent to create a sale order by uploading data (material code and quantity) from an excel file.

How can i upload the content of an excel file into a table using java web dynpro technoloy?.

Thank you for your attention

Best Regards

Alessandro Fernandez

Accepted Solutions (0)

Answers (4)

Answers (4)

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Alessandro,

there is no IWDExcel2Context-API exsiting in Web Dynpro. To copy the excel content to the context you have to utilize some external service API for reading excel files (/people/prakash.singh4/blog/2005/03/16/create-an-excel-file-from-java-using-hssf-api). Populating context nodes should then be no problem.

Regards, Bertram

Former Member
0 Kudos

To Valery Sylaev

Thanks for your answer but I need more information about the uploading from an excel file.

I try to explain in detail the issue.

Well I have an I-View with a table (layout data: RowHeadData). In this table the user can write the material code and the quantity and proceed with the saving of the sale order.

An another way to create the sale order is to import the material code and the quantity from an excel file. Trough clicking the browse button I search the excel file and by clicking the import button I need that the data, contained in the excel, are written in the table. The problem isn’t the browsing but importing data into table.

How can I do this using java web dynpro tehcnology?

To Raman

I need to import a file .xls not a .csv.

Thank you for your attention

Best Regards

Alessandro Fernandez

vijayakhanna_raman
Active Contributor
0 Kudos

Hi Alessandro,

I have created the File for preparing the question bank and stored it in the data base from an excel sheet which is in CSV format.

Write the code in the init method

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("upload");

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();

This code in the Action event handler of file upload.

try{

byte b[]= wdContext.currentContextElement().getUpload();

int i=0;

String datas=new String(b);

String rowarray[]=new String[1000];

StringTokenizer datastoken=new StringTokenizer(datas,"\r");

while(datastoken.hasMoreTokens())

{

rowarray<i>=datastoken.nextToken();

i++;

}

String characterarray[]=new String[1000];

or(int k=0, m=0;m<i;m++)

{

StringTokenizer stn1=new StringTokenizer(rowarray[m],",");

while(stn1.hasMoreTokens())

{

characterarray[k]=stn1.nextToken();

k++;

}

}

InitialContext ctx=new InitialContext();

javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("jdbc/SAPJ2EDB");

java.sql.Connection con=ds.getConnection();

java.sql.Statement stmt=con.createStatement();

int x=-1,z;

for(z=0;z<i-1;z++) {

con.setAutoCommit(false);

ResultSet rs=stmt.executeQuery("select count(*) from TMP_QUESTIONBANK1");

rs.next();

int index=rs.getInt(1)+1;

String subid=wdContext.currentNode_subElement().getTech_admin_subid();

int retIns = stmt.executeUpdate("insert into TMP_QUESTIONBANK1(INDEX,SUBJECTID,QUESTIONS,OPTIONA,OPTIONB,OPTIONC,OPTIOND,ANSWER) values("index",'"subid"','"characterarray[x].trim()"','"characterarray[x]"','"characterarray[x]"','"characterarray[x]"','"characterarray[x]"','"characterarray[x]"')");

con.commit();

con.setAutoCommit(true);

wdComponentAPI.getMessageManager().reportSuccess("hai-updated----


"+index);

}

con.close();

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportException("Exception "+e,true);

}

Regards,

Vijayakhanna Raman

Former Member
0 Kudos

Alessandro

1. Use IWDFileUpload control to submit file

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/5c8500cd-0401...

2. Use Jakarta POI / HSSF to parse content into context node elements

/people/prakash.singh4/blog/2005/03/16/create-an-excel-file-from-java-using-hssf-api

(here is "writing" covered, parsing is even simplier, refer to POI docs as well)

3. Use IWDTable to show content

VS