Dim dtb As New DataTableBuilder("齐套异常") '生成临时表
dtb.AddDef("工单号", Gettype(String), 32)
dtb.AddDef("产品品名", Gettype(String), 100)
dtb.AddDef("预计齐套日期", Gettype(Date))
dtb.AddDef("备料料号", Gettype(String), 32)
dtb.AddDef("料件品名", Gettype(String), 100)
dtb.AddDef("异常_描述", Gettype(String), 225)
dtb.AddDef("异常_采购部回复", Gettype(String), 225)
dtb.AddDef("备注", Gettype(String), 225)
dtb.Build()
Dim Cols1() As String = {"工单号","产品品名","预计齐套日期","备料料号","料件品名","异常_描述","异常_采购部回复"}
Dim Cols2() As String = {"工单号","产品品名","预计齐套日期","备料料号","料件品名","异常_描述","异常_采购部回复"}
For Each dr1 As DataRow In DataTables("齐套信息").Select("[异常_处理结果] = 1 ") '生成临时表
Dim dr2 As DataRow = DataTables("齐套异常").AddNew()
For i As Integer = 0 To Cols1.Length -1
dr2(Cols2(i)) = dr1(Cols1(i))
Next
Next
Dim dt As Table = Tables("齐套异常")
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim Style As Xls.Style = Book.NewStyle '新建一个样式
Style.BackColor = Color.Red '样式的背景颜色设为红色
For c As Integer = 0 To dt.Cols.Count -1
Sheet(0, c).Value = dt.Cols(c).Name '总表添加列标题
Next
For r As Integer = 0 To dt.Rows.Count - 1
CurrentTable.Position = r '循环当前行
book.Sheets.Add(dt.rows(r)(0))
Dim Sheet1 As XLS.Sheet = Book.Sheets(r+1) '循环引用工作簿的工作表
For c As Integer = 0 To dt.Cols.Count -1
Sheet(r +1, c).Value = dt.rows(r)(c) '总表填入数据
Next
Next
Dim App As New MSExcel.Application '打开工作簿
Book.Save("c:\reports\齐套异常.xls") '保存
Dim Proc As New Process '打开excel
Proc.File = "c:\reports\齐套异常.xls" '打开excel
Proc.Start() '打开excel
App.Visible = True '显示excel