Dim doc As New PrintDoc '定义一个报表专业打印窗口_Table1"员工.员工需求
Dim Rows As List(Of DataRow)
Dim tbl As Table = Tables("员工")
Dim tb As Table = Tables("员工需求")'
'Dim tb As Table = Tables("员工.员工需求")'
'主表 - 选定区 - 打印
With Tables("员工")
If .TopPosition > -1 Then '如果选定区域包括数据行
For i2 As Integer = .TopPosition To .BottomPosition
Dim pr As Row = .rows(i2)
'员工-主表
For i As Integer = tbl.TopRow To tbl.BottomRow
Dim rw As Row = tbl.Rows(i)
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim rt2 As New prt.RenderTable() '定义一个表格对象
Dim rx As New prt.RenderText '定义一个文本对象
Dim ra As New prt.RenderArea '定义一个容器
ra.SplitVertBehavior = prt.SplitBehaviorEnum.Never '禁止容器因为分页而被垂直分割
Dim prs As Integer = 10'
Dim cols() As String = { "员工编号", "类别名称", "说明", "图片"}
' Rows = tb.DataTable.select("员工编号='" & rw("员工编号") & "'")
Rows = tb.DataTable.select("员工编号='" & pr("员工编号") & "'")
rx.text = "员工资料卡"
rx.Style.FontBold = True '字体加粗
rx.Style.FontSize = 16 '大体大小为16磅
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中排列
rx.Style.Spacing.Bottom = 3 '和下面的对象(表格)距离3毫米
ra.Children.Add(rx) '加入到容器中
rt.Rows.Count = 7 '设置总行数
rt.Cols.Count = 5 '设置总列数
rt.Height = 75 '设置表格的高度
rt.Rows(6).Height = 30 '设置第7行(显示备注的行)的高度,剩余高度被平均分排到其他行
rt.Cols(0).Width = 26 '设置前四列的宽度,剩余的宽度被分配给5列(显示图片的那列)
rt.Cols(1).Width = 35
rt.Cols(2).Width = 26
rt.Cols(3).Width = 40
rt.Cells(0, 4).SpanRows = 6 '第1行第5个单元格向下合并6行(用于显示照片)
rt.Cells(4, 1).SpanCols = 3 '第5行第2个单元格向右合并3列(用于显示地址)
rt.Cells(6, 0).SpanCols = 5 '第7行第1个单元格向右合并5列(用于显示备注)
rt.CellStyle.Spacing.All = 1 '单元格内容缩进1毫米
rt.Style.Spacing.Bottom = 5 '和下一个资料卡的距离是5毫米
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.Rows(6).Style.TextAlignVert = prt.AlignVertEnum.Top '唯独第7行是备注,内容靠上对齐
rt.Cells(0, 0).Text = "姓名"
rt.Cells(0, 1).Text = rw("姓名")
rt.Cells(0, 2).Text = "出生日期"
rt.Cells(0, 3).Text = rw("出生日期")
rt.Cells(1, 0).Text = "部门"
rt.Cells(1, 1).Text = rw("部门")
rt.Cells(1, 2).Text = "雇佣日期"
rt.Cells(1, 3).Text = rw("雇佣日期")
rt.Cells(2, 0).Text = "性别"
rt.Cells(2, 1).Text = rw("性别")
rt.Cells(2, 2).Text = "职务"
rt.Cells(2, 3).Text = rw("职务")
rt.Cells(3, 0).Text = "城市"
rt.Cells(3, 1).Text = rw("城市")
rt.Cells(3, 2).Text = "邮政编码"
rt.Cells(3, 3).Text = rw("邮政编码")
rt.Cells(4, 0).Text = "地址"
rt.Cells(4, 1).Text = rw("地址")
rt.Cells(5, 0).Text = "家庭电话"
rt.Cells(5, 1).Text = rw("家庭电话")
rt.Cells(5, 2).Text = "办公电话"
rt.Cells(5, 3).Text = rw("办公电话")
rt.Cells(6, 0).Text = rw("备注")
rt.Cells(0, 4).Image = GetImage(rw("照片"))
ra.Children.Add(rt) '加入到容器中
Doc.Body.ChildRen.Add(ra) '将容器加入到报表中
rt2 = New prt.RenderTable
rt2.Style.GridLines.All = New Prt.LineDef(0.5, Color.Black)
'rt.Style.GridLines.Horz = New Prt.LineDef(Color.Red)
rt2.Style.GridLines.Horz = New Prt.LineDef(Color.Black)
rt2.Style.GridLines.Vert = New Prt.LineDef(Color.Green)
rt2.Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt2.Style.TextAlignVert = prt.AlignVertEnum.Center
rt2.Style.Borders.Bottom = New prt.LineDef(0.3, Color.LightGray)
rt2.CellStyle.Spacing.All = 1
rt2.Cols.Count = 4'设
For j As Integer = 0 To cols.Length - 1 '打印标题
rt2.Cells(0, j).Text = cols(j)
Next
rt2.Cols(0).Width = 50 '
rt2.Cols(1).Width = 80 '
rt2.Cols(2).Width = 90 '
rt2.Cols(3).Width = 26 '
rt2.Cols(4).Width = 50 '
[此贴子已经被作者于2024/6/21 16:41:29编辑过]
For r As Integer = 0 To Rows.Count - 1
rt2.Cells(r + 1, 0).Text = rows(r)("员工编号")
rt2.Cells(r + 1, 1).Text = rows(r)("类别名称")
rt2.Cells(r + 1, 2).Text = rows(r)("说明")
rt2.Cells(r + 1, 3).Text = rows(r)("图片")
Next
Next
End If
Next
Next
Next
Next
End If
End With
Doc.Preview() '预览报表
代码是3楼+4楼,由代码量太大,分2楼发
上面执行,没报错,但明细数据还是无法打印,请老师帮看,哪里错,如何改?
[此贴子已经被作者于2024/6/21 18:01:44编辑过]
rt.Cells(8, 0).Text = "照片"
rt.Cells(8, 0).Image = GetImage(rw("照片"))
Dim CurRow As Row = Tables("员工").Current
Dim fls As List(Of String)
' For Each f As String In lfls
For i3 As Integer = 0 To fls.Count - 1
rt.Style.ImageAlign.StretchHorz = False '禁止
rt.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center ''
fls = CurRow.DataRow.Lines("照片")
rt.Cells(8, 0).Image = GetImage(fls(0))
rt.Cells(8, 2).Image = GetImage(fls(1))
Next
红代码,报错找不到对象,如何解决?
[此贴子已经被作者于2024/6/22 1:09:38编辑过]