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!

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply