EasyXLS™ library allows setting an autofilter or a custom filter that permits to filter a range of data from an Excel sheet and hide records that don't meet your criteria, displaying just a subset of data in a range of cells.
Source code sample
The below example shows how to export data with autofilter to Excel.
// Create an instance of the class that exports Excel files, having one sheet
ExcelDocument workbook = new ExcelDocument(1);
// Get the table of the first worksheet that will keep the data and the autofilter
ExcelWorksheet xlsTab = ((ExcelWorksheet)workbook.easy_getSheet("Sheet1"));
ExcelTable xlsTable = xlsTab.easy_getExcelTable();
// Add data to cells
...
// Add autofilter to a range of cells
ExcelFilter xlsFilter = xlsTab.easy_getFilter();
xlsFilter.setAutoFilter("A1:E1");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel autofilter.xlsx");
' Create an instance of the class that exports Excel files, having one sheetDim workbook As New ExcelDocument(1)
' Get the table of the first worksheet that will keep the data and the autofilterDim xlsTab As ExcelWorksheet = workbook.easy_getSheet("Sheet1")
Dim xlsTable = xlsTab.easy_getExcelTable
' Add data to cells
...
' Add autofilter to a range of cellsDim xlsFilter As ExcelFilter = xlsTab.easy_getFilter()
xlsFilter.setAutoFilter("A1:E1")
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel autofilter.xlsx")
C++// Create an instance of the class that exports Excel files, having one sheet
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
// Create a worksheet
workbook->easy_addWorksheet_2("Sheet1");
// Get the table of the first worksheet that will keep the data and the autofilter
EasyXLS::IExcelWorksheetPtr xlsTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheet("Sheet1");
EasyXLS::IExcelTablePtr xlsTable = xlsTab->easy_getExcelTable();
// Add data to cells
...
// Add autofilter to a range of cells
EasyXLS::IExcelFilterPtr xlsFilter =
(EasyXLS::IExcelFilterPtr)xlsTab->easy_getFilter();
xlsFilter->setAutoFilter_2("A1:E1");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel autofilter.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files, having one sheet
ExcelDocument ^workbook = gcnew ExcelDocument(1);
// Get the table of the first worksheet that will keep the data and the autofilter
ExcelWorksheet ^xlsTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheet("Sheet1"));
ExcelTable ^xlsTable = xlsTab->easy_getExcelTable();
// Add data to cells
...
// Add autofilter to a range of cells
ExcelFilter ^xlsFilter = xlsTab->easy_getFilter();
xlsFilter->setAutoFilter("A1:E1");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel autofilter.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files, having one sheet
ExcelDocument workbook = new ExcelDocument(1);
// Get the table of the first worksheet that will keep the data and the autofilter
ExcelWorksheet xlsTab = ((ExcelWorksheet)workbook.easy_getSheet("Sheet1"));
ExcelTable xlsTable = xlsTab.easy_getExcelTable();
// Add data to cells
...
// Add autofilter to a range of cells
ExcelFilter xlsFilter = xlsTab.easy_getFilter();
xlsFilter.setAutoFilter("A1:E1");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel autofilter.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create a worksheet
$workbook->easy_addWorksheet_2("Sheet1");
// Get the table of the first worksheet that will keep the data and the autofilter
$xlsTable = $workbook->easy_getSheet("Sheet1")->easy_getExcelTable();
// Add data to cells
...
// Add autofilter to a range of cells
$xlsFilter = $xlsTab->easy_getFilter();
$xlsFilter->setAutoFilter_2("A1:E1");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel autofilter.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create a sheet
$workbook->easy_addWorksheet("Sheet1");
// Get the table of data for the worksheet
$xlsTab = $workbook->easy_getSheet("Sheet1");
$xlsTable = $xlsTab->easy_getExcelTable();
// Add data to cells
...
// Apply auto-filter on cell range A1:E1
$xlsFilter = $xlsTab->easy_getFilter();
$xlsFilter->setAutoFilter("A1:E1");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel autofilter.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create a worksheet
workbook.easy_addWorksheet_2("Sheet1")
' Get the table of the first worksheet that will keep the data and the autofilterSet xlsTable = workbook.easy_getSheet("Sheet1").easy_getExcelTable()
' Add data to cells
...
' Add autofilter to a range of cellsset xlsFilter = xlsTab.easy_getFilter()
xlsFilter.setAutoFilter_2("A1:E1")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel autofilter.xlsx")
' Create an instance of the class that exports Excel files, having one sheetSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create a worksheet
workbook.easy_addWorksheet_2 ("Shet1")
' Get the table of the first worksheet that will keep the data and the autofilterSet xlsTable = workbook.easy_getSheet("Sheet1").easy_getExcelTable()
' Add data to cells
...
' Add autofilter to a range of cellsSet xlsFilter = xlsTab.easy_getFilter()
xlsFilter.setAutoFilter_2 ("A1:E1")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel autofilter.xlsx")
' Create an instance of the class that exports Excel files, having one sheetSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create a worksheet
workbook.easy_addWorksheet_2("Sheet1")
' Get the table of the first worksheet that will keep the data and the autofilterSet xlsTable = workbook.easy_getSheet("Sheet1").easy_getExcelTable()
' Add data to cells
...
' Add autofilter to a range of cellsSet xlsFilter = xlsTab.easy_getFilter()
xlsFilter.setAutoFilter_2("A1:E1")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel autofilter.xlsx")
<!-- Create an instance of the class that exports Excel files, having one sheet --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create a worksheet --><cfset ret = workbook.easy_addWorksheet("Sheet1")><!-- Get the table of the first worksheet that will keep the data and the autofilter --><cfset xlsTable = workbook.easy_getSheet("Sheet1").easy_getExcelTable()><!-- Add data to cells -->
...
<!-- Add autofilter to a range of cells --><cfset xlsFilter = xlsTab.easy_getFilter()><cfset xlsFilter.setAutoFilter("A1:E1")><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel autofilter.xlsx")>
.NET:# Create an instance of the class that exports Excel files having one sheet
workbook = ExcelDocument(1)
# Get the table of data for the worksheet
xlsTab = workbook.easy_getSheet("Sheet1")
xlsTable = xlsTab.easy_getExcelTable()
# Add data in cells
...
# Apply auto-filter on cell range A1:E1
xlsFilter = xlsTab.easy_getFilter()
xlsFilter.setAutoFilter("A1:E1")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel autofilter.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files having one sheet
workbook = gateway.jvm.ExcelDocument(1)
# Get the table of data for the worksheet
xlsTab = workbook.easy_getSheet("Sheet1")
xlsTable = xlsTab.easy_getExcelTable()
# Add data in cells
...
# Apply auto-filter on cell range A1:E1
xlsFilter = xlsTab.easy_getFilter()
xlsFilter.setAutoFilter("A1:E1")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel autofilter.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of an exported Excel report that has an autofilter applied.
Getting started with EasyXLS Excel library
To download the trial version of EasyXLS Excel Library, press the below button:
If you already own a license key, you may login and download EasyXLS from your account.