繁体   English   中英

VB.NET中的Excel自动筛选

[英]Excel Autofilter in VB.NET

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM