Aspose Cells 控件如何实现数据过滤(附代码和下载地址)
Aspose Cells?是一款操作和處理以及轉(zhuǎn)換Excel文件的類庫(kù),支持.NET和JAVA版,幾乎所有Excel能實(shí)現(xiàn)的功能,Aspose Cells都可以實(shí)現(xiàn),在Excel中經(jīng)常會(huì)用到數(shù)據(jù)過(guò)濾,通過(guò)過(guò)濾規(guī)則,以達(dá)到想要顯示的結(jié)果,一般過(guò)濾都是根據(jù)設(shè)置的條件,通常是文本、數(shù)字或者日期。
Aspose Cells控件下載地址:http://www.componentcn.com/kongjianchanpin/yonghujiemian/biaogekongjian/2014-09-16/174.html
下面咱們首先介紹,在Excel里是怎么實(shí)現(xiàn)數(shù)據(jù)自動(dòng)過(guò)濾功能的
1. 首先在工作表里點(diǎn)擊某一列的列頭,然后在"數(shù)據(jù)"菜單里選擇過(guò)濾和自動(dòng)過(guò)濾
2. 然后點(diǎn)擊過(guò)濾箭頭查看過(guò)濾列表選項(xiàng)
在Aspose Cells里要實(shí)現(xiàn)自動(dòng)過(guò)濾也是相當(dāng)簡(jiǎn)單的,控件提供了Worksheet類,里面包含了各種屬性和方法,其中AutoFilter屬性就是用來(lái)進(jìn)行過(guò)濾的,該屬性是AutoFilter類的實(shí)例對(duì)象,提供了Range屬性用于指定在表頭單元格的范圍,在每個(gè)工作表里只能指定一個(gè)過(guò)濾范圍,這個(gè)是Excel所限制的,并不是控件導(dǎo)致的。如果客戶需要進(jìn)行設(shè)置數(shù)據(jù)的自定義過(guò)濾可以使用AutoFilter.Custom進(jìn)行設(shè)置。
下面的事例代碼闡述了如何使用Aspose Cells進(jìn)行自動(dòng)過(guò)濾
//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();
同樣地開(kāi)發(fā)人員也可以調(diào)用AutoFilter 類的 Filter方法進(jìn)行過(guò)濾條件的設(shè)置
//Creating AutoFilter by giving the cells range of the heading row
worksheet.AutoFilter.Range = "A1:B1";
//過(guò)濾某一列,采用指定的值
worksheet.AutoFilter.Filter(1, "Bananas");
轉(zhuǎn)載于:https://www.cnblogs.com/kjyj/p/4561119.html
總結(jié)
以上是生活随笔為你收集整理的Aspose Cells 控件如何实现数据过滤(附代码和下载地址)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: WPF 文本框添加水印效果
- 下一篇: magento更新产品状态报错