手工编码生成

 

前面我们介绍了根据DataTable和Table自动生成网页的方法,简单到只需一行代码。
 

如果需要对细节做更多的控制,则需要手工编码,不过也不要担心,代码依然简单,因为这是Foxtable嘛。

 

一个例子

 

下面的HttpRequest事件代码,从订单表中提取数量超过100的订单,按日期顺序生成网页表:

 

Select Case e.Path

    Case "table.htm"

        Dim wb As New WeUI

        With wb.AddTable("","Table1")

            .Alternate = 3

            Dim nms() As String = {"产品","客户","数量","单价","日期"}

            .Head.AddRow(nms)

            For Each r As DataRow In DataTables("订单").Select("数量 > 100", "日期 Desc")

                With .Body.AddRow(r("产品"),r("客户"),r("数量"))

                    .AddCell(Format(r("单价"),"#0.00"))

                    .AddCell(Format(r("日期"),"MMdd"))

                End With

            Next

        End With

        e.WriteString(wb.Build)

End Select

 

这是在手机上访问的效果:

 

 

加上行号

 

如果希望显示行号,可以参考下面的HttpRequest事件代码:

 

Select Case e.Path

    Case "table.htm"

        Dim wb As New WeUI

        With wb.AddTable("","Table1")

            .Alternate = 3

            .RowHead = 1

            .ColWidth = "12px"

            Dim nms() As String = {"","产品","客户","数量","单价","日期"}

            .Head.AddRow(nms)

            Dim cnt As Integer

            For Each r As DataRow In DataTables("订单").Select("数量 > 100", "日期 Desc")

                cnt = cnt + 1

                With .Body.AddRow(cnt, r("产品"), r("客户"), r("数量"))

                    .AddCell(Format(r("单价"), "#0.00"))

                    .AddCell(Format(r("日期"), "MMdd"))

                End With

            Next

        End With

        e.WriteString(wb.Build)

End Select

 

多层表头

 

假定有下图所示的一个已知结构的有多层表头的数据表:

 

 

如果要根据这个表生成网页,可以参考下面的HttpRequest事件代码:

 

Select Case e.Path

    Case "table.htm"

        Dim wb As New WeUI

        With wb.AddTable("","Table1")

            '下面这个数组,用实际的列名.

            Dim nms() As String = {"产品","东部_一季度","东部_二季度","东部_三季度","东部_四季度","南部_一季度","南部_二季度","南部_三季度","南部_四季度"}

            .Head.AddRow("产品","东部","东部","东部","东部","西部","西部","西部","西部") '第一层标题

            .Head.AddRow("产品","一季度","二季度","三季度","四季度","一季度","二季度","三季度","四季度") '第二层标题

            For Each r As DataRow In DataTables("表名").DataRows

                With .Body.AddRow()

                    For Each nm As String In nms

                        .AddCell(r(nm))

                    Next

                End With

            Next

        End With

        e.WriteString(wb.Build)

End Select

 


本页地址:http://www.foxtable.com/mobilehelp/topics/0072.htm