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 产品,Count(日期) As 订单数,Sum(数量) As 数量,Sum(金额) As 金额 From {订单} Group By 产品" 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 rt.Cells(r +1,Count).Text = dt.DataRows(r)(Col.Name) 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()