以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  专业报表 分组错误  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=176693)

--  作者:yifan3429
--  发布时间:2022/4/23 1:06:00
--  专业报表 分组错误
 Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim tbl As Table = Tables("订单_产品主表")
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("区域名称")
doc.Pagesetting.LandScape = True
For Each Region As String In Regions
    rx = New prt.RenderText
    rx.Style.FontSize = 14
    rx.Style.FontBold = True
    rx.Style.Spacing.Bottom = 2
    rx.Text = "区域: " & Region
    doc.Body.Children.Add(rx)
    rt = New prt.RenderTable
    rt.Style.Font = Tables("订单_产品主表").Font
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center
    rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray)
    rt.Style.Spacing.Bottom = 5
    rt.CellStyle.Spacing.All = 1
    rt.Style.Font = tbl.Font
    Rows = tbl.DataTable.Select("[区域名称] = \'" & Region & "\'")
    
    Dim tb As Table = Tables("订单_产品主表")
    Dim ColNames As String() = New String(){"区域楼层","区域名称","订单类别","产品名称","图片","工艺描述","销售单价","计价单位","数量","金额小计","备注"}
    rt.Style.Font = tb.Font
    For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容
        rt.Cells(0,c).Text = ColNames(c) \'列名作为标题
        rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中
        If ColNames(c) <> "备注" Then \'
            rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth
        End If
        For r As Integer = 0 To tb.Rows.Count -1 \'开始填入该列内容
            rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
        Next
    Next
    rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线
    rt.CellStyle.Spacing.All = 0.5 \'单元格内距设为0.5毫米
    rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中
    rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头.
    doc.Body.Children.Add(rt) \'将表格加入到报表
Next
doc.preview()

上面的分组不精准  每个分组包含了所有内容没有区分
  需求是只能包含筛选出来的行 如下图餐厅下面就只有属于 区域名称 餐厅的内容。而不是全部 下面厨房如此需求


图片点击可在新窗口打开查看此主题相关图片如下:企业微信截图_20220423010318.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2022/4/23 1:07:29编辑过]

--  作者:程兴刚
--  发布时间:2022/4/23 1:41:00
--  
 Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim tbl As Table = Tables("订单_产品主表")
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("区域名称")
doc.Pagesetting.LandScape = True
For Each Region As String In Regions
    rx = New prt.RenderText
    rx.Style.FontSize = 14
    rx.Style.FontBold = True
    rx.Style.Spacing.Bottom = 2
    rx.Text = "区域: " & Region
    doc.Body.Children.Add(rx)
    rt = New prt.RenderTable
    rt.Style.Font = Tables("订单_产品主表").Font
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center
    rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray)
    rt.Style.Spacing.Bottom = 5
    rt.CellStyle.Spacing.All = 1
    rt.Style.Font = tbl.Font
    Rows = tbl.DataTable.Select("[区域名称] = \'" & Region & "\'")
    
    Dim tb As Table = Tables("订单_产品主表")
    Dim ColNames As String() = New String(){"区域楼层","区域名称","订单类别","产品名称","图片","工艺描述","销售单价","计价单位","数量","金额小计","备注"}
    rt.Style.Font = tb.Font
For r As Integer = 0 To tb.Rows.Count -1 \'开始填入该列内容
    For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容
if r = 0
        rt.Cells(0,c).Text = ColNames(c) \'列名作为标题
        rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中
        If ColNames(c) <> "备注" Then \'
            rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth
        End If
end if
            rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
next
        Next
    rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线
    rt.CellStyle.Spacing.All = 0.5 \'单元格内距设为0.5毫米
    rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中
    rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头.
    doc.Body.Children.Add(rt) \'将表格加入到报表
Next
doc.preview()


手机改的,自己排一下版!
[此贴子已经被作者于2022/4/23 11:10:39编辑过]

--  作者:yifan3429
--  发布时间:2022/4/23 9:33:00
--  
 ---------------------------
错误
---------------------------
编译错误:“c”是一个类型,不能用作表达式。



错误代码:rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
---------------------------
确定   
---------------------------


--  作者:有点蓝
--  发布时间:2022/4/23 10:00:00
--  
   For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容
        rt.Cells(0,c).Text = ColNames(c) \'列名作为标题
        rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中
        If ColNames(c) <> "备注" Then \'
            rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth
        End If
        For r As Integer = 0 To Rows .Count -1 \'开始填入该列内容
            rt.Cells(r + 1, c).Text = Rows (r)(ColNames(c))
        Next
    Next
--  作者:程兴刚
--  发布时间:2022/4/23 10:40:00
--  
再用2楼代码试试,手机编写不方便,这一段应放循环里:
else
            rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
end if
[此贴子已经被作者于2022/4/23 10:45:50编辑过]