Dim de As Table = Tables("临时箱单")
Dim Book As New XLS.Book
Dim Sheet As XLS.Sheet = Book.Sheets(0)
With Sheet.PrintSetting
.AutoScale = True '自动缩放
.FitPagesAcross = 1 '垂直方向缩为1页
End With
Dim Style As XLS.Style = Book.NewStyle() '定义新样式
Dim styel1 As XLS.Style = Book.NewStyle() '定义新样式
styel1.font = New Font("微软雅黑", 16)
Dim styel2 As XLS.Style = Book.NewStyle() '定义新样式
styel2.font = New Font("微软雅黑", 12)
Style.BorderTop = XLS.LineStyleEnum.Thin
Style.BorderBottom = XLS.LineStyleEnum.Thin
Style.BorderLeft = XLS.LineStyleEnum.Thin
Style.BorderRight = XLS.LineStyleEnum.Thin
styel1.BorderTop = XLS.LineStyleEnum.Thin
styel1.BorderBottom = XLS.LineStyleEnum.Thin
styel1.BorderLeft = XLS.LineStyleEnum.Thin
styel1.BorderRight = XLS.LineStyleEnum.Thin
styel2.BorderTop = XLS.LineStyleEnum.Thin
styel2.BorderBottom = XLS.LineStyleEnum.Thin
styel2.BorderLeft = XLS.LineStyleEnum.Thin
styel2.BorderRight = XLS.LineStyleEnum.Thin
Style.BorderColorTop = Color.Black
Style.BorderColorBottom = Color.Black
Style.BorderColorLeft = Color.Black
Style.BorderColorRight = Color.Black
styel1.BorderColorTop = Color.Black
styel1.BorderColorBottom = Color.Black
styel1.BorderColorLeft = Color.Black
styel1.BorderColorRight = Color.Black
styel2.BorderColorTop = Color.Black
styel2.BorderColorBottom = Color.Black
styel2.BorderColorLeft = Color.Black
styel2.BorderColorRight = Color.Black
Sheet.Rows(0).Height = 70 '设置第1行的行高
styel1.WordWrap = True
styel2.AlignHorz = XLS.AlignHorzEnum.Center
styel2.AlignVert = XLS.AlignVertEnum.Center
styel1.AlignHorz = XLS.AlignHorzEnum.Center
styel1.AlignVert = XLS.AlignVertEnum.Center
Style.AlignHorz = XLS.AlignHorzEnum.Center
Style.AlignVert = XLS.AlignVertEnum.Center
de.CreateSheetHeader(Sheet,1,0,True)'生成表头
Sheet(0,0).Value = "产品销售统计" & vbcrlf & "箱单"
For r As Integer = 0 To de.Rows.Count - 1 '填入数据
For c As Integer = 0 To de.Cols.Count -1
Sheet.Cols(0).Width = 120
Sheet.Cols(1).Width = 120
Sheet.Cols(2).Width = 70
Sheet.Cols(3).Width = 120
For a As Integer = 4 To de.Cols.Count -3
Sheet.Cols(a).Width = 30 '设置第1列的宽度
Next
For a As Integer = de.Cols.Count -2 To de.Cols.Count -1
Sheet.Cols(a).Width = 60 '设置第1列的宽度
Next
Sheet(0,0).Style = styel1
Sheet.MergeCell(0,0,1,c+1)
If de.rows(r)(c) = Nothing Then
Sheet(r +3 , c).Value = Nothing
Else
Sheet(r +3 , c).Value = de.rows(r)(c)
End If
Sheet(r +3, c).Style = Style
Sheet(0,c).Style = Style
Sheet(1,c).Style = Style
Sheet(2,c).Style = Style
Sheet(1,c).Style = styel2
Sheet(2,c).Style = styel2
Dim Sum As Double= de.Compute("Sum(数量)")
Dim Sum3 As Double = de.Compute("Sum(箱数)")
Dim Sum1 As Integer
Dim Sum2 As Integer
sum1 = de.Cols.Count
sum2 = de.Rows.Count
Dim dtd As DataTable = DataTables("临时箱单")
Dim dre = dtd.Select("款号 = '" & dm.Text & "'and 合同号 like '%" & cj.Text & "%'")
For Each drf As DataRow In dre
Sum = Sum + drf("数量")
Sum3 = Sum3 + drf("箱数")
Sheet(sum1+2, 0).Value = "合计:"
Sheet(sum1+2, sum2).Value = sum
Sheet(sum1+2, sum2-1).Value = sum3
Next
Next
Next
Book.Save("c:\reports\test.xls")
Dim Proc As New Process
Proc.File = "c:\reports\test.xls"
Proc.Start()
问题解决