Dim doc As New PrintDoc
Dim rt As New prt.RenderTable '定义一个新表格
Dim tb As Table = Tables( "出库.出库明细" )
Dim ColNames As New List(Of String)
Dim rs As New prt.RenderText()
rt.Width = "Parent.Width"
rt.Style.Spacing.Top = 21 '表格和前面对象的垂直间隔为4毫米
rs.Text = "xxxxxxxxxx公司出库单"
rs.Style.Font = New Font("微软雅黑",15)
rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本内容水平居中
doc.Body.Children.Add(rs)
rs= New prt.RenderText()
rt.Width = "Parent.Width"
rt.Style.Spacing.Top = 6 '表格和前面对象的垂直间隔为4毫米
rs.Text = "xxxxxxxxxxxx"
rs.Style.Font = New Font("微软雅黑",10)
rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本内容水平居中
doc.Body.Children.Add(rs) '将文本对象加入到表格中
For Each cl As Col In tb.Cols '排除隐藏列
Select Case cl.Name
Case "商品代码","商品名称","商品类别","出库用途","规格","数量","单价","单位","金额","备注"
' If cl.Visible Then
ColNames.Add(cl.Name)
'End If
End Select
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
rt.Cols(c).Style.TextAlignHorz =prt.AlignHorzEnum.Center
rt.Cols(c).Style.TextAlignVert =prt.AlignVertEnum.Center
For r As Integer = 0 To tb.Rows.Count -1
rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
Next
Next
rt.Rows.Count = rt.Rows.Count + 1
Dim cnt As Integer = rt.Rows.Count - 1
rt.Cells(cnt,0).Text = "总计"
For c As Integer = 0 To ColNames.Count - 1
If tb.Cols(ColNames(c)).IsNumeric Then
rt.Cells(cnt,c).Text = tb.Compute("Sum(" & ColNames(c) & ")")
End If
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.LightGray) ' 网格线
doc.Body.Children.Add(rt)doc.PageSetting.Landscape = True '打印方向
Doc.PageSetting.LeftMargin = 10 '设置左边距
Doc.PageSetting.RightMargin = 10 '设置右边距
Doc.PageSetting.TopMargin = 10 '设置上边距
Doc.PageSetting.BottomMargin = 10 '设置下边距
doc.PageSetting.Width = 270
doc.PageSetting.Height = 120 这边的纸张大小等于 打印区域的大小 帮我写下代码
doc.Preview()
老大,红字部分帮帮忙 纠结了很多天了.
[此贴子已经被作者于2013-4-22 22:31:33编辑过]