以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  专业报表做明细表输出问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=29225)

--  作者:mamuaiqing
--  发布时间:2013/3/2 17:14:00
--  专业报表做明细表输出问题

上传项目,上传图片跟代码先

 

Dim doc As New PrintDoc \'定义一个报表
Dim rt As New prt.RenderTable() \'定义一个表格对象
Dim rx As New prt.RenderText \'定义一个文本对象
Dim tb As Table = Tables("表C")

doc.PageSetting.Landscape = True \'横向打印
doc.PageSetting.PaperKind = 6 \'纸张类型改为A5 Rotated
Doc.PageSetting.TopMargin = 2 \'设置上边距
Doc.PageSetting.BottomMargin = 0 \'设置下边距
Doc.PageSetting.RightMargin = 1 \'设置右边距
Doc.PageSetting.LeftMargin = 5 \'设置左边距

rx = New prt.RenderText
rx.Style.FontSize = 14
rx.Style.FontBold = True
rx.Style.Spacing.Bottom = 5
rx.Text = "产品: " & Tables("表C").Current("产品")
doc.Body.Children.Add(rx)

rt = New prt.RenderTable \'创建表格对象
For c As Integer = 0 To 9
    rx = New prt.RenderText \'创建文本对象
    rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
    rx.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中
    rx.Text =  c \'为文本对象设置内容
    rt.Cells(0, c).RenderObject = rx \'将文本对象放置在单元格中
Next
rt.Rows.Count = 4 \'设置总行数
rt.Cols.Count = 10 \'设置总列数
rt.Style.GridLines.All = New prt.Linedef
rt.Height = 40 \'设置表格的高度为80毫米
rt.Width = 198 \'设置表格的宽度为198
rt.Rows(0).Height = 8 \'设置第1行的高度为6毫米,剩余高度被平均分排到其他行
doc.Body.Children.Add(rt)

rx = New prt.RenderText
rx.Style.FontBold = True
rx.Style.Spacing.Top = 3
rx.Text = "总计: " & Tables("表C").Rows.Count
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right
doc.Body.Children.Add(rx)

Doc.Preview() \'预览报表


图片点击可在新窗口打开查看此主题相关图片如下:图1.png
图片点击可在新窗口打开查看
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目11.zip


--  作者:mamuaiqing
--  发布时间:2013/3/2 17:20:00
--  

表中有 父,子,孙关联表,当中以单号关联,要求以专业报表形式打印出孙表当中跟父表关联的所有明细,明细效果按产品分组,如图所示

 

内容从第二行开始填入,代码中学生只研究到了这里,请教老师后面代码该怎么写?


--  作者:mamuaiqing
--  发布时间:2013/3/2 17:42:00
--  

感谢 muhua老师,关联表和报表无法实现我想要的,原因如下:

 

1.需要打印的内容在孙表中,三表同样关联单号列,父表跟孙表关联的是产品跟单号列

 

2.孙表内容是按表格中从左到右填入,表格中不够填入的时候自动从下一行再进行填入,不是从上向下填入

 

3.一种产品一个表格明细,当纸张不够打印明细时自动换页,这个就有点类似"分组"报表形式

 

还望老师再次进行指导


--  作者:mamuaiqing
--  发布时间:2013/3/2 20:39:00
--  

根据 muhua 老师的指导学习了下"连续打印关联表",写了下面的代码,上传图片先,当中加入了自动生成行号,一直研究不出这样才能让数据横着的顺序排列,达到10列数据后自动从第二行填入数据

 

Dim doc As New Printdoc
Dim rx As prt.RenderText
Dim rt As prt.RenderTable
Dim Rows As List(Of DataRow)
Dim tbl As Table = Tables("表A.表B")

With Tables("表A.表B")
    For i As Integer = 0 To .Rows.Count - 1 \'遍历关联表每一行
        rx = New prt.RenderText
        rx.Style.FontSize = 14
        rx.Style.FontBold = True
        rx.Style.Spacing.Bottom = 5
        rx.Text = "产品: " & Tables("表A.表B").Rows(i)("产品")
        doc.Body.Children.Add(rx)
        rt = New prt.RenderTable
        rt.Cols.Count = 2 \'设置总列数
        rt.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和
       
        rt.Style.TextAlignVert = prt.AlignVertEnum.Center
        rt.Style.Borders.Bottom = New prt.LineDef(0.3,Color.LightGray)
        rt.CellStyle.Spacing.All = 1
        rt.Cols.Count = 2
        rt.Cells(0,1).Text = "重量"
        rt.rows(0).Style.Borders.Top = New prt.LineDef(1,Color.LightGray)
        rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1,Color.LightGray)
       
        Rows = Tables("表A.表B").Rows(i).DataRow.GetChildRows("表C")
        For r As Integer = 0 To Rows.Count - 1
            rt.Cells(r+1,1).Text = rows(r)("明细")
        Next
        rt.Cols.Insert(0) \'在左边插入一列,用于打印行号
        rt.Cols(0).Width = 10 \'设置行号列的宽度
        For i1 As Integer = 1 To rt.Rows.Count - 1
            rt.Cells(i1,0).text = i1 \'逐行写入行号
        Next
        doc.Body.Children.Add(rt)
        rx = New prt.RenderText
        rx.Style.FontBold = True
        rx.Style.Spacing.Top = 3
        rx.Text = "总计: " & Tables("表A.表B").Rows(i)("重量")
        rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right
        doc.Body.Children.Add(rx)
    Next
End With
doc.Preview


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

--  作者:狐狸爸爸
--  发布时间:2013/3/4 8:27:00
--  

Dim doc As New Printdoc
Dim rx As prt.RenderText
Dim rt As prt.RenderTable
Dim Rows As List(Of DataRow)
Dim tbl As Table = Tables("表A.表B")

With Tables("表A.表B")
    For i As Integer = 0 To .Rows.Count - 1 \'遍历关联表每一行
        rx = New prt.RenderText
        rx.Style.FontSize = 14
        rx.Style.FontBold = True
        rx.Style.Spacing.Bottom = 5
        rx.Text = "产品: " & Tables("表A.表B").Rows(i)("产品")
        doc.Body.Children.Add(rx)
        rt = New prt.RenderTable
        rt.Cols.Count = 2 \'设置总列数
       
        rt.Style.TextAlignVert = prt.AlignVertEnum.Center
        rt.Style.Borders.Bottom = New prt.LineDef(0.3,Color.LightGray)
        rt.CellStyle.Spacing.All = 1
        rt.Cols.Count = 2
        rt.Cells(0,1).Text = "重量"
        rt.rows(0).Style.Borders.Top = New prt.LineDef(1,Color.LightGray)
        rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1,Color.LightGray)
        rt.cols.Count = 11
        For r As Integer = 0 To 10
            rt.cols(i).width = 100 / 11
        Next

        Rows = Tables("表A.表B").Rows(i).DataRow.GetChildRows("表C")
        For r As Integer = 0 To Rows.Count - 1
            Dim rw As Integer = i \\ 10
            Dim cl As Integer = r - rw * 10
            rt.Cells(rw + 1,cl + 1).Text = rows(r)("明细")
        Next


        For r As Integer = 1 To rt.Rows.Count - 1
            rt.Cells(r,0).text = r \'逐行写入行号
        Next
       
        doc.Body.Children.Add(rt)
        rx = New prt.RenderText
        rx.Style.FontBold = True
        rx.Style.Spacing.Top = 3
        rx.Text = "总计: " & Tables("表A.表B").Rows(i)("重量")
        rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right
        doc.Body.Children.Add(rx)
    Next
End With
doc.Preview

 


--  作者:mamuaiqing
--  发布时间:2013/3/4 14:53:00
--  

感谢老爹,根据老爹的代码进行了修改,如图中所示,第一行的0-15为行号,数据超过10行的时候没自动从下一行开始排列

Dim doc As New Printdoc
Dim rx As prt.RenderText
Dim rt As prt.RenderTable
Dim Rows As List(Of DataRow)
Dim tbl As Table = Tables("表A.表B")

With Tables("表A.表B")
    For i As Integer = 0 To .Rows.Count - 1 \'遍历关联表每一行
        rx = New prt.RenderText
        rx.Style.FontSize = 14
        rx.Style.FontBold = True
        rx.Style.Spacing.Bottom = 5
        rx.Text = "产品: " & Tables("表A.表B").Rows(i)("产品")
        doc.Body.Children.Add(rx)
        rt = New prt.RenderTable
        rt.Cols.Count = 2 \'设置总列数
       
        rt.Style.TextAlignVert = prt.AlignVertEnum.Center
        rt.Style.Borders.Bottom = New prt.LineDef(0.3,Color.LightGray)
        rt.CellStyle.Spacing.All = 1
        rt.Cols.Count = 2
        rt.Cells(1,0).Text = "重量"
        rt.rows(0).Style.Borders.Top = New prt.LineDef(1,Color.LightGray)
        rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1,Color.LightGray)
        rt.cols.Count = 11
        For r As Integer = 0 To 10
            rt.cols(i).width = 100 / 11
        Next
       
        Rows = Tables("表A.表B").Rows(i).DataRow.GetChildRows("表C")
        For r As Integer = 0 To Rows.Count - 1
            Dim rw As Integer = i \\ 10
            Dim cl As Integer = r - rw * 10
            rt.Cells(rw + 1,cl + 1).Text = rows(r)("明细")
        Next
        For c As Integer = 0 To 15
            rx = New prt.RenderText \'创建文本对象
            rx.Text =  c \'为文本对象设置内容
            rt.Cells(0, c).RenderObject = rx \'将文本对象放置在单元格中
        Next
       
       
        doc.Body.Children.Add(rt)
        rx = New prt.RenderText
        rx.Style.FontBold = True
        rx.Style.Spacing.Top = 3
        rx.Text = "总计: " & Tables("表A.表B").Rows(i)("重量")
        rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right
        doc.Body.Children.Add(rx)
    Next
End With
doc.Preview


--  作者:mamuaiqing
--  发布时间:2013/3/4 14:53:00
--  

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

--  作者:狐狸爸爸
--  发布时间:2013/3/4 15:00:00
--  

Dim doc As New Printdoc
Dim rx As prt.RenderText
Dim rt As prt.RenderTable
Dim Rows As List(Of DataRow)
Dim tbl As Table = Tables("表A.表B")

With Tables("表A.表B")
    For i As Integer = 0 To .Rows.Count - 1 \'遍历关联表每一行
        rx = New prt.RenderText
        rx.Style.FontSize = 14
        rx.Style.FontBold = True
        rx.Style.Spacing.Bottom = 5
        rx.Text = "产品: " & Tables("表A.表B").Rows(i)("产品")
        doc.Body.Children.Add(rx)
        rt = New prt.RenderTable
        rt.Cols.Count = 2 \'设置总列数
       
        rt.Style.TextAlignVert = prt.AlignVertEnum.Center
        rt.Style.Borders.Bottom = New prt.LineDef(0.3,Color.LightGray)
        rt.CellStyle.Spacing.All = 1
        rt.Cols.Count = 2
        rt.Cells(0,1).Text = "重量"
        rt.rows(0).Style.Borders.Top = New prt.LineDef(1,Color.LightGray)
        rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1,Color.LightGray)
        rt.cols.Count = 11
        For r As Integer = 0 To 10
            rt.cols(i).width = 100 / 11
        Next
       
        Rows = Tables("表A.表B").Rows(i).DataRow.GetChildRows("表C")
        For r As Integer = 0 To Rows.Count - 1
            Dim rw As Integer = r \\ 10
            Dim cl As Integer = r - rw * 10
            rt.Cells(rw + 1,cl + 1).Text = rows(r)("明细")
        Next
       
       
        For r As Integer = 1 To rt.Rows.Count - 1
            rt.Cells(r,0).text = r \'逐行写入行号
        Next
       
        doc.Body.Children.Add(rt)
        rx = New prt.RenderText
        rx.Style.FontBold = True
        rx.Style.Spacing.Top = 3
        rx.Text = "总计: " & Tables("表A.表B").Rows(i)("重量")
        rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right
        doc.Body.Children.Add(rx)
    Next
End With
doc.Preview


 


--  作者:mamuaiqing
--  发布时间:2013/3/4 15:18:00
--  
图片点击可在新窗口打开查看解决问题了 ,感谢老爹