Skip to Content
0
Former Member
Jan 22, 2010 at 07:48 AM

how to export the data from table to excel sheet

17 Views

hi experts i have some problem am trying to export the data fro table to Excel sheet in the view controller i have created one button wit public void onActionCLEAR(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionCLEAR(ServerEvent)

//wdContext.nodeBapi_Salesorder_Getlist_Input().

//wdContext.nodeBapi_Salesorder_Getlist_Input().invalidate();

//@@end

}

//@@begin javadoc:onActionExporToExcel(ServerEvent)

/** Declared validating event handler. */

//@@end

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

{

//@@begin onActionExporToExcel(ServerEvent)

try{

FileOutputStream fos=new FileOutputStream("Test.xls");

PrintStream ps=new PrintStream(fos);

ps.println("<html><body><table border=1>");

int size=wdContext.nodeBapi_Salesorder_Getlist_Input().size();

Iterator attributes=wdContext.getNodeInfo().iterateAttributes();

ps.println("<tr>");

while(attributes.hasNext()){

ps.println("<th>");

DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();

ps.println(attrName.getName());

ps.println("</th>");

}

ps.println("</tr>");

for(int i=0; i<wdContext.nodeBapi_Salesorder_Getlist_Input().size();i++)

{

attributes=wdContext.getNodeInfo().iterateAttributes();

ps.println("<tr>");

IWDNodeElement ele=wdContext.getElementAt(i);

while(attributes.hasNext()){

ps.println("<td>");

DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();

ps.println(""+ele.getAttributeAsText(attrName.getName()));

ps.println("</td>");

}

ps.println("</tr>");

}

ps.println("</table></body></html>");

ps.flush();

ps.close();

fos.close();

}

catch(Exception e){

wdComponentAPI.getMessageManager().reportException(e.getMessage(), false);

}

finally{

//return("Test.xls") ;

}

//@@end

}h action and i have return the code

its running sucessfully but am not able to perform the action plz help me