Filter Objects while loading Workbook or Worksheet
Possible Usage Scenarios
Please use LoadOptions.load_filter property while filtering data from the workbook. But if you want to filter data from individual worksheets, then you will have to override the LoadFilter.start_sheet method. Please provide appropriate value from the LoadDataFilterOptions enumeration while creating or working with LoadFilter.
The LoadDataFilterOptions enumeration has the following possible values.
- All
- BookSettings
- CellBlank
- CellBool
- CellData
- CellError
- CellNumeric
- CellString
- CellValue
- Chart
- ConditionalFormatting
- DataValidation
- DefinedNames
- DocumentProperties
- Formula
- Hyperlinks
- MergedArea
- PivotTable
- Settings
- Shape
- SheetData
- SheetSettings
- Structure
- Style
- Table
- VBA
- XmlMap
Filter Objects while loading Workbook
The following sample code illustrates how to filter charts from the workbook. Please check the sample excel file used in this code and the output PDF generated by it. As you can see in the output PDF, all charts have been filtered out of the workbook.
from aspose.cells import LoadDataFilterOptions, LoadFilter, LoadOptions, PdfSaveOptions, Workbook | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Filter charts from the workbook. | |
lOptions = LoadOptions() | |
lOptions.load_filter = LoadFilter(LoadDataFilterOptions.ALL & ~LoadDataFilterOptions.CHART) | |
# Load the workbook with above filter. | |
workbook = Workbook(dataDir + "sampleFilterCharts.xlsx", lOptions) | |
# Save worksheet to a single PDF page. | |
pOptions = PdfSaveOptions() | |
pOptions.one_page_per_sheet = True | |
# Save the workbook in PDF format. | |
workbook.save(dataDir + "sampleFilterCharts.pdf", pOptions) |