Foxtable(狐表)用户栏目专家坐堂 → [求助]导出文件符合条件的单元格字体变红加粗


  共有4055人关注过本帖树形打印复制链接

主题:[求助]导出文件符合条件的单元格字体变红加粗

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/5/4 9:47:00 [显示全部帖子]

 

Dim t As Table = Tables(dlg.FileName) 中红色的代码,改成你自己的表的名称,比如

 

Dim t As Table = Tables("表A")

 

 

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/5/5 11:02:00 [显示全部帖子]

你的table的表名是什么?请具体设置啊

 

Dim t As Table = Tables("表A")

 

如果提示不存在对应的表,说明你foxtable里面就是没有对应的表啊。

 

请单独做个例子发上来测试。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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 = "临界生名册已导出并删除!"

 回到顶部