ワークブックまたはワークシートの読み込み中にオブジェクトをフィルタリングする
Contents
[
Hide
]
考えられる使用シナリオ
使ってくださいLoadOptions.LoadFilterワークブックからデータをフィルタリングする際のプロパティ。ただし、個々のワークシートからデータをフィルター処理する場合は、オーバーライドする必要があります[LoadFilter.startSheet](https://reference.aspose.com/cells/java/com.aspose.cells/loadfilter#startSheet(com.aspose.cells.Worksheet) ) 方法。から適切な値を入力してくださいLoadDataFilterOptions作成中または操作中の列挙LoadFilter.
のLoadDataFilterOptions列挙には次の値があります。
- なし
- 全て
- CELL_BLANK
- CELL_STRING
- CELL_NUMERIC
- CELL_ERROR
- CELL_BOOL
- CELL_VALUE
- 方式
- CELL_DATA
- チャート
- 形
- MERGED_AREA
- 条件付き書式
- データ検証
- ピボットテーブル
- テーブル
- ハイパーリンク
- シート設定
- シートデータ
- BOOK_SETTINGS
- 設定
- XML_MAP
- 構造
- DOCUMENT_PROPERTIES
- DEFINED_NAMES
- VBA
- スタイル
ワークブックの読み込み中にオブジェクトをフィルタリングする
次のサンプル コードは、ワークブックからグラフをフィルター処理する方法を示しています。を確認してくださいサンプルエクセルファイルこのコードと出力 PDFそれによって生成されます。出力 PDF でわかるように、すべてのグラフがワークブックから除外されています。
This file contains 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
// 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); |
ワークシートの読み込み中にオブジェクトをフィルタリングする
次のサンプル コードは、ソースエクセルファイルカスタム フィルターを使用してワークシートから次のデータをフィルター処理します。
- NoCharts という名前のワークシートからチャートをフィルタリングします。
- NoShapes という名前のワークシートから Shapes をフィルター処理します。
- NoConditionalFormatting という名前のワークシートから条件付き書式をフィルター処理します。
一度、ロードしますソースエクセルファイルカスタム フィルターを使用すると、すべてのワークシートの画像を 1 つずつ取得します。参考までに、出力イメージを次に示します。ご覧のとおり、最初の画像にはグラフがなく、2 番目の画像には図形がなく、3 番目の画像には条件付き書式がありません。
This file contains 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
// 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"); | |
} | |
} | |
} |