Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共7 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:专业报表调取后台数据如何合并单元格?

1楼
唐尸三摆手 发表于:2010/5/14 8:16:00
请问老大,专业报表调取后台数据如何合并单元格(如何展现合并模式结果)?
2楼
狐狸爸爸 发表于:2010/5/14 8:19:00

打印三列,合并第一列:

 

Dim doc As New PrintDoc '定义一个新报表
Dim rt As New prt.RenderTable '定义一个新表格
Dim tb as Table = Tables("订单")
Dim ColNames As String() = New String(){"产品", "日期", "数量"}
rt.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
rt.CanSplitHorz = True '表格宽度超出页宽时,可以水平换页
rt.Style.Font = tb.Font
Dim lr As Integer
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 '标题内容水平居中
    rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth '列宽等于实际列宽
    If tb.Cols(ColNames(c)).IsNumeric Orelse tb.Cols(ColNames(c)).IsDate Then '如果是数值或日期列
        rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
    End If
    For r As integer = 0 To tb.Rows.Count -1 '开始填入该列内容
        If c = 0 then
            if (r = 0 orelse tb.Rows(r)(ColNames(c)) <> tb.Rows(r - 1)(ColNames(c))) Then
                rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
                lr = r + 1
            Else
                rt.cells(lr,c).SpanRows  = rt.cells(lr,c).SpanRows  + 1
            End If
        Else
            rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
        End If
    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) '将表格加入到报表
doc.Preview()

3楼
唐尸三摆手 发表于:2010/5/14 8:33:00

谢谢老大及时回复

4楼
唐尸三摆手 发表于:2010/5/14 8:44:00
再请教老大,假如“订单”表前三列都要合并模式,(产品、客户、雇员)要如何改动上面的代码呢?
5楼
狐狸爸爸 发表于:2010/5/14 8:54:00

第二列合并的前提是前两列的内容和上一行相同,第三列合并的条件是前三列和上一行相同,你根据条件,自行修改吧。

6楼
gdtgl 发表于:2010/5/16 11:01:00

楼主要的是这样的效果吧

 


图片点击可在新窗口打开查看此主题相关图片如下:合并.jpg
图片点击可在新窗口打开查看
7楼
gdtgl 发表于:2010/5/16 11:02:00
Dim doc As New PrintDoc
Dim rt As New prt.RenderTable
Dim tb as Table = Tables("订单")
tb.Sort = "产品,客户,雇员"
'rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
rt.Style.Font = tb.Font
rt.Style.GridLines.All = prt.Linedef.Default
rt.CellStyle.Spacing.All = 1
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center
Dim FirstRow As Integer = 1
    rt.Cells(0,0).Text = "产品"
    rt.Cells(0,1).Text = "客户"
    rt.Cells(0,2).Text = "雇员"
    For r As integer = 0 To tb.Rows.Count -1
        If tb(r,0) Is Nothing Then
            Continue for
        End if
        rt.Cells(r+1, 1).Text = tb(r,1)
        rt.Cells(r+1, 2).Text = tb(r,2)
        rt.Cells(r+1, 3).Text = tb(r,3)
        If r > 0 AndAlso tb(r,0) = tb(r-1,0) Then
               rt.Cells(FirstRow,0).SpanRows =  rt.Cells(FirstRow,0).SpanRows  + 1
               if tb(r,1) = tb(r-1,1) then
                   rt.Cells(FirstRow,1).SpanRows =  rt.Cells(FirstRow,1).SpanRows  + 1
               end if
               if tb(r,2) = tb(r-1,2) then
                   rt.Cells(FirstRow,2).SpanRows =  rt.Cells(FirstRow,2).SpanRows  + 1
               end if
            
            Else
                 rt.Cells(r+1, 0).Text = tb(r,0)
                 FirstRow = r + 1
         End if
    Next
doc.Body.Children.Add(rt)
doc.Preview()
共7 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03906 s, 2 queries.