Onclick the button to export excel in XPages

家住魔仙堡 提交于 2021-01-29 14:25:07

问题


I found the code on the website: https://www.xpagedomino.com/2015/02/xpage-export-to-excel-using-javascript.html

Now I have :

  1. a view
  2. one button

I want to use the button to export the excel.

The following is I already tried the code:

In the button(Client-side) :

var viewPanel1Id = "view:_id1:viewPanel1"
var htmltable = document.getElementById(viewPanel1Id);
var html = htmltable.outerHTML;
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));

But the button was no response...

How can I export to excel?????


The following is the code of XPages

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:button value="Export5" id="button5">
    <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
        <xp:this.action><![CDATA[#{javascript: var viewPanel = document.getElementById("#{id:viewPanel1}");
 var html = viewPanel.outerHTML;
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));}]]>
</xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:viewPanel rows="30" id="viewPanel1" viewStyle="width:100%">
        <xp:this.facets>
            <xp:pager partialRefresh="true" layout="Previous Group Next"
                xp:key="headerPager" id="pager1">
            </xp:pager>
        </xp:this.facets>
        <xp:this.data>
            <xp:dominoView var="view1" viewName="VEMPM03"></xp:dominoView>
        </xp:this.data>
        <xp:viewColumn columnName="LOCAL_PR_NO" id="viewColumn1"
            showCheckbox="true">
            <xp:viewColumnHeader value="prno" id="viewColumnHeader1"
                showCheckbox="true">
            </xp:viewColumnHeader>
        </xp:viewColumn>
        <xp:viewColumn columnName="PUR_DEPT_S01" id="viewColumn2">
            <xp:viewColumnHeader value="pur" id="viewColumnHeader2">
            </xp:viewColumnHeader>
        </xp:viewColumn>
        <xp:viewColumn columnName="ITEM_NAME" id="viewColumn3">
            <xp:viewColumnHeader value="name" id="viewColumnHeader3">
            </xp:viewColumnHeader>
        </xp:viewColumn>
    </xp:viewPanel>
</xp:view>

回答1:


Your Button executes ServerSide Script. When using <xp:this.script> it worked for me.

    <xp:button value="Export5" id="button5">
      <xp:eventHandler event="onclick" submit="false">
        <xp:this.script><![CDATA[ 
                var viewPanel = document.getElementById("#{id:viewPanel1}");
                var html = viewPanel.outerHTML;
                window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));]]>
  </xp:this.script>
    </xp:eventHandler>
</xp:button>



回答2:


This may not fix your problem, but the line below is a better way to reference an element by its id in csjs:

 var viewPanel1Id = document.getElementById("#{id:viewPanel1}")


来源:https://stackoverflow.com/questions/63407992/onclick-the-button-to-export-excel-in-xpages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!