下面的代码小于零可以正常为红色
Dim dt As Table = Tables("月盈亏表_Table1")
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim Style As Xls.Style = Book.NewStyle '新建一个样式
Style.foreColor = 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 '填入数据
For c As Integer = 0 To dt.Cols.Count -1
Sheet(r +1, c).Value = dt.rows(r)(c)
Dim sta As String = "" & dt.Cols(c).Name & ""
If sta.StartsWith("M") = True OrElse sta.StartsWith("本") = True Then
If dt.rows(r)("" & sta & "") < 0 Then
Sheet(r + 1,dt.Cols("" & sta & "").Index).Style = Style '设置单元格的样式
End If
End If
Next
Next
下面的代码就是不能显为红色
但是msgbox(55555)是可以正常提示的
修改代码只是想让它只导出部分列的数据
Dim dt As Table = Tables("月盈亏表_Table1")
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim Style As Xls.Style = Book.NewStyle '新建一个样式
Style.foreColor = Color.Red '样式设为红色
'For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
For c As Integer = 0 To wws.count-1 '添加列标题
Sheet(0, c).Value = wws(c)
Next
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
For c As Integer = 0 To wws.count-1
Sheet(r +1, c).Value = dt.rows(r)(wws(c))
Dim sta As String = wws(c)
If sta.StartsWith("M") = True OrElse sta.StartsWith("本") = True Then
If dt.rows(r)("" & sta & "") < 0 Then
msgbox(55555)
Sheet(r + 1,dt.Cols("" & sta & "").Index).Style = Style '设置单元格的样式
End If
End If
Next
Next
想不通为什么会这样??????