Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
348

Hi all. I saw this tutorial for create a component controller for an XML Excel export functionality.

But I want something more easy, in HTML.

So I wrote this function:


  public void exportToExcel( com.sap.tc.webdynpro.progmodel.api.IWDNode node )  {
    //@@begin exportToExcel()
        try {
            StringBuffer csv = new StringBuffer();
            csv.append("<html><body><table border=1>");
            Iterator<? extends IWDAttributeInfo> attributes = node.getNodeInfo().iterateAttributes();
            csv.append("<tr>");
            while (attributes.hasNext()) {
                csv.append("<th>");
                IWDAttributeInfo attrName = attributes.next();
                csv.append(attrName.getName());
                csv.append("</th>");
            }
            csv.append("</tr>");
            for (int i = 0; i < node.size(); i++) {
                attributes = node.getNodeInfo().iterateAttributes();
                csv.append("<tr>");
                IWDNodeElement ele = node.getElementAt(i);
                while (attributes.hasNext()) {
                    csv.append("<td>");
                    IWDAttributeInfo attrName = attributes.next();
                    csv.append("" + ele.getAttributeAsText(attrName.getName()));
                    csv.append("</td>");
                }
                csv.append("</tr>");
            }
            csv.append("</table></body></html>");
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bos.write(csv.toString().getBytes());
            bos.flush();
            IWDResource resource = null;
            resource = WDResourceFactory.createCachedResource(bos.toByteArray(), "Test.xls", WDWebResourceType.XLS);
            IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(
                    resource.getUrl(WDFileDownloadBehaviour.ALLOW_SAVE.ordinal()));
            window.show();
        } catch (Exception e) {
            wdComponentAPI.getMessageManager().reportException(e.getMessage());
        } finally {
        }
    //@@end
  }

I hope this help!

Labels in this area