以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  相同的第一列如何合并成一个单元格?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=151330)

--  作者:hzcaqjf
--  发布时间:2020/6/20 19:24:00
--  相同的第一列如何合并成一个单元格?
相同的"线路"列如何合并成一个单元格(如图)?

图片点击可在新窗口打开查看此主题相关图片如下:a.png
图片点击可在新窗口打开查看

代码如下:
Tables("现金录入").sort = "序号"
Dim doc As New PrintDoc \'定义一个新报表

doc.PageSetting.PaperKind = 9  \'A4纸
doc.PageSetting.Landscape = False \'竖向打印
doc.PageSetting.LeftMargin = 10 \'设置左边距
doc.PageSetting.RightMargin = 10 \'设置右边距
doc.PageSetting.TopMargin = 10 \'设置上边距
doc.PageSetting.BottomMargin = 10 \'设置下边距

Dim rt As Prt.RenderTable
rt = New prt.RenderTable
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
\'rt.Style.GridLines.All = New prt.LineDef(0.1,Color.White)    \'无边框
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线
rt.CellStyle.Spacing.All = 0.2
rt.Style.Font = New Font("宋体",9)
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中
Dim cnt As Integer
Dim tbl As Table = Tables("现金录入")
Dim ColNames As String() = New String(){"线路","车号","纸币","硬币","金额"}
Dim ColWidths As String() = New String(){"20", "25", "25","30","30"}
Dim drs As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("线路","","序号")
For c As Integer = 0 To ColNames.Length - 1
    rt.Cells(0,c).Text = ColNames(c)
    rt.Cols(c).Width = ColWidths(c)
Next
rt.cells(0,2).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.cells(0,3).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.cells(0,4).Style.TextAlignHorz = prt.AlignHorzEnum.Center 
For Each pd As String In Regions
    drs = tbl.DataTable.Select("[线路] = \'" & pd & "\'","序号")
    Dim m As Integer = drs.count \'记录每条线路的行数
    For Each dr As DataRow In drs
        cnt = rt.Rows.Count \'报表总行数
       \' 这里cnt 以1,3,5,7,9......递增,不能理解.
        For c As Integer = 0 To ColNames.Length - 1
            If tbl.Cols(ColNames(c)).IsNumeric  Then
                If dr(ColNames(c)) <> 0 Then
                    rt.Cells(cnt + 1, c).Text = Format(dr(tbl.Cols(ColNames(c)).Name),"0.0")
                    rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right
                End If
            Else
                rt.Cells(cnt + 1, c).Text = dr(tbl.Cols(ColNames(c)).Name)
                rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.center
            End If
        Next
    Next
    cnt = rt.Rows.Count
    rt.Cells(cnt, 0).Text = "小计 " & pd    
    rt.Cells(cnt,2).Text = Format(tbl.compute("Sum(纸币)", "线路 = \'" & pd & "\'"),"0.0")
    rt.Cells(cnt,3).Text = Format(tbl.compute("Sum(硬币)", "线路 = \'" & pd & "\'"),"0.0")
    rt.Cells(cnt,4).Text = Format(tbl.compute("Sum(金额)", "线路 = \'" & pd & "\'"),"0.0")
    rt.Cells(cnt-m,0).SpanRows = m  \'问题出在此处,应怎样修改?
    rt.Cells(cnt,0).SpanCols = 2 
Next
cnt = rt.Rows.Count
rt.Cells(cnt, 0).Text = "合计 " \'打印合计
rt.Cells(cnt, 2).Text = Format(tbl.compute("Sum(纸币)"),"0.0")
rt.Cells(cnt, 3).Text = Format(tbl.compute("Sum(硬币)"),"0.0")
rt.Cells(cnt, 4).Text = Format(tbl.compute("Sum(金额)"),"0.0")
Doc.Columns.Add() \'增加第一栏
Doc.Columns.Add() \'增加第二栏
Doc.Columns.Add() \'增加第三栏
Doc.Columns(0).Spacing = 3
Doc.Columns(1).Spacing = 3
Doc.Body.Children.Add(rt)

Dim ra As New prt.RenderArea
Dim rx As New prt.RenderText
Dim tm As Date = e.Form.Controls("DateTimePicker1").value
rx.Text = "车售款明细表 (" & Format(tm,"yyyy年MM月dd日") & ")"
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center
rx.Style.Padding.Bottom = 0.5
rx.Style.Font = New Font("黑体",11)
ra.Children.Add(rx)
Doc.PageHeader = ra

rx = New prt.RenderText \'设置文本对象的内容
Dim cmb As String = e.Form.Controls("CheckedComboBox1").value
rx.Text = "点钞人员: " & cmb
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right \'靠右对齐
rx.Style.Padding.Bottom = 0.5 \'底端内容缩进0.5毫米
rx.Style.FontSize = 8 \'字体大小为8磅
Doc.PageFooter = rx

doc.Preview() \'预览

[此贴子已经被作者于2020/6/20 19:25:04编辑过]

--  作者:有点蓝
--  发布时间:2020/6/21 20:36:00
--  
……
rt.cells(0,2).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.cells(0,3).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.cells(0,4).Style.TextAlignHorz = prt.AlignHorzEnum.Center 
For Each pd As String In Regions
    drs = tbl.DataTable.Select("[线路] = \'" & pd & "\'","序号")
    Dim m As Integer = drs.count \'记录每条线路的行数
cnt = rt.Rows.Count+1 \'报表总行数
    For Each dr As DataRow In drs
        For c As Integer = 1 To ColNames.Length - 1
            If tbl.Cols(ColNames(c)).IsNumeric  Then
                If dr(ColNames(c)) <> 0 Then
                    rt.Cells(cnt, c).Text = Format(dr(tbl.Cols(ColNames(c)).Name),"0.0")
                    rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right
                End If
            Else
                rt.Cells(cnt, c).Text = dr(tbl.Cols(ColNames(c)).Name)
                rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.center
            End If
        Next
cnt += 1
    Next
rt.Cells(cnt-m,0).SpanRows = m 
rt.Cells(cnt -m , 0).Text = pd
cnt += 1
    rt.Cells(cnt, 0).Text = "小计 " & pd    
    rt.Cells(cnt,2).Text = Format(tbl.compute("Sum(纸币)", "线路 = \'" & pd & "\'"),"0.0")
    rt.Cells(cnt,3).Text = Format(tbl.compute("Sum(硬币)", "线路 = \'" & pd & "\'"),"0.0")
    rt.Cells(cnt,4).Text = Format(tbl.compute("Sum(金额)", "线路 = \'" & pd & "\'"),"0.0")
    rt.Cells(cnt,0).SpanCols = 2 
Next
cnt = rt.Rows.Count
rt.Cells(cnt, 0).Text = "合计 " \'打印合计
……

--  作者:hzcaqjf
--  发布时间:2020/6/21 21:13:00
--  
完全达到预期效果.先谢谢老师,再慢慢学习.