Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LibreOffice计算中的脚本_Java_Freemarker_Libreoffice - Fatal编程技术网

Java LibreOffice计算中的脚本

Java LibreOffice计算中的脚本,java,freemarker,libreoffice,Java,Freemarker,Libreoffice,使用libreofficewriter,我可以在文档中输入脚本(插入->脚本)。它们在.odt-文件的content.xml中显示为..。使用jodreports jar文件时,我可以让这些脚本按照中所述工作 现在我想对其他LibreOffice文档类型执行相同的操作,但是没有在Calc或Impress中插入->脚本的选项。我唯一看到的是宏,但它们存储在单独的xml文件中,而不是content.xml。如果我能在content.xml文件中找到正确的标记来输入脚本,我相信jodreports会完

使用libreofficewriter,我可以在文档中输入脚本(插入->脚本)。它们在
.odt
-文件的
content.xml
中显示为
..
。使用jodreports jar文件时,我可以让这些脚本按照中所述工作

现在我想对其他LibreOffice文档类型执行相同的操作,但是没有在Calc或Impress中插入->脚本的选项。我唯一看到的是宏,但它们存储在单独的xml文件中,而不是
content.xml
。如果我能在
content.xml
文件中找到正确的标记来输入脚本,我相信jodreports会完成这项工作

有什么想法吗

仅支持LO文本或html文件。但是您可以通过将Writer OLE对象插入到计算表中(菜单“
插入”
”->“
对象”
”->“
OLE对象”
”->“
LibreOffice 4.2 Text
”)。在OLE对象中,“
Insert
”->“
Script
”的工作方式与“native”
.odt
文件中的工作方式相同。脚本也将出现在
.ods
文件的
content.xml


编辑:抱歉,没有如我所希望的那样工作-脚本代码实际上将放置在不同的
content.xml
(OLE对象在子目录中有自己的
context.xml
),但不在ods的
content.xml

中,这可以通过更改jodreports代码来解决。这不会在
.odt
文件中添加请求的
标记,因此严格来说,这可能不是对特定问题的回答,但它将解决让jodreports更好地处理LibreOffice Calc文件的根本问题

更改-使用代码-位于文件
ScriptTagFilter.java
中的
net.sf.jooreport.templates.xmlfilters
-包中。在函数
doFilter
中,我替换了

Nodes scriptNodes = document.query("//text:script[translate(@script:language, 'CIJOPRST', 'cijoprst')='jooscript']", XPATH_CONTEXT);


因为在代码中,实际的脚本是逐行读取的,如果将脚本放在一行中,则会失败。只有第一行应该有
--!jooscript:
前缀。

不幸的是(因为我对这个答案非常兴奋),它没有。。。xml中显示的是一个嵌入对象,它指的是ods文件中的一个文件夹“Object1”,其中有一个单独的content.xml用于文本文档。这个单独的文档显示了标记,但是main content.xml没有…哦,你说得对,我只是快速地对示例脚本的内容进行了
grep-R
,没有注意到我在
Object 1
子目录中找到了一个目标。。。我很抱歉!没问题,公平的尝试。如果没有一个stackoverflow天才想出我们缺少的东西,我会回头看看jodreports代码,看看是否可以让它适用于其他标记。
    //WRITER document (odt)
    Nodes odtScriptNodes = document.query("//text:script[translate(@script:language, 'CIJOPRST', 'cijoprst')='jooscript']", XPATH_CONTEXT);
    Nodes scriptNodes = odtScriptNodes;

    //CALC document (ods)
    Nodes odsPotentialScriptNodes = document.query("//table:table-cell", XPATH_CONTEXT);
    for(int nodeIndex = 0; nodeIndex < odsPotentialScriptNodes.size(); nodeIndex++){
        Element tableCellElement = (Element) odsPotentialScriptNodes.get(nodeIndex);
        Elements textElements = tableCellElement.getChildElements();
        if(textElements.size() > 0 && textElements.get(0).getValue().toLowerCase().startsWith("--!jooscript:")){
            String fullScript = textElements.get(0).getValue().substring("--!jooscript:".length());
            for(int elementIndex = 1; elementIndex < textElements.size(); elementIndex++){
                fullScript += System.getProperty("line.separator") + textElements.get(elementIndex).getValue();
            }
            for(int elementIndex = textElements.size()-1; elementIndex > 0; elementIndex--){
                tableCellElement.removeChild(elementIndex);
            }

            Element firstTextElement = (Element) tableCellElement.getChild(0);
            firstTextElement.removeChildren();
            firstTextElement.appendChild(fullScript);
            scriptNodes.append(firstTextElement);
        }
    }
@table:table-row
[#list items as item]
@/table:table-row
[/#list]