以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请教专业报表汇总模式,合并单元格  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=159714)

--  作者:冷泉
--  发布时间:2021/1/5 23:19:00
--  请教专业报表汇总模式,合并单元格
按客户名称汇总模式生成的专业报表,第一列客户名称需要单元格合并,帮助里面的合并单元格的代码应该如何整合进去? 研究了几天弄不出来,麻烦老师帮忙完善下代码,谢谢!


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20210105231034.jpg
图片点击可在新窗口打开查看


Dim doc As New PrintDoc
Dim rt As New Prt.RenderTable
Dim rx As prt.RenderText
Dim cnt As Integer
Dim tbl As Table = Tables("订单明细")
Dim drs As List(Of DataRow)
Dim pds As List(Of String) = tbl.DataTable.GetValues("客户名称",tbl.Filter)

rt.Style.GridLines.All = New prt.LineDef(0.1,Color.LightGray)
rt.CellStyle.Spacing.All = 1
rt.Style.FontSize = 10.5 \'字体大小为16磅
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中排列
rt.Rows(0).Style.FontBold = True \'字体加粗
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中排列
rt.Rows(0).Style.TextAlignVert = prt.AlignVertEnum.Center \'内容垂直居中
rt.Rows(0).Style.FontSize = 11 \'字体大小为16磅

For c As Integer = 0 To tbl.Cols.Count - 1 \'生成列标题
    rt.Cells(0,c).Text = tbl.Cols(c).Name    
    rt.Rows(0).Height=7
    rt.Cols(0).Width = 50
    rt.Cols(1).Width = 50
    rt.Cols(2).Width = 30
    rt.Cols(3).Width = 30
    rt.Cols(4).Width = 30    
Next

For Each pd As String In pds \'分产品打印
    If tbl.Filter > "" Then
        drs = tbl.DataTable.Select("客户名称 = \'" & pd & "\' And " & tbl.Filter)
    Else
        drs = tbl.DataTable.Select("客户名称 = \'" & pd & "\'" )
    End If

    For Each dr As DataRow In drs \'逐行打印此产品的订单
        cnt = rt.Rows.Count
        For c As Integer = 0 To tbl.Cols.Count - 1
            rt.Cells(cnt, c).Text = dr(tbl.Cols(c).Name)
        Next
    Next

    cnt = rt.Rows.Count
    rt.Cells(cnt, 0).Text = pd & "合计 "  \'打印产品的小计
    rt.Cells(cnt, 0).style.TextAlignHorz = prt.AlignHorzEnum.right \'水平居中排列
    rt.Cells(cnt, 0).Style.FontBold = True \'字体加粗
    rt.Cells(cnt, 0).Style.FontSize = 10.5 \'大体大小为16磅
    rt.Cells(cnt, 2).Style.FontBold = True \'字体加粗
    rt.Cells(cnt, 2).Style.FontSize = 10.5 \'大体大小为16磅
    rt.Cells(cnt, 3).Style.FontBold = True \'字体加粗
    rt.Cells(cnt, 3).Style.FontSize = 10.5 \'大体大小为16磅
    rt.Cells(cnt,0).SpanCols = 2 \'第5行第2个单元格向右合并3列(用于显示地址)
    rt.Cells(cnt,2).Text = tbl.compute("Sum(数量)", "客户名称 = \'" & pd & "\'") & "件"
    rt.Cells(cnt,3).Text = tbl.compute("Sum(欠款)", "客户名称 = \'" & pd & "\'") & "元"
Next

doc.Body.Children.Add(rt)
doc.preview()

--  作者:有点蓝
--  发布时间:2021/1/6 8:38:00
--  
For Each pd As String In pds \'分产品打印
    If tbl.Filter > "" Then
        drs = tbl.DataTable.Select("客户名称 = \'" & pd & "\' And " & tbl.Filter)
    Else
        drs = tbl.DataTable.Select("客户名称 = \'" & pd & "\'" )
    End If
dim c1 as integer = rt.Rows.Count
    For Each dr As DataRow In drs \'逐行打印此产品的订单
        cnt = rt.Rows.Count
        For c As Integer = 0 To tbl.Cols.Count - 1
            rt.Cells(cnt, c).Text = dr(tbl.Cols(c).Name)
        Next
    Next
rt.Cells(c1,0).SpanRows = drs.count
    cnt = rt.Rows.Count
    rt.Cells(cnt, 0).Text = pd & "合计 "  \'打印产品的小计

--  作者:白国栋
--  发布时间:2021/1/12 23:00:00
--  
专业报表的程序放哪里啊?是设计一个按钮吗?
--  作者:有点蓝
--  发布时间:2021/1/12 23:18:00
--  
一般放到按钮事件里
--  作者:riverzhang163
--  发布时间:2022/8/23 10:10:00
--  
如果产品名称也要合并单元格,要怎么写?谢谢!
--  作者:有点蓝
--  发布时间:2022/8/23 10:38:00
--  
For Each pd As String In pds \'分产品打印
    If tbl.Filter > "" Then
        drs = tbl.DataTable.Select("客户名称 = \'" & pd & "\' And " & tbl.Filter)
    Else
        drs = tbl.DataTable.Select("客户名称 = \'" & pd & "\'" )
    End If
dim c1 as integer = rt.Rows.Count
dim c2 as integer = rt.Rows.Count
dim ci as integer = 0
    For i as integer = 0 to drs.count - 1 \'逐行打印此产品的订单
dim dr a datarow = drs (i)
        cnt = rt.Rows.Count
        For c As Integer = 0 To tbl.Cols.Count - 1
if i > 0 andalso c = 1 then
if drs (i-1)(tbl.Cols(c).Name) <> dr(tbl.Cols(c).Name) then
dim rr as integer = i - ci
rt.Cells(c2,1).SpanRows = rr
c2 = c2 + rr
ci = i
end if
end if
            rt.Cells(cnt, c).Text = dr(tbl.Cols(c).Name)
        Next
    Next
rt.Cells(c1,0).SpanRows = drs.count
    cnt = rt.Rows.Count
    rt.Cells(cnt, 0).Text = pd & "合计 "  \'打印产品的小计