以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]导出文件符合条件的单元格字体变红加粗 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=134428) |
||||
-- 作者:cqlpjks -- 发布时间:2019/5/3 21:48:00 -- [求助]导出文件符合条件的单元格字体变红加粗 此主题相关图片如下:临界生名册.jpg 导出时报错: 要想符合条件的单元格字体变红加粗(如上表效果),下面代码有误,怎么修改?请指教。谢谢! 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 = "临界生名册已导出并删除!" |
||||
-- 作者:有点甜 -- 发布时间:2019/5/4 9:47:00 --
Dim t As Table = Tables(dlg.FileName) 中红色的代码,改成你自己的表的名称,比如
Dim t As Table = Tables("表A")
|
||||
-- 作者:cqlpjks -- 发布时间:2019/5/5 10:56:00 -- Dim t As Table = Tables("重点线上下"& dr("专科B") &"分名册") |
||||
-- 作者:有点甜 -- 发布时间:2019/5/5 11:02:00 -- 你的table的表名是什么?请具体设置啊
Dim t As Table = Tables("表A")
如果提示不存在对应的表,说明你foxtable里面就是没有对应的表啊。
请单独做个例子发上来测试。 |
||||
-- 作者:cqlpjks -- 发布时间:2019/5/5 12:10:00 -- 例子:
[此贴子已经被作者于2019/5/5 12:14:33编辑过]
|
||||
-- 作者:有点甜 -- 发布时间:2019/5/5 12:49:00 -- 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 = "临界生名册已导出并删除!" |
||||
-- 作者:cqlpjks -- 发布时间:2019/5/5 17:17:00 -- 谢谢! |