Dim Values() As String = {"总分"}
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
For Each Value As String In Values
If e.Form.Controls("年级").value Is Nothing Then
MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
Else
Dim nj As String = e.Form.Controls("年级").text
If Value <> "成绩库" And Value <> "校名设置" Then
If DataTables.Contains(value & nj & "级目标") Then
Tables(value & nj & "级目标").SaveExcel(dlg.FileName,value & nj & "级目标") '保存文件
'DataTables.Delete(value & nj & "级目标") '删除原文件
End If
End If
Dim book As new XLS.Book(dlg.FileName) '保存为Excel文件
Dim sheet As XLS.Sheet = book.Sheets(value & nj & "级目标") '保存为Excel文件中的一个工作表
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 = {"全区合计","分数线"}
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
Next
Style.BorderTop = XLS.LineStyleEnum.Thin
Style.BorderBottom = XLS.LineStyleEnum.Thin
Style.BorderLeft = XLS.LineStyleEnum.Thin
Style.BorderRight = XLS.LineStyleEnum.Thin
Style.BorderColorTop = Color.Black
Style.BorderColorBottom = Color.Black
Style.BorderColorLeft = Color.Black
Style.BorderColorRight = Color.Black
Book.Save(dlg.FileName) '保存文件
End If
Next
e.Form.Controls("Label1").Text = "目标统计表已导出并删除!"
End If
只是单位 = {"全区合计","分数线"}的行单元格加了网格线
此主题相关图片如下:网格线12.png

要想全部加风格线如何修改代码?请指教。谢谢!
此主题相关图片如下:更改后.png

[此贴子已经被作者于2021/3/29 17:07:52编辑过]