找回密码
 立即注册

QQ登录

只需一步,快速开始

zhuyifirst

注册会员

2

主题

5

帖子

70

积分

注册会员

积分
70
最新发帖
zhuyifirst
注册会员   /  发表于:2018-12-2 16:11  /   查看:3001  /  回复:3
一次读入多张单据(不确定单据的数量),连续打印,每张据页头位置的数据不一样,比如单据编号等。使用StartDoc和EndDoc的方法,第一页总加不上页头的内容,之后页的页头内容也会移位。

  以下是代码的小样:
        Dim r As Int32, c As Int32 ,i As Int32

        nDoc.Clear()

        nDoc.AllowNonReflowableDocs = True

        nDoc.PageLayout.PageSettings.PaperKind = PaperKind.Custom
        nDoc.PageLayout.PageSettings.Height = "148mm"
        nDoc.PageLayout.PageSettings.Width = "210mm"

        nDoc.PageLayout.PageSettings.Landscape = False

        nDoc.StartDoc()

        For i = 0 To UBound(nGroup_id)'nGroup_id 是字符型数组,保存每张单子的单据编号

            Dim Rt(UBound(nGroup_id)) As RenderTable

            Rt(i) = New RenderTable
            Rt(i).Cols.Count = 5
            For c = 1 To 5
                Rt(i).Cols(c - 1).Width = 100
            Next

            Rt(i).Cells(0, 0).Text = "费用报销单"
            Rt(i).Cells(0, 0).SpanRows = 1
            Rt(i).Cells(0, 0).SpanCols = 5
            Rt(i).Cells(0, 0).Style.TextAlignHorz = AlignHorzEnum.Center
            Rt(i).Cells(0, 0).Style.TextAlignVert = AlignVertEnum.Center
            Rt(i).Cells(0, 0).Style.Font = New Font("宋体", 26, FontStyle.Bold)
            Rt(i).Rows(0).Height = 0.5

            Rt(i).Cells(1, 0).Text = "编号:" & nGroup_id(i)
            Rt(i).Cells(1, 0).SpanRows = 1
            Rt(i).Cells(1, 0).SpanCols = 3

            Rt(i).Cells(1, 3).Text = "日期:" & nFg.GetData(1, 0).ToString.Trim
            Rt(i).Cells(1, 3).SpanRows = 1
            Rt(i).Cells(1, 3).SpanCols = 2
            Rt(i).Rows(1).Height = 0.3

            Rt(i).Cells(2, 0).Text = "部门:" & nFg.GetData(1, 2).ToString.Trim
            Rt(i).Cells(2, 0).SpanRows = 1
            Rt(i).Cells(2, 0).SpanCols = 3

            Rt(i).Cells(2, 3).Text = "项目名称:" & nFg.GetData(1, 3).ToString.Trim
            Rt(i).Cells(2, 3).SpanRows = 1
            Rt(i).Cells(2, 3).SpanCols = 2
            Rt(i).Rows(2).Height = 0.3

            Rt(i).Cells(3, 0).Text = "摘要"
            Rt(i).Cells(3, 0).SpanRows = 1
            Rt(i).Cells(3, 0).SpanCols = 3

            Rt(i).Cells(3, 3).Text = "金额"
            Rt(i).Cells(3, 4).Text = "科目"
            Rt(i).Rows(3).Height = 0.3

            nDoc.PageLayout.PageHeader = Rt(i)

            '==============设置页脚============================================
            Dim RtB(UBound(nGroup_id)) As RenderTable

            RtB(i) = New RenderTable
            With RtB(i)
                For c = 1 To 5
                    .Cols(c - 1).Width = lsColsWidth
                Next

                .Cells(0, 0).Text = "报销人"
                .Cells(0, 1).Text = "部门经理"
                .Cells(0, 2).Text = "财务审核"
                .Cells(0, 3).Text = "副总"
                .Cells(0, 4).Text = "总经理"
            End With

            nDoc.PageLayout.PageFooter = RtB(i) 'New RenderText("Page [PageNo] of [PageCount]")

            '=====================================================================


            Dim RtA(UBound(nGroup_id)) As RenderTable

            RtA(i) = New RenderTable
            With RtA(i)

                For c = 1 To 5
                    .Cols(c - 1).Width = 100
                Next

                For r = 1 To nFg.Rows.Count - 1

                    For c = 0 To 4
                        '摘要
                        .Cells(r, 0).Text = nFg.GetData(r, 4).ToString.Trim
                        .Cells(r, 0).SpanRows = 1
                        .Cells(r, 0).SpanCols = 3

                        '金额
                        .Cells(r, 3).Text = nFg.GetData(r, 5).ToString.Trim

                        '科目
                        .Cells(r, 4).Text = nFg.GetData(r, 6).ToString.Trim
                    Next 'c

                    .Rows(r).Height = 0.3

                Next 'r


                ' nDoc.Body.Children.Add(RtA)

                .Style.GridLines.All = New LineDef("1pt", Color.Black)
                .Style.GridLines.Horz = New LineDef("1pt", Color.Gray)
                .Style.GridLines.Vert = New LineDef("1pt", Color.Gray)
            End With

            nDoc.RenderBlock(RtA(i))

            If i < UBound(nGroup_id) Then nDoc.NewPage()

        Next 'i

        nDoc.EndDoc()
        CPP.Document = nDoc

3 个回复

倒序浏览
JeffryLI
葡萄城公司职员   /  发表于:2018-12-3 13:50:48
沙发
您好,您用的是是哪个版本,操作系统是哪个版本,可以给实际场景下的demo吗?最好是能直接运行起来的demo。
请点击评分,对我5分评价,谢谢!

葡萄城控件服务团队
官方网站: https://www.grapecity.com.cn/developer
回复 使用道具 举报
zhuyifirst
注册会员   /  发表于:2018-12-3 14:45:08
板凳
控件版本号是2.0.20152.67,win7操作系统
问题解决了,我发现页头和页脚只是最后一次设定的值有效,所以就设的rendertable 手动写的页头和页脚,计算每页能打印多少行,能打印多页,然后手动分的页
回复 使用道具 举报
JeffryLI
葡萄城公司职员   /  发表于:2018-12-3 14:56:03
地板
好的,发现很多用户对C1PrintDocumnet 用的很多,可否提供一个你们现在正在使用的案例给我们。我们有金币奖励。
请点击评分,对我5分评价,谢谢!

葡萄城控件服务团队
官方网站: https://www.grapecity.com.cn/developer
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部