【问题标题】:Excel Autofilter in VB.NETVB.NET 中的 Excel 自动过滤器
【发布时间】:2010-12-16 09:56:45
【问题描述】:

在我的应用程序中,我通过获取 HTML 页面的布局来导出 Excel 文件。因此,在我的代码隐藏中,我正在修改 HTML 布局并在其上插入元素,就像它是网页一样。这样做,我不需要使用任何外部库,并且由于我要导出的数据只是一张表,我不需要任何复杂的东西来处理它。我的问题是:有一种方法可以通过修改 HTML 标签来创建自动过滤器吗?我的意思是,如果在 HTML 中放一个 列名,当导出到 Excel 时它将变为 Bold,是否可以使用 AutoFilter 做同样的事情?

【问题讨论】:

    标签: html vb.net excel autofilter


    【解决方案1】:

    这样的宏可能会对您有所帮助。抱歉格式化了。

    Sub HTMLConvert()
    
    Dim X As Integer
    Dim Y As Integer
    
    'Make your range of rows here
    For X = 1 To 50
    
    'Make your range of columns here
    For Y = 1 To 10
    
    'Each tag that you want to look for needs one of these if statements
    If InStr(1, Cells(X, 1), "<b>") > 0 Then
    
    'Keep in mind this solution will only bold the whole cell, not part of one.
    
    Cells(X, 1).Font.Bold = True
    Cells(X, 1) = Replace(Cells(X, 1), "<b>", "")
    
    'If you have a closing tag, like </b>, make sure you clear it too
    
    End If
    
    Next
    
    Next
    
    End Sub
    

    【讨论】:

    • 请记住,这个宏是一个 VBA 宏,在您导入文本后在 Excel 中使用。
    猜你喜欢
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多