有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用xdocreport和velocity以行格式显示列表数据

    Java code:
    ------------------------------------
    List dosData = new ArrayList();

    for (int x = 0; x < ti.getRowCount(); x++){
    String[] rowContent = ti.getRow(x);

    List<String> listData = new ArrayList<String>();

    for(int i = 0;i<rowContent.length;i++){
    listData.add(rowContent[i]);
    }
    dosData.add(listData);
    }

    If I print dosData variable:

    system.out.println(dosData);

    --------------------
    [1/3/2014, 3/4/2014,|(list contains lists)
    cd1, decs1]         |
    ------------------- |
    [1/3/2014, 3/4/2014,|
    cd2, decs2]         |
    ------------------- |
    [1/3/2014, 3/4/2014,|
    cd3, decs3]         |
    ------------------- |
    [1/3/2014, 3/4/2014,|
     cd4, decs4]         |
    ------------------- 

    I want to display above content in word document in the form row format, I have tried below code   to display

  ------------------------------------------
    «@before-cell#foreach($d in $dosData)»  |
    «@before-cell#foreach($f in $d)»        |
    «$f»                                    |
    «@after-cell#end»                       |
    «@after-cell#end»                       |
 --------------------------------------------
Its working,But it is not getting required format what we want,Below is the expected result what we want.

    Expected format:
    ---------------

    1/3/2014    3/4/2014 cd1 decs1
    1/3/2014    3/4/2014 cd2 decs2
    1/3/2014    3/4/2014 cd3 decs3
    1/3/2014    3/4/2014 cd4 decs4

当我在word文档中运行上述代码时得到的实际格式(错误格式):我们得到的响应是线性的

2014年1月3日2014年3月4日cd1 decs1 1/3/2014年3/4/2014 cd2 decs2 1/3/2014 3/4/2014 cd3 decs3 1/3/2014 3/4/2014 cd4 decs4

    Please help me on this any one ...

共 (1) 个答案

  1. # 1 楼答案

    你需要在内环后面加一个新行字符

    «@before-cell#foreach($d in $dosData)»  |
    «@before-cell#foreach($f in $d)»        |
    «$f»                                    |
    «@after-cell#end»    
    new line character                   |
    «@after-cell#end»  
    

    新行字符可以是\n、\r或\n\r