使用以下命令在导出 Excel 文件中启用 Excel 自动筛选
我编写了一个 C# 方法,它将导出到 Excel 2007,一个包含 html 表的 html 文件。在 Excel 中打开导出的文件时,数据呈现完美。
我想在上述导出中添加一个额外的功能,以便当我在 Excel 中打开导出的数据时,自动过滤器会自动打开。
在导出过程中,我可以在 C# 中做什么来为所有列启用自动筛选?
I have written a C# method that will export to Excel 2007, a html file that contains an html table. The data renders perfectly when the exported file is opened in Excel.
I would like to add an extra feature into the above export, so that when I open the exported data in Excel, the autofilter is turned on automatically.
What can I do in C# during export, to enable autofilter for all columns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果要自动使过滤器显示在通过以编程方式将 html 导出到 .xls 文件而创建的 Excel 文件中的标题行,请记住向此文件添加以下 2 个功能。
就是这样。然后你就完成了。就这么简单。下面给出了一个示例列表,我从记事本将其另存为“SampleInHTML.xls”,并在 Excel 2007 和 Excel 2010 中进行了测试,可以与在 Excel 中打开保存的文件时自动出现的自动筛选功能完美配合。
If you want to automatically make the filters appear for header row in an Excel file that is created through programatically exporting html to an .xls file, then remember to add the following 2 features to this file.
That's it. Then you are done. Its as simple as this. A sample listing that I saved as 'SampleInHTML.xls' from notepad and tested in Excel 2007 AND Excel 2010 to work perfectly with auto-filtering appearing automatically on opening the saved file in Excel, is given below.
要执行此类操作,您必须直接对电子表格对象进行操作。据我所知,这不能通过导出 HTML 表来完成。
我已经使用了 Gembox.Spreadsheet ,它将能够做你想做的事情。然而,它不是免费的。
To do these kind of things, you have to operate directly against a spreadsheet obect. As far as I know this cannot be done by exporting a HTML table.
I have used Gembox.Spreadsheet and it will be able to do what you want. However, it is not free.
好吧,我只需使用以下几点即可实现此目的:
xmlns:x="urn:schemas-microsoft-com:office:excel"
。th
的 Autofilter 属性 -x:autofilter='all'
下面是该示例的 html。
Well, I was able to achieve this just using below points:
xmlns:x="urn:schemas-microsoft-com:office:excel"
.th
-x:autofilter='all'
Below is the sample html for that.