Foxtable(狐表)用户栏目专家坐堂 → 专业报表的多页打印问题


  共有7548人关注过本帖树形打印复制链接

主题:专业报表的多页打印问题

帅哥哟,离线,有人找我吗?
huashan_1
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:74 积分:682 威望:0 精华:0 注册:2011/8/27 9:12:00
专业报表的多页打印问题  发帖心情 Post By:2012/6/21 8:18:00 [只看该作者]

我是想设置每页打印六行,剩下的下页打印,我设置好之后多了一页空白页,请各位高手帮我瞧瞧

代码如下:

Dim doc As New PrintDoc '定义一个新报表

doc.AutoRotate = False '禁止自动旋转打印内容
doc.PageSetting.Width = 210 '纸张宽度
doc.PageSetting.Height =297 '纸张高度
Doc.PageSetting.LeftMargin = 5 '设置左边距
Doc.PageSetting.RightMargin = 5 '设置右边距
Doc.PageSetting.TopMargin = 3 '设置上边距
Doc.PageSetting.BottomMargin = 1 '设置下边距

''''++++++++++++++++++''''定义表头及表尾文字
Dim dr As Row = Args(2)
Dim tb As Table = Args(3)

If Args(1) <> "重打" Then
    Dim cmd As new SQLCommand
    cmd.C
    cmd.CommandText = "update sc_ddzb set dy = 1 where scph = '" & Trim(dr("订单编号")) & "'"
    cmd.ExecuteScalar()
End If

Dim ir As Integer
If tb.Rows.Count Mod 6 = 0 Then
    ir = tb.Rows.Count / 6
Else
    ir = tb.Rows.Count / 6 + 1
End If

For i As Integer = 0 To ir - 1
    'MessageBox.Show(1 + i)
    Dim ra As New prt.RenderArea '定义一个容器
    'ra.Height = 250
    ra.SplitVertBehavior = prt.SplitBehaviorEnum.Never  '禁止容器因为分页而被垂直分割
    Dim rt1,rt2,rt3,rt4,rt5,rt6,rt7,rt8 As New prt.RenderText '定义文本对象
    'For i As Integer = tb.TopRow To tb.BottomRow
    rt1.Text = "高宏饰品生产总单"
    rt1.Style.Font =  New Font("华文细黑", 24 )
    rt1.Style.TextAlignHorz = prt.AlignHorzEnum.Center '居中
    rt1.Style.FontBold = True '加粗
    rt1.y = 14  '指定垂直位置
    ra.Children.Add(rt1)
    'doc.Body.Children.Add(rt1)
   
    rt2.Text = "客户名称:" & dr("客户名称")
    rt2.Style.Font =  New Font("宋体", 12 ) ',
    rt2.x = 6 '指定水位位置
    rt2.y = 27 '指定垂直位置
    'doc.Body.Children.Add(rt2)
    ra.Children.Add(rt2)
    '''''
    rt3.Text = "接单日期:" & dr("接单日期") & "            " & "下单日期:" & Format(dr("下单日期"),"yyyy-MM-dd")
    rt3.Style.Font =  New Font("宋体", 12 ) ',
    rt3.X = 72 '指定水平位置
    rt3.y = 27 '指定垂直位置
    'doc.Body.Children.Add(rt3)
    ra.Children.Add(rt3)
    '''''
    rt4.Text = "订单编号:" & dr("订单编号")
    rt4.Style.Font =  New Font("宋体", 12 ) ',
    rt4.x = 6
    rt4.y = 33 '指定垂直位置
    'doc.Body.Children.Add(rt4)
    ra.Children.Add(rt4)
   
    rt5.Text = "交货日期:" & dr("交货日期") & "            " & "操 作 人:" & dr("操作员")
    rt5.Style.Font =  New Font("宋体", 12) ',
    rt5.X = 72 '指定水平位置
    rt5.y = 33 '指定垂直位置
    'doc.Body.Children.Add(rt5)
    ra.Children.Add(rt5)
   
    rt6.Text = "总共" & ir & "页 第" & i +1 & "页"
    rt6.Style.Font =  New Font("宋体", 10) ',
    rt6.X = 174 '指定水平位置
    rt6.y = 38 '指定垂直位置
    'doc.Body.Children.Add(rt5)
    ra.Children.Add(rt6)
   
    '''''
    Dim rt As New prt.RenderTable '定义一个新表格
    rt.X = 4 '指定水平位置
    rt.y = 42 '指定垂直位
   
    Dim ColNames As String() = New String(){"产品编号", "产品名称", "图片","工艺","效果要求","包装要求","数量"}
    ''''''''''''''''''设置列宽
    rt.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
    rt.Cols(0).Width = 18  '产品编号
    rt.Cols(1).Width = 18  '产品名称
    rt.Cols(2).Width = 40  '图片
    rt.Cols(3).Width = 24  '工艺
    rt.Cols(4).Width = 50   '效果要求
    rt.Cols(5).Width = 24   '包装要求
    rt.Cols(6).Width = 15  '数量
   
    '''''''''''''''填入内容
    Dim cmd As new SQLCommand
    cmd.C
    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 tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(c)).IsDate Then '如果是数值或日期列
            rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
        Else
            rt.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '生产批号居中
            rt.Cols(4).Style.TextAlignHorz = prt.AlignHorzEnum.left '计价居中
            rt.Cols(5).Style.TextAlignHorz = prt.AlignHorzEnum.Center '单位居中
            'rt.Cols(6).Style.TextAlignHorz = prt.AlignHorzEnum.left '单位居中
        End If
        For r As Integer = 0 To tb.Rows.Count -1 '开始填入该列内容
            rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
           
            cmd.CommandText = "select tp from yp_cptp where cpbh = '" & tb.Rows(r)(ColNames(0)) & "'"
            If cmd.ExecuteScalar() IsNot Nothing Then
                Dim imageByte() As Byte = cmd.ExecuteScalar()    '查询数据,并存入字节数组
                Dim ms As New IO.MemoryStream(imageByte)         '将字节数组转换为二进制流
                Dim image As Image = Image.FromStream(ms)        '将二进制流转换为图片
                Dim rm As New prt.RenderImage() '定义一个图片对象
                rm.Image = image '请改为实际的图标名称和路径
                rm.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center '图片水平居中
                rm.Style.ImageAlign.AlignVert = prt.ImageAlignVertEnum.Center '图片垂直居中
                rm.Style.ImageAlign.KeepAspectRatio = True
                rm.Height = 45
                rm.Width = 45
                rt.Cells(r + 1, 2).RenderObject = rm
            Else
                rt.Cells(r + 1, 2).RenderObject = Nothing
            End If
        Next
    Next
   
    ''''''''''''以下代码确保数据行数为7行
    For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
        For r1 As Integer = tb.Rows.Count + 2 To 6 '开始填入该列内容
            rt.Cells(r1, c).Text = ""
        Next
    Next
    For r2 As Integer = 0 To rt.Rows.Count -1
        rt.Rows(r2).Height = 32.5 '行高
        rt.Rows(r2).Style.TextAlignVert = prt.AlignVertEnum.Center '文字垂直居中
        rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
    Next
    '''''''''''
    rt.Rows(0).Height = 10  '设置表头行高
    rt.Rows(7).Height = 13  '设置表头行高
    rt.Cells(7,0).SpanCols = 7 '第7行第1个单元格向右合并5列
    rt.Cells(7,0).text = "  生产经理:                                                                                                                          " & _
    "下单员:" & Vars("UserName")
    rt.Rows(7).Style.TextAlignVert = prt.AlignVertEnum.Center '文字垂直居中
    rt.Rows(7).Style.TextAlignHorz = prt.AlignHorzEnum.Center
    rt.Cells(7,0).Style.TextAlignHorz = prt.AlignHorzEnum.left
   
    rt.Style.GridLines.All = New Prt.LineDef(0.2, Color.Black) '所有边框
    rt.Style.GridLines.Bottom = New Prt.LineDef(0.5, Color.Black) '下边框
    rt.Style.GridLines.Left = New Prt.LineDef(0.5, Color.Black) '左边框
    rt.Style.GridLines.Right = New Prt.LineDef(0.5, Color.Black) '右边框
    rt.Style.GridLines.Top = New Prt.LineDef(0.5, Color.Black) '上边框
   
    'rt.BreakAfter = prt.BreakEnum.page   '打印之后另起一栏
    ra.Children.Add(rt)
    'ra.BreakAfter = prt.BreakEnum.page
    doc.Body.Children.Add(ra) '将文本对象加入到报表
Next

doc.Preview()
'doc.Print()


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2012/6/21 9:02:00 [只看该作者]

应该做个简单的,能直接运行的例子。

 回到顶部