码迷,mamicode.com
首页 > Web开发 > 详细

Aspose Cells 控件如何实现数据过滤(附代码和下载地址)

时间:2015-06-08 16:32:38      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

Aspose Cells 是一款操作和处理以及转换Excel文件的类库,支持.NET和JAVA版,几乎所有Excel能实现的功能,Aspose Cells都可以实现,在Excel中经常会用到数据过滤,通过过滤规则,以达到想要显示的结果,一般过滤都是根据设置的条件,通常是文本、数字或者日期。

Aspose Cells控件下载地址:http://www.componentcn.com/kongjianchanpin/yonghujiemian/biaogekongjian/2014-09-16/174.html

下面咱们首先介绍,在Excel里是怎么实现数据自动过滤功能的

1. 首先在工作表里点击某一列的列头,然后在"数据"菜单里选择过滤和自动过滤
2. 然后点击过滤箭头查看过滤列表选项

技术分享

技术分享
Aspose Cells里要实现自动过滤也是相当简单的,控件提供了Worksheet类,里面包含了各种属性和方法,其中AutoFilter属性就是用来进行过滤的,该属性是AutoFilter类的实例对象,提供了Range属性用于指定在表头单元格的范围,在每个工作表里只能指定一个过滤范围,这个是Excel所限制的,并不是控件导致的。如果客户需要进行设置数据的自定义过滤可以使用AutoFilter.Custom进行设置。

下面的事例代码阐述了如何使用Aspose Cells进行自动过滤

//Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream("C:\\book1.xls", FileMode.Open);

//Instantiating a Workbook object
//Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);

//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];

//Creating AutoFilter by giving the cells range of the heading row
worksheet.AutoFilter.Range = "A1:B1";

//Saving the modified Excel file
workbook.Save("C:\\output.xls");

//Closing the file stream to free all resources
fstream.Close();

同样地开发人员也可以调用AutoFilter 类的 Filter方法进行过滤条件的设置

//Creating AutoFilter by giving the cells range of the heading row
worksheet.AutoFilter.Range = "A1:B1";

//过滤某一列,采用指定的值
worksheet.AutoFilter.Filter(1, "Bananas");

Aspose Cells 控件如何实现数据过滤(附代码和下载地址)

标签:

原文地址:http://www.cnblogs.com/kjyj/p/4561119.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!