!--a11y-->
Implementing the Public Service Method
exportToExcel2003() 
After completing the required code preparations, we can now implement the service method exportToExcel2003(), which is exposed to external component users. The following steps are implemented in this method:
...
1. Create an XML representation of the given context data by calling the private toExcel() method.
2. Store the XML file in the Web Dynpro Binary Cache by calling the private getCachedWebResource() method.
3. Store the file name and the URL of the cached Excel Web resource for the purpose of data binding within the corresponding context attributes.
4. Open a popup window for displaying a link to the cached Excel file on the user interface.
Component Controller ExcelExportComp.java Component ExcelComp |
//@@begin javadoc:exportToExcel2003() /** * Exports data in given context node to an Excel file. Contained * attributes (columns) and the corresponding header texts must be specified in * a map object. * A cached Web resource is created and the corresponding URL link is * displayed in a separate popup window. */ //@@end public void exportToExcel2003( com.sap.tc.webdynpro.progmodel.api.IWDNode dataNode, java.util.Map columnInfos ) { //@@begin exportToExcel2003() byte[] excelXMLFile; IWDCachedWebResource cachedExcelResource = null; String fileName = dataNode.getNodeInfo().getName() + ".xls";
try { // create Excel 2003 XML data as a byte array for the given context node, // attributes and headers excelXMLFile = toExcel(dataNode, columnInfos).getBytes("UTF-8"); // create a cached Web Dynpro XLS resource for the given byte array // and filename cachedExcelResource = getCachedWebResource( excelXMLFile, fileName, WDWebResourceType.XLS);
// Store URL and file name of cached Excel resource in context. if (cachedExcelResource != null) { wdContext.currentContextElement().setExcelFileURL( cachedExcelResource.getURL()); wdContext.currentContextElement().setExcelFileName( cachedExcelResource.getResourceName()); // Open popup window with a link to the cached Excel file Web resource. openExcelLinkPopup(); } else { wdComponentAPI.getMessageManager().reportException( "Failed to create Excel file from table!", true); } } catch (UnsupportedEncodingException e) { wdComponentAPI.getMessageManager().reportException( e.getLocalizedMessage(), true); } catch (WDURLException e) { wdComponentAPI.getMessageManager().reportException( e.getLocalizedMessage(), true); } //@@end } |
Using the new Component ExcelExportComp