2016-07-15 63 views
1

我正在写一个Java应用程序来创建一个将用于报告的HTML文件。我正在使用wffweb来创建HTML文档。 我想以编程方式创建一个表作为下面提及:如何使用wffweb创建具有colspan属性的Td?

<table> 
<tr> 
    <td> Column 1 <td> 
    <td> Column 2 <td> 
    <td> Column 3 <td> 
    <td> Column 3 <td> 
</tr> 
<tr> 
    <td> Column 1 <td> 
    <td colspan="3"> Column 2 <td> 
</tr> 
</table> 

是否有任何可能的方式来创建跨越使用wffweb多列列?

回答

2

您可以使用CustomAttribute类为td TAG提供colspan属性。下面是示例代码

public static void main(String[] args) { 

    Html html = new Html(null) { 
     Body body = new Body(this) { 
      Table table = new Table(this, new CustomAttribute("border", 
        "1px")) { 

       { 
        Tr tr = new Tr(this) { 
         Td td1 = new Td(this) { 
          Blank cellContent = new Blank(this, "1"); 
         }; 
         Td td2 = new Td(this) { 
          Blank cellContent = new Blank(this, 
            "First Name"); 
         }; 
         Td td3 = new Td(this) { 
          Blank cellContent = new Blank(this, "Last Name"); 
         }; 
        }; 
        Tr tr1 = new Tr(this) { 
         Td td1 = new Td(this, new CustomAttribute(
           "colspan", "3")) { 
          Blank cellContent = new Blank(this, 
            "First Name"); 
         }; 

        }; 

       } 

      }; 
     }; 
    }; 

    html.setPrependDocType(true); 
    System.out.println(html.toHtmlString()); 
} 
+0

谢谢,这是我一直在寻找。 –

相关问题