最简单的统计报表

统计订单表中不同产品的销售额,用Excel形式输出:

Dim dt As DataTable = DataTables("订单")
Dim
Book As New XLS.Book '定义一个Excel工作簿
Dim
Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim
Names As List(Of String) = dt.GetValues("产品")
Sheet
(0,1).Value = "产品销售统计"
For
i As Integer = 0 to Names.Count - 1
   
Sheet(i + 1, 0).Value = Names(i)
   
Sheet(i + 1, 1).Value = dt.Compute("Sum(数量)","[产品] = '" & Names(i) & "'")
Next

'下面的代码用于将首行字体加粗

Dim
Style As XLS.Style = Book.NewStyle
Style
.FontBold = True
Sheet
(0,1).Style = Style
'打开工作簿

Book.Save(
"c:\reports\test.xls")
Dim
Proc As New Process
Proc.File =
"c:\reports\test.xls"

Proc.Start()

直接在命令窗口执行上面的代码,可得到:


本页地址:http://www.foxtable.com/webhelp/topics/1147.htm