使用jopendocument与coldfusion/railo,如何添加表格行?

发布于 2024-12-17 19:12:07 字数 651 浏览 4 评论 0 原文

我正在使用 jopendocument 1.2 和 Railo 3.3.1.000,

来自 http://www.jopendocument.org/start_text_2。 html

List<Map<String, String>> months = new ArrayList<Map<String, String>>();
months.add(createMap("January", "-12", "3"));
months.add(createMap("February", "-8", "5"));
months.add(createMap("March", "-5", "12"));
months.add(createMap("April", "-1", "15"));
months.add(createMap("May", "3", "21"));
template.setField("months", months);

如何在 cfml 中编写该代码,或者任何有 jopendocument 经验的人都可以使用 cfml 在 odt 模板文件中添加行?

I'm using jopendocument 1.2 with Railo 3.3.1.000

from http://www.jopendocument.org/start_text_2.html

List<Map<String, String>> months = new ArrayList<Map<String, String>>();
months.add(createMap("January", "-12", "3"));
months.add(createMap("February", "-8", "5"));
months.add(createMap("March", "-5", "12"));
months.add(createMap("April", "-1", "15"));
months.add(createMap("May", "3", "21"));
template.setField("months", months);

How to write that code in cfml, or anyone have experience with jopendocument to add row in odt template file with cfml?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩心不撩汉 2024-12-24 19:12:07

List>>月 = new ArrayList>();

用 CF 术语来说,该代码创建一个结构体数组。因为 java 是强类型的,所以代码使用泛型来指示每个对象包含什么类型

    List< Map<...> >          // Array containing structures 
    Map< String, String >     // Structure containing "String" values

,幸运的是,CF 数组在内部是 java.util.List 对象,而结构是 java.util.Map > 对象。因此,您只需要使用正确的键和值创建一个 CF 结构数组。然后将数组传递给 template.setField(...)

我不确定在结构中使用哪些键,因此我从 jOpenDocument-template-1.2.zip。它显示每个结构应包含三 (3) 个键,每个键对应表中的每一列:nameminmax。只要您使用字符串填充结构,就应该可以工作:

// Create an array of structures. Each structure represents a table row. 
// The key names for columns 1-3 are: "name", "min", "max"
months = [
            {name="January", min="-12", max="3"}
            , {name="February", min="-8", max="5"}
            , {name="March", min="-5", max="12"}
            , {name="April", min="-1", max="15"}
            , {name="May", min="3", max="21"}
            , {name="June", min="5", max="32"}
        ];  

// populate table rows
template.setField("months", months);

List<Map<String, String>> months = new ArrayList<Map<String,
String>>();

In CF terms, that code creates an array of structures. Because java is strongly typed the code uses generics to indicate what type of objects each one contains

    List< Map<...> >          // Array containing structures 
    Map< String, String >     // Structure containing "String" values

Fortunately CF arrays are java.util.List objects internally and structures are java.util.Map objects. So you only need to create a CF array of structures with the proper keys and values. Then pass the array into template.setField(...).

I was not sure which keys to use in the structure, so I downloaded the "test.odt" template from jOpenDocument-template-1.2.zip. It revealed each structure should contain three (3) keys, one for each column in the table: name, min, max. As long as you populate the structures with strings, this should work:

// Create an array of structures. Each structure represents a table row. 
// The key names for columns 1-3 are: "name", "min", "max"
months = [
            {name="January", min="-12", max="3"}
            , {name="February", min="-8", max="5"}
            , {name="March", min="-5", max="12"}
            , {name="April", min="-1", max="15"}
            , {name="May", min="3", max="21"}
            , {name="June", min="5", max="32"}
        ];  

// populate table rows
template.setField("months", months);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文