要想符合条件的单元格字体变红加粗(如上表效果),下面代码有误,怎么修改?请指教。谢谢!
Dim Kms() As String = {"总分"}
Dim bbs() As String = {"高文","高理"}
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
If e.Form.Controls("年级").value Is Nothing And e.Form.Controls("类别").value Is Nothing Then '如果统计年级和类别存在
MessageBox.Show("请选择统计年级和类别再执行此操作","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
Else
Dim tjnj As String = e.Form.Controls("年级").text '统计年级
Dim tjlb As String = e.Form.Controls("类别").text '统计类别
For Each Km As String In Kms
Dim dr As DataRow = DataTables("校名设置").Find("单位 = '统计'")
Tables(Km & tjnj &"级"& tjlb &"重点线上下"& dr("专科B") &"分名册").SaveExcel(dlg.FileName, "重点线上下"& dr("专科B") &"分名册") '保存文件
'DataTables.Delete( Km & tjnj &"级"& tjlb &"重点线上下"& dr("专科B") &"分名册") '删除原文件
Dim book As new XLS.Book(dlg.FileName)
Dim sheet As XLS.Sheet = book.Sheets("重点线上下"& dr("专科B") &"分名册") '工作表
Dim Style As Xls.Style = book.NewStyle '新建一个样式
Style.ForeColor = Color.Red '样式的字体颜色设为红色
Style.Font = new font("宋体",9,FontStyle.Bold) '宋体,9号,红色,加粗
Style.AlignHorz = XLS.AlignHorzEnum.Center '居中
Style.AlignVert = XLS.AlignVertEnum.Center '居中
For i As Integer = 0 To sheet.Rows.count -1
Dim Hjs() As String = {"重庆市","梁平县"}
Dim km1s() As String = {"语文","数学","英语","物理","化学","生物","政治","历史","地理"}
For Each Hj As String In Hjs '符合条件和行变红加粗
If sheet(i,0).Text.EndsWith(Hj) Then '如果指定列(第1列)中含Hj字符存在
For n As Integer = 0 To sheet.Cols.count -1
sheet(i,n).Style = Style
Next
End If
Next
For Each km1 As String In km1s '低于有效分的字体变红,加粗
Dim t As Table = Tables(dlg.FileName)
Dim ns2 As C1.Win.C1FlexGrid.CellStyle = t.grid.Styles.Add("自定义的样式2")
ns2.ForeColor = Color.Red
ns2.Font = New Font("宋体",9, FontStyle.Bold)
For Each bb As String In bbs
For Each r As Row In t.Rows
If r("部别") = "高理" Then
Dim lr As DataRow = DataTables(dlg.FileName).Find("单位 = '重庆市' And 部别 = '高理' And 年级 = '" & tjnj & "'And 类别 = '" & tjlb & "'")
If r(km1) < lr(km1) Then
t.Grid.SetCellStyle(r.Index+1, t.Cols(km1).Index+1, ns2)
End If
Else
Dim wr As DataRow = DataTables(dlg.FileName).Find("单位 = '重庆市' And 部别 = '高文' And 年级 = '" & tjnj & "'And 类别 = '" & tjlb & "'")
If r(km1) < wr(km1) Then
t.Grid.SetCellStyle(r.Index+1, t.Cols(km1).Index+1, ns2)
End If
End If
Next
Next
Next
Next
Book.Save(dlg.FileName)
Next
End If
End If
e.Form.Controls("Label1").Text = "临界生名册已导出并删除!"