Filtrar objetos al cargar el libro de trabajo o la hoja de trabajo
Posibles escenarios de uso
Por favor useLoadOptions.LoadFilter propiedad al filtrar datos del libro de trabajo. Pero si desea filtrar datos de hojas de trabajo individuales, tendrá que anularLoadFilter.startSheet método. Proporcione el valor apropiado de laLoadDataFilterOptions enumeración al crear o trabajar conCargarfiltro.
ÉlLoadDataFilterOptionsenumeración tiene los siguientes valores.
- NINGUNO
- TODOS
- CELL_BLANK
- CELL_STRING
- CELL_NUMERIC
- CELL_ERROR
- CELL_BOOL
- CELL_VALUE
- FÓRMULA
- DATOS_CELULARES
- GRÁFICO
- FORMA
- MERGED_AREA
- FORMATO CONDICIONAL
- VALIDACIÓN DE DATOS
- TABLA DINÁMICA
- MESA
- HIPERVÍNCULOS
- HOJA_AJUSTES
- HOJA_DATOS
- CONFIGURACIÓN_LIBRO
- AJUSTES
- XML_MAPA
- ESTRUCTURA
- PROPIEDADES DEL DOCUMENTO
- DEFINED_NAMES
- VBA
- ESTILO
Filtrar objetos al cargar el libro de trabajo
El siguiente código de ejemplo ilustra cómo filtrar gráficos del libro. Por favor, checa elejemplo de archivo de Excel utilizado en este código y elsalida PDFgenerada por ella. Como puede ver en el resultado PDF, todos los gráficos se han filtrado del libro de trabajo.
// 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); |
Filtrar objetos al cargar la hoja de trabajo
El siguiente código de ejemplo carga elarchivo fuente excel y filtra los siguientes datos de sus hojas de trabajo usando un filtro personalizado.
- Filtra gráficos de la hoja de trabajo denominada NoCharts.
- Filtra las formas de la hoja de trabajo denominada NoShapes.
- Filtra el formato condicional de la hoja de trabajo denominada NoConditionalFormatting.
Una vez, carga elarchivo fuente excel con un filtro personalizado, toma las imágenes de todas las hojas de trabajo una por una. Aquí están las imágenes de salida para su referencia. Como puede ver, la primera imagen no tiene gráficos, la segunda imagen no tiene formas y la tercera imagen no tiene formato condicional.
// 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"); | |
} | |
} | |
} |