以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 当导出excel表中的数据小于零时为红色 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=135240) |
-- 作者:mxl810823 -- 发布时间:2019/5/21 16:17:00 -- 当导出excel表中的数据小于零时为红色 下面的代码小于零可以正常为红色 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 想不通为什么会这样?????? |
-- 作者:有点甜 -- 发布时间:2019/5/21 16:56:00 -- Sheet(r + 1,dt.Cols("" & sta & "").Index).Style = Style \'设置单元格的样式
改成
Sheet(r + 1, c).Style = Style \'设置单元格的样式 |