Filtra gli oggetti durante il caricamento della cartella di lavoro o del foglio di lavoro
Possibili scenari di utilizzo
Si prega di utilizzareLoadOptions.LoadFilter property durante il filtraggio dei dati dalla cartella di lavoro. Ma se vuoi filtrare i dati da singoli fogli di lavoro, dovrai eseguire l’overrideLoadFilter.startSheet metodo. Si prega di fornire il valore appropriato daLoadDataFilterOptions enumerazione durante la creazione o l’utilizzoCarica filtro.
IlLoadDataFilterOptionsenumerazione ha i seguenti valori.
- NESSUNO
- TUTTO
- CELLA_VUOTO
- CELL_STRING
- CELL_NUMERIC
- CELL_ERROR
- CELL_BOOL
- CELL_VALUE
- FORMULA
- DATI_CELLA
- GRAFICO
- FORMA
- UNIONE_AREA
- FORMATTAZIONE CONDIZIONALE
- CONVALIDA DEI DATI
- TABELLA PIVOT
- TAVOLO
- COLLEGAMENTI IPERTESTUALI
- IMPOSTAZIONI_FOGLIO
- FOGLIO_DATI
- IMPOSTAZIONI_LIBRO
- IMPOSTAZIONI
- XML_MAP
- STRUTTURA
- PROPRIETÀ_DOCUMENTO
- DEFINED_NAMES
- VBA
- STILE
Filtra oggetti durante il caricamento della cartella di lavoro
Il codice di esempio seguente illustra come filtrare i grafici dalla cartella di lavoro. Si prega di controllarefile excel di esempio utilizzato in questo codice e iluscita PDFgenerato da esso. Come puoi vedere nell’output PDF, tutti i grafici sono stati filtrati dalla cartella di lavoro.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(FilterObjectsLoadingWorkbook.class) + "articles/"; | |
//Filter charts from entire workbook | |
LoadOptions ldOpts = new LoadOptions(); | |
ldOpts.setLoadFilter(new LoadFilter(LoadDataFilterOptions.ALL & ~LoadDataFilterOptions.CHART)); | |
//Load the workbook with above filter | |
Workbook wb = new Workbook(dataDir + "sampleFilterCharts.xlsx", ldOpts); | |
//Save entire worksheet into a single page | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.setOnePagePerSheet(true); | |
//Save the workbook in pdf format with the above pdf save options | |
wb.save(dataDir + "sampleFilterCharts.pdf", opts); |
Filtra oggetti durante il caricamento del foglio di lavoro
Il codice di esempio seguente carica il filefile excel di origine e filtra i seguenti dati dai fogli di lavoro utilizzando un filtro personalizzato.
- Filtra i grafici dal foglio di lavoro denominato NoCharts.
- Filtra le forme dal foglio di lavoro denominato NoShapes.
- Filtra la formattazione condizionale dal foglio di lavoro denominato NoConditionalFormatting.
Una volta, carica il filefile excel di origine con un filtro personalizzato, prende le immagini di tutti i fogli di lavoro uno per uno. Ecco le immagini di output per riferimento. Come puoi vedere, la prima immagine non ha grafici, la seconda immagine non ha forme e la terza immagine non ha formattazione condizionale.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
public class FilterObjectsLoadingWorksheets { | |
// Implement your own custom load filter, it will enable you to filter your | |
// individual worksheet | |
class CustomLoadFilter extends LoadFilter { | |
public void startSheet(Worksheet sheet) { | |
if (sheet.getName().equals("NoCharts")) { | |
// Load everything and filter charts | |
this.setLoadDataFilterOptions(LoadDataFilterOptions.ALL& ~LoadDataFilterOptions.CHART); | |
} | |
if (sheet.getName().equals("NoShapes")) { | |
// Load everything and filter shapes | |
this.setLoadDataFilterOptions(LoadDataFilterOptions.ALL& ~LoadDataFilterOptions.DRAWING); | |
} | |
if (sheet.getName().equals("NoConditionalFormatting")) { | |
// Load everything and filter conditional formatting | |
this.setLoadDataFilterOptions(LoadDataFilterOptions.ALL& ~LoadDataFilterOptions.CONDITIONAL_FORMATTING); | |
} | |
}// End StartSheet method. | |
}// End CustomLoadFilter class. | |
public static void main(String[] args) throws Exception { | |
FilterObjectsLoadingWorksheets pg = new FilterObjectsLoadingWorksheets(); | |
pg.Run(); | |
} | |
public void Run() throws Exception { | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(FilterObjectsLoadingWorksheets.class) + "TechnicalArticles/"; | |
// Filter worksheets using custom load filter | |
LoadOptions ldOpts = new LoadOptions(); | |
ldOpts.setLoadFilter(new CustomLoadFilter()); | |
// Load the workbook with above filter | |
Workbook wb = new Workbook(dataDir + "sampleFilterDifferentObjects.xlsx", ldOpts); | |
// Take the image of all worksheets one by one | |
for (int i = 0; i < wb.getWorksheets().getCount(); i++) { | |
// Access worksheet at index i | |
Worksheet ws = wb.getWorksheets().get(i); | |
// Create image or print options, we want the image of entire | |
// worksheet | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setOnePagePerSheet(true); | |
opts.setImageType(ImageType.PNG); | |
// Convert worksheet into image | |
SheetRender sr = new SheetRender(ws, opts); | |
sr.toImage(0, dataDir + ws.getName() + ".png"); | |
} | |
} | |
} |