Dim doc As New PrintDoc Dim rt As New prt.RenderTable Dim cmd As New SQLCommand '定义一个SQL命令 Dim dt As DataTable '定义一个数据表变量 Dim Count As Integer = 0 cmd.CommandText = "Select * From {订单} Where Year(日期) = 2009 And Month(日期) = 6" dt = cmd.ExecuteReader() '生成一个临时表 For Each Col As DataCol In Dt.DataCols rt.Cells(0,Count).Text = Col.Name For r As Integer = 0 To dt.DataRows.Count - 1 If dt.DataRows(i).IsNull(Col.Name) Then rt.Cells(r +1,Count).Text = "" Else rt.Cells(r +1,Count).Text = dt.DataRows(r)(Col.Name) End If Next Count = Count + 1 Next rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线 rt.CellStyle.Spacing.All = 1 '内容距离网格线1毫米 rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中 doc.Body.Children.Add(rt) doc.Preview()
|