如题..打印代码如下:
Dim rt As Prt.RenderTable
Dim tbl As Table = Tables("领药单")
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetUniqueValues("","住院ID")
doc.Pagesetting.LandScape = false
For Each Region As String In Regions
Dim rs As New prt.RenderText
Dim dr As DataRow = datatables("住院信息").find("[住院ID] = '" & region & "'")
rs.Text = "床位: " & dr("床位") & " 姓名: " & dr("姓名")
rs.Style.FontSize = 10
rs.Style.FontBold = True
doc.Body.Children.Add(rs)
rt = New prt.RenderTable
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Style.GridLines.Top = New prt.LineDef(0.4,Color.Black)
rt.Style.Spacing.Bottom = 5
rt.CellStyle.Spacing.All = 1
rt.Style.Font = tbl.Font
rt.Cols(1).Width = 40
rt.Cols(2).Width = 30
Rows = tbl.Datatable.Select("[住院ID] = '" & Region & "'")
Dim cc as integer = tbl.Cols.Count
rt.Cells(0,cc).Text = "金额"
For c As integer = 0 To tbl.Cols.Count - 1
rt.Cells(0,c).Text = tbl.Cols(c).Name
For r As integer = 0 To Rows.Count -1
rt.Cells(r + 1, cc).Text = tbl(r,5)*tbl(r,6)
rt.Cells(r + 1, c).Text = rows(r)(tbl.Cols(c).Name)
Next
Next
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All
rt.Style.Gridlines.Horz = New prt.Linedef(0.3,Color.LightGray)
doc.Body.Children.Add(rt)
Next
原表有一列隐藏列......执行上述代码时,隐藏列也给我打出来了....记得以前是不会的..
此主题相关图片如下:001.jpg
[此贴子已经被作者于2009-2-20 21:21:59编辑过]
下面是排除隐藏列的通用代码,请参考:
Dim tb as Table = Tables("订单")
Dim ColNames As New List(Of String)
For Each cl As Col In tb.Cols '排除隐藏列
If cl.Visible Then
ColNames.Add(cl.Name)
End If
Next
rt.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
rt.CanSplitHorz = True '表格宽度超出页宽时,可以水平换页
rt.Style.Font = tb.Font
For c As Integer = 0 To ColNames.Count - 1 '逐列设置和填入内容
rt.Cells(0,c).Text = ColNames(c) '列名作为标题
rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth '列宽等于实际列宽
If tb.Cols(ColNames(c)).IsNumeric Orelse tb.Cols(ColNames(c)).IsDate Then '如果是数值或日期列
rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right '数据水平靠右
End If
For r As integer = 0 To tb.Rows.Count -1 '开始填入该列内容
rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
Next
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt.CellStyle.Spacing.All = 0.5 '单元格内距设为0.5毫米
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '利用行组,将第一行设为表头.
doc.Body.Children.Add(rt) '将表格加入到报表
doc.Preview()
同样的代码以前是不用的呀....不过还是谢谢了..
测试过好像不行..
[此贴子已经被作者于2009-2-20 22:04:41编辑过]
呵呵,应该是你记错了的,这一部分我从来没有动过的。
老爹,你猜我用什么方法解决?只要一行代码就OK.....
就是把要隐藏的列设为0
rt.Cols(0).Width = 0
[此贴子已经被作者于2009-2-20 22:14:53编辑过]