0

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

4

1 回答 1

0

像这样的宏可以帮助你。抱歉格式化。

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
于 2010-05-22T06:14:51.847 回答