XPages - 使用 POI 4 XPages 并且它在 $ 符号导出到 Word/PDF 时出错

XPages - using POI 4 XPages and it errors on $ symbol exporting to Word/PDF

我正在为我的 Xpage 使用出色的 POI4Xpages 插件。它可以很好地将网页映射到 Word 或 PDF,但我注意到当 Xpage/Notes 文档的任何字段中有美元符号 ($) 时它就会爆炸。

现在,我对用户的解决方法是用 USD 代替 $ 符号,但我的用户和我希望它能处理 $。

我在下面附上了错误转储。

非常感谢关于从哪里开始(和结束)的建议。提前谢谢你。

POI 4 XPages -> ERROR
--------------------------------------------------------------
Error    : Error during Documentgeneration
POI LIB  : 1.2.6.201312211419
StackTrace:
java.lang.IllegalArgumentException: Illegal group reference
    at java.util.regex.Matcher.appendReplacement(Matcher.java:724)
    at java.util.regex.Matcher.replaceAll(Matcher.java:824)
    at java.lang.String.replaceAll(String.java:1591)
    at         biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks2Run(DocumentProcessor.java:129)
    at     biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks    2Paragraph(DocumentProcessor.java:118)
    at     biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks    2Table(DocumentProcessor.java:110)
    at     biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processBookmarks    2Document(DocumentProcessor.java:84)
    at     biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.processDocument(    DocumentProcessor.java:193)
at     biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.generateNewFile(    DocumentProcessor.java:143)
    at     biz.webgate.dominoext.poi.component.containers.UIDocument.processAjaxRequest(    UIDocument.java:208)
    at     biz.webgate.dominoext.poi.component.actions.DocumentGenerationServerAction.in    voke(DocumentGenerationServerAction.java:48)
    at     com.ibm.xsp.application.ActionListenerImpl.processAction(ActionListenerImpl.j    ava:60)
    at javax.faces.component.UICommand.broadcast(UICommand.java:324)
    at     com.ibm.xsp.component.UIEventHandler.broadcast(UIEventHandler.java:366)
    at     com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
    at     com.ibm.xsp.extlib.component.layout.UIVarPublisherBase.broadcast(UIVarPublish    erBase.java:185)
    at         com.ibm.xsp.component.UIViewRootEx.broadcast(UIViewRootEx.java:1535)
    at         javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:307)
    at     javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:428)
    at     com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase    .java:94)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96)
    at     com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:2    56)
    at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:228)
    at     com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
    at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
    at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
    at     com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103    )
    at     com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(Compone    ntModule.java:576)
    at     com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentMo    dule.java:1335)
    at     com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invoke    Servlet(ComponentModule.java:853)
    at     com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doServ    ice(ComponentModule.java:796)
    at     com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentMo    dule.java:565)
    at     com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule    .java:1319)
    at     com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:66    2)
    at     com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
    at     com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironme    nt.java:357)
    at     com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment    .java:313)
    at     com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.jav    a:272)

我们遇到了同样的问题,基本上做了如下黑客攻击,如果我们找到小数点,就在 $ 前加上前缀。希望这对您有所帮助。

function process(xwpfdocument){

    try{
        // Get POI Document
        var x = xwpfdocument;
        var tables:java.util.Iterator = x.getTablesIterator();
        while(tables.hasNext()){
            var t = tables.next();
            var numRows = t.getNumberOfRows();
            // Loop Through All Rows
            if(numRows>0){
                for(var row=0; row<numRows; row++){
                    var cellList:java.util.List = t.getRow(row).getTableCells();
                    var numCells = cellList.size();
                    // Loop through all Cells
                    for(var cell=0; cell<numCells; cell++){
                        var c = cellList.get(cell);
                        var paragraphs:java.util.List = c.getParagraphs();
                        // Loop through all Paragraphs
                        for(var para=0; para<paragraphs.size();para++){
                            var p = paragraphs.get(para);
                            var runs:java.util.List = p.getRuns();
                            // Loop through all Runs
                            for(var r=0;r<runs.size();r++){
                                var run = runs.get(r);
                                var txt=run.getText(0);
                                if(txt.indexOf("<NL>")>-1){
                                    var newRun = p.createRun();
                                    var newTxt = txt.split("<NL>");
                                    for(var n=0; n<newTxt.length; n++){
                                        // Add New Runs with Breaks
                                        var prefix = "";
                                        if(newTxt[n].indexOf(".")>-1){
                                            prefix = "$";
                                        }
                                        newRun.setText(@Text(prefix+newTxt[n]));
                                        newRun.addBreak();
                                    }
                                    //Delete old run
                                    //p.removeRun(0);
                                } else { //added for cases with only one account
                                    var newRun = p.createRun();
                                    var prefix = "";
                                    if(txt.indexOf("%")>-1) { //added so SS002, SS003, and SS004 keep the %, added from the Letter.getBookmarkAPR function, rather than prepending a $
                                        //nothing required
                                    } else if(txt.indexOf(".")>-1){
                                        prefix = "$";
                                    }
                                    newRun.setText(@Text(prefix+txt));
                                }
                                //Delete old run
                                p.removeRun(0);
                            }
                        }
                    }
                }
            }
        }
    } catch(e){
        // Write to Log
        system.out.println(e.getLocalizedMessage());
    }
    //Done
    return;
}

Christian Güdemann 发布了一个新版本,解决了文本字段中间的 $ 字符问题。

http://www.webgate.biz/ftp/openntf/POI4XPages/snapshot/biz.webgate.dominoext.poi-1.3.0-SNAPSHOT.zip

顺便说一句,有一个邮件列表可以了解开发版本: http://mm.wgcdev.ch/mailman/listinfo

感谢您的帮助,Dwain 和 Christian!