以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  无法找到列-1  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=94300)

--  作者:刘林
--  发布时间:2016/12/20 19:36:00
--  无法找到列-1
Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim tbl= Tables("学生信息_table1")
tbl.sort = "班级,学生姓名"
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String()) = tbl.DataTable.GetValues("年级,班级") \'\'\'\'改后句子
Dim rm As prt.RenderEmpty
Doc.PageSetting.LeftMargin = 5 \'设置左边距
Doc.PageSetting.RightMargin = 5 \'设置右边距
Doc.PageSetting.TopMargin = 5 \'设置上边距
Doc.PageSetting.BottomMargin = 5 \'设置下边距
For Each region As String() In Regions
    rm = new prt.RenderEmpty \'定义一个新的空对象
    rm.BreakBefore = prt.BreakEnum.Page \'打印前换页
    doc.Body.Children.Add(rm)
    rx = New prt.RenderText
    rx.Style.Font = New Font("黑体", 16, FontStyle.Bold) \'
    rx.Style.FontBold = True
    rx.Style.Spacing.Bottom = 2
    rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center
    rx.Text =  Region(0) & "学生基本信息表"
    doc.Body.Children.Add(rx)
    rt = New prt.RenderTable
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中
    rt.Style.GridLines.All = New prt.LineDef(0.3,Color.black)
    rt.Width = "auto"
    rt.Style.Font = New Font("宋体", 8)
    Rows = tbl.DataTable.Select("[班级] =\'" & region(1) &  "\'", "学生姓名")
    For c As Integer = 0 To tbl.Cols.Count -1 \'
        If tbl.Cols(c).Visible Then
            rt.Cells(0,c).Text = tbl.Cols(c).Name
        End If
        Dim r As Integer
        For r = 0 To Rows.Count -1
            rt.Rows(0).Height = 5
            rt.Rows(r+1).height = 4
            rt.Cells(r+1,c).Text = rows(r)(tbl.Cols(c).Name)
        Next     
    Next
  rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
    doc.Body.Children.Add(rt)
Next
doc.preview()

老师,上面的代码总是说:         无法找到列 -1。请问是什么问题

--  作者:有点蓝
--  发布时间:2016/12/20 20:23:00
--  
http://www.foxtable.com/webhelp/scr/2747.htm,认认真真看几遍示例六

调试技巧:http://www.foxtable.com/webhelp/scr/1485.htm,自己学会调试代码,看是那一句代码有问题

--  作者:刘林
--  发布时间:2016/12/20 20:42:00
--  
Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim tbl= Tables("学生信息_table1")
tbl.sort = "班级,学生姓名"
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String()) = tbl.DataTable.GetValues("班级") \'\'\'\'改后句子
Dim rm As prt.RenderEmpty
Doc.PageSetting.LeftMargin = 5 \'设置左边距
Doc.PageSetting.RightMargin = 5 \'设置右边距
Doc.PageSetting.TopMargin = 5 \'设置上边距
Doc.PageSetting.BottomMargin = 5 \'设置下边距
For Each region As String() In Regions
    rm = new prt.RenderEmpty \'定义一个新的空对象
    rm.BreakBefore = prt.BreakEnum.Page \'打印前换页
    doc.Body.Children.Add(rm)
    rx = New prt.RenderText
    rx.Style.Font = New Font("黑体", 16, FontStyle.Bold) \'
    rx.Style.FontBold = True
    rx.Style.Spacing.Bottom = 2
    rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center
    rx.Text =  Region(0) & "学生基本信息表"
    doc.Body.Children.Add(rx)
    rt = New prt.RenderTable
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中
    rt.Style.GridLines.All = New prt.LineDef(0.3,Color.black)
    rt.Width = "auto"
    rt.Style.Font = New Font("宋体", 8)
    Rows = tbl.DataTable.Select("[班级] =\'" & region(0) &  "\'", "学生姓名")
    For c As Integer = 0 To tbl.Cols.Count -1 \'
        If tbl.Cols(c).Visible Then
            rt.Cells(0,c).Text = tbl.Cols(c).Name
        End If
        Dim r As Integer
        For r = 0 To Rows.Count -1
            rt.Rows(0).Height = 5
            rt.Rows(r+1).height = 4
            rt.Cells(r+1,c).Text = rows(r)(tbl.Cols(c).Name)
        Next     
    Next
  rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
    doc.Body.Children.Add(rt)
Next
doc.preview()
改了一下,又提示  无法将类型为“System.Collections.Generic.List`1[System.String]”的对象强制转换为类型“System.Collections.Generic.List`1[System.String[]]”。

--  作者:刘林
--  发布时间:2016/12/20 20:46:00
--  
找到了


--  作者:刘林
--  发布时间:2016/12/20 21:01:00
--  
如何只打印加载到表中显示了的列
--  作者:有点蓝
--  发布时间:2016/12/20 22:06:00
--  
http://www.foxtable.com/webhelp/scr/0572.htm

if Tables("订单").Cols("折扣").Visible = True then
打印
else
不打印
end if