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