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 = 1 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 '如果指定列(第i列)中含Hj字符存在 For n As Integer = 0 To sheet.Cols.count -1 sheet(i,n).Style = Style Next End If Next Dim t = Tables(Km & tjnj &"级"& tjlb &"重点线上下"& dr("专科B") &"分名册") Dim lr As DataRow = t.DataTable.Find("单位 = '重庆市' And 部别 = '高理' And 年级 = '" & tjnj & "'And 类别 = '" & tjlb & "'") Dim wr As DataRow = t.DataTable.Find("单位 = '重庆市' And 部别 = '高文' And 年级 = '" & tjnj & "'And 类别 = '" & tjlb & "'") For Each km1 As String In km1s '低于有效分的字体变红,加粗 Dim idx = t.Cols(km1).Index Dim bubie = sheet(i, t.Cols("部别").Index).text 'output.show(val(sheet(i, idx).text) & " " & wr(km1)) If bubie = "高理" Then If val(sheet(i, idx).text) < lr(km1) Then sheet(i,idx).Style = Style End If Else If val(sheet(i, idx).text) < wr(km1) Then sheet(i,idx).Style = Style End If End If Next Next book.save(dlg.FileName) Next End If End If e.Form.Controls("Label3").Text = "临界生名册已导出并删除!"
|