Last active
May 19, 2021 09:33
-
-
Save aspose-com-gists/d1a6633db176cde4400b1ef1f84d3f90 to your computer and use it in GitHub Desktop.
Add or Remove AutoFilter in Excel Files using C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Examples for Adding or Removing AutoFilter in Excel Files using C++ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the source Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Book3.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Creating AutoFilter by giving the cell range | |
worksheet->GetIAutoFilter()->SetRange(new String("A1:B1")); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("AutoFilter_out.xlsx"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the source Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleCountryNames.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Call Custom function to apply the filter | |
worksheet->GetIAutoFilter()->Custom(0, FilterOperatorType_Equal, new String("Brazil")); | |
// Call the Refresh function to update the worksheet | |
worksheet->GetIAutoFilter()->Refresh(); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("CustomFilter_out.xlsx"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the source Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Book4.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Call AddDateFilter function to apply the filter | |
worksheet->GetIAutoFilter()->AddDateFilter(0, DateTimeGroupingType_Month, 2018, 1, 1, 0, 0, 0); | |
// Call the Refresh function to update the worksheet | |
worksheet->GetIAutoFilter()->Refresh(); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("DateFilter_out.xlsx"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the source Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Book4.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Call DynamicFilter function to apply the filter | |
worksheet->GetIAutoFilter()->DynamicFilter(0, DynamicFilterType_Februray); | |
// Call the Refresh function to update the worksheet | |
worksheet->GetIAutoFilter()->Refresh(); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("DynamicDateAutoFilter_out.xlsx"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the source Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("SampleAutoFilter.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Remove AutoFilters | |
worksheet->RemoveAutoFilter(); | |
// Save the Excel file | |
workbook->Save(outDir->StringAppend(new String("RemoveAutoFilter_out.xlsx"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment