Dim dt As Table = Tables("南京徳亨文生物科技有限公司设备一览表")
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
sheet.name = "abc"
Dim Style As Xls.Style
style = Book.NewStyle '新建一个样式
Style.ForeColor = Color.Red
style.FontBold = True '样式的背景颜色设为红色
Dim Style1 As Xls.Style
style1 = Book.NewStyle '新建一个样式
Style1.BackColor = Color.yellow
style1.BorderBottom = XLS.LineStyleEnum.Thin
style1.Bordertop = XLS.LineStyleEnum.Thin
style1.Borderleft = XLS.LineStyleEnum.Thin
style1.Borderright = XLS.LineStyleEnum.Thin
style1.FontBold = True '样式的背景颜色设为红色
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 '填入数据
For c As Integer = 0 To dt.Cols.Count -1
Sheet(r +1, c).Value = dt.rows(r)(c)
Next
If dt.Rows(r)("中心") = "公共设施" OrElse dt.Rows(r)("中心") = "离职" Then
For c As Integer = 0 To dt.Cols.Count -1
Sheet(r +1, c).style = style1
Next
End If
If dt.rows(r)("内存") = "2G" Then '如果折扣大于等于0.15
Sheet(r + 1,dt.Cols("内存").Index).Style = Style '设置折扣单元格的样式
End If
If dt.Rows(r)("生产日期").year = 2008 OrElse dt.Rows(r)("生产日期").year = 2008 OrElse dt.Rows(r)("生产日期").year = 2008 Then
Sheet(r + 1,dt.Cols("生产日期").Index).Style = Style '设置折扣单元格的样式
End If
If dt.Rows(r)("使用年限") / 365 >= 5 Then
Sheet(r + 1,dt.Cols("使用年限").Index).Style = Style '设置折扣单元格的样式
End If
Dim d As Double = dt.Rows(r)("使用年限")
Sheet(r + 1,dt.Cols("使用年限").Index).value = d \ 365 & "年" & (d Mod 365) \ 30 & "月"
Next
book.Save("d:\test.xls")
Dim proc As new Process
proc.File = "d:\test.xls"
proc.Start