简体   繁体   English

VB.NET中的Excel自动筛选

[英]Excel Autofilter in VB.NET

In my application I'm exporting an Excel file by getting the layout of a HTML page. 在我的应用程序中,我通过获取HTML页面的布局来导出Excel文件。 So, in my codebehind, I'm modifying the HTML layout and inserting itens on it like if it was a webpage. 因此,在我的后台代码中,我正在修改HTML布局并在其上插入itens,就像它是网页一样。 Doing it that way, I don't need to use any external library and, as the data I'm exporting is just a table, I don't need nothing complex to handle it. 这样,我不需要使用任何外部库,并且由于导出的数据只是一个表,因此不需要任何复杂的处理。 My question is: there is a way to create an AutoFilter by just modifying the HTML tags? 我的问题是:有一种方法可以通过仅修改HTML标签来创建自动过滤器? I mean, like if a put a < b>Column Name in the HTML, when exporting to Excel it will become Bold , it is possible to do the same thing with the AutoFilter? 我的意思是,就像在HTML中放置<b>列名一样,当导出到Excel时它将变为Bold ,是否可以使用AutoFilter做同样的事情?

A macro like this may help you. 这样的宏可能会对您有所帮助。 Sorry for the formatting. 抱歉,格式化。

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