一次读入多张单据(不确定单据的数量),连续打印,每张据页头位置的数据不一样,比如单据编号等。使用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
|
|