将数据表导出到Excel时无效的工作表名称错误

问题描述 投票:1回答:1

当我点击“export as excel”链接时,我想将jsf datatable导出为ex​​celsheet。我正在使用“Apache poi library”和“PrimeFaces”库来完成这项任务。

我使用PrimeFaces成功显示我的数据表。当我点击“export as excel”链接时,我得到例外

javax.faces.FacesException:sheetName''无效 - 字符数必须大于或等于1且小于或等于31。

请帮我解决我的问题。

谢谢。

这是我的jsf文件。

     <p:dataTable id = "dataTableId" var = "pr" value = "#{dashboard.beanList}"  >

        <p:panel header="Export All Data">

        <h:commandLink value="export as excel sheet">

            <p:dataExporter type="xls"  target="dataTableId" fileName="myexcel" />

        </h:commandLink>
        </p:panel>

这是我的stacktrace文件。

javax.faces.FacesException: sheetName '' is invalid - character count MUST be greater than or equal to 1 and less than or equal to 31
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:85)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:334)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
          Caused by: java.lang.IllegalArgumentException: sheetName '' is invalid - character count MUST be greater than or equal to 1 and less than or equal to 31 at org.apache.poi.ss.util.WorkbookUtil.validateSheetName(WorkbookUtil.java:108)
at org.apache.poi.hssf.record.BoundSheetRecord.setSheetname(BoundSheetRecord.java:94)
at org.apache.poi.hssf.model.InternalWorkbook.setSheetName(InternalWorkbook.java:588)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet(HSSFWorkbook.java:798)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet(HSSFWorkbook.java:78)
at org.primefaces.component.export.ExcelExporter.export(ExcelExporter.java:52)
at org.primefaces.component.export.DataExporter.processAction(DataExporter.java:112)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:84)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773)
at javax.faces.component.UICommand.broadcast(UICommand.java:296)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1255)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
... 22 more

这是我完整的Xhtml文件。

    <p:dataTable id = "dataTableId" var = "pr" value = "#{dashboard.beanList}"  >

    <f:facet name="header">
<!-- edit button -->    
    <p:commandButton id="toggler1" type="button" value="Customize Columns" style="float:right" icon="ui-icon-calculator" />
    <p:columnToggler datasource="dataTableId" trigger="toggler1" />
</f:facet>


            <p:column>
                <f:facet name="header"><h:selectBooleanCheckbox /> </f:facet>
                <h:selectBooleanCheckbox />
            </p:column>


            <p:column>

                <f:facet name="header"> UPC </f:facet>
                <div class="help-tip">
                    <h:outputLabel value="#{pr.lUpc}" id="l1" />
                </div>
            </p:column>


            <p:column>
                <f:facet name="header"> Cost </f:facet>
                <h:outputLabel value="#{pr.dCost}" />
            </p:column>



            <p:column>
                <f:facet name="header"> SKU </f:facet>
                <h:outputLabel value="#{pr.sSku}" />
            </p:column>


            <p:column>
                <f:facet name="header"> ProductName </f:facet>
                <h:outputLabel value="#{pr.sProductName}" id="l2" />
            </p:column>




            <p:column>

                <p:commandButton id="btn" value="Edit" onclick = "getupc(#{pr.lUpc})" >

                </p:commandButton>
            </p:column>

        </p:dataTable>




    <p:panel header="Export All Data">

    <h:commandLink value="export as excel sheet">

        <p:dataExporter type="xls"  target="dataTableId" fileName="myexcel" />

    </h:commandLink>
    </p:panel>
jsf primefaces apache-poi
1个回答
0
投票

尝试评论此行:编辑按钮 </ f:facet> - >

© www.soinside.com 2019 - 2024. All rights reserved.