Skip to Content
avatar image
Former Member

upload an excel file to table data

Hi ,

I could succesfully develope an application for uploading an excel file and displaying the data in tabular format (i.e through table display ) . But on Action <<Export TO Table>> it is not showing the details in tabular format . After uploadinfg file it is providing successful msg but when i m clicking on Export to table it is not displaying table data .

Its a demo WD program in java given below

Could anybody please guide me in this approach ?

public void onActionUploadFileData(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

InputStream text = null;

int temp = 0 ;

String path ;

try

{

File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());

FileOutputStream output = new FileOutputStream(file);

if (wdContext.currentContextElement().getResource()!= null )

{

text = wdContext.currentContextElement().getResource().read(false);

while ((temp=text.read())!= -1)

{

output.write(temp);

}

}

output.flush();

output.close();

path = file.getAbsolutePath();

wdComponentAPI.getMessageManager().reportSuccess(path);

}

catch (Exception ex)

{

ex.printStackTrace();

}

}

public void onActionExport_To_Table(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionExport_To_Table(ServerEvent)

try {

Workbook workbook = Workbook.getWorkbook(new File(path));

Sheet sheet = workbook.getSheet(0);

int columns = sheet.getColumns();

int rows = sheet.getRows();

int i=0;

int j;

for (j=1;j<=rows;j++)

{

element = wdContext.nodeTableData().createTableDataElement();

Cell cell1 = sheet.getCell(i,j);

element.setEmpId(cell1.getContents());

Cell cell2 = sheet.getCell(i+1,j);

element.setFirstname(cell2.getContents());

Cell cell3 = sheet.getCell(i+2,j);

element.setLastname(cell3.getContents());

wdContext.nodeTableData().addElement(element);

}

}

catch (Exception ex)

{

ex.printStackTrace();

}

Edited by: Trina_Saheli on Feb 26, 2010 4:22 PM

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Mar 03, 2010 at 01:32 PM

    Hi trina,

    i have found two issues in this

    1) check whenther you have added the JExcelApi in the class path.

    2) Please remove the line String path from the 0nActionUploadFileData() method please declare the same in the global declarations part as it is using the same in the another method.

    please do this you will resolve this issue.

    post me further updates

    Thanks,

    SG

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Trina,

      Check onAction method(onActionExporttotable) of "Export to Table ". Print the c1.getContents(), c2.getContents,c3.getContents value with MessageManager while setting vaule to node attribute.

      Once the all the attribute added to node TableData, print the table attribute in onActionExporttotable method itself.

      Also check the TableData node properties which is bind to table of displaying in the screen.

      Hopt it helps

      Regards,

      Arun