|
| 1 | +/* |
| 2 | + * Copyright 2001-2016 Aspose Pty Ltd. All Rights Reserved. |
| 3 | + * |
| 4 | + * This file is part of Aspose.Cells. The source code in this file |
| 5 | + * is only intended as a supplement to the documentation, and is provided |
| 6 | + * "as is", without warranty of any kind, either expressed or implied. |
| 7 | + */ |
| 8 | +package com.aspose.cells.examples.files.handling; |
| 9 | + |
| 10 | +import com.aspose.cells.LoadDataOption; |
| 11 | +import com.aspose.cells.LoadOptions; |
| 12 | +import com.aspose.cells.Workbook; |
| 13 | +import com.aspose.cells.examples.Utils; |
| 14 | + |
| 15 | +public class LoadVisibleSheetsOnly { |
| 16 | + |
| 17 | + public static void main(String[] args) throws Exception { |
| 18 | + String dataDir = Utils.getDataDir(LoadVisibleSheetsOnly.class); |
| 19 | + String sampleFile = "Sample.out.xlsx"; |
| 20 | + String samplePath = dataDir + sampleFile; |
| 21 | + |
| 22 | + // Create a sample workbook |
| 23 | + // and put some data in first cell of all 3 sheets |
| 24 | + Workbook createWorkbook = new Workbook(); |
| 25 | + createWorkbook.getWorksheets().get("Sheet1").getCells().get("A1").setValue("Aspose"); |
| 26 | + createWorkbook.getWorksheets().add("Sheet2").getCells().get("A1").setValue("Aspose"); |
| 27 | + createWorkbook.getWorksheets().add("Sheet3").getCells().get("A1").setValue("Aspose"); |
| 28 | + // Keep Sheet3 invisible |
| 29 | + createWorkbook.getWorksheets().get("Sheet3").setVisible(false); |
| 30 | + createWorkbook.save(samplePath); |
| 31 | + |
| 32 | + // Load the sample workbook |
| 33 | + LoadDataOption loadDataOption = new LoadDataOption(); |
| 34 | + loadDataOption.setOnlyVisibleWorksheet(true); |
| 35 | + LoadOptions loadOptions = new LoadOptions(); |
| 36 | + loadOptions.setLoadDataAndFormatting(true); |
| 37 | + loadOptions.setLoadDataOptions(loadDataOption); |
| 38 | + |
| 39 | + Workbook loadWorkbook = new Workbook(samplePath, loadOptions); |
| 40 | + |
| 41 | + System.out.println("Sheet1: A1: " + loadWorkbook.getWorksheets().get("Sheet1").getCells().get("A1").getValue()); |
| 42 | + System.out.println("Sheet2: A1: " + loadWorkbook.getWorksheets().get("Sheet2").getCells().get("A1").getValue()); |
| 43 | + System.out.println("Sheet3: A1: " + loadWorkbook.getWorksheets().get("Sheet3").getCells().get("A1").getValue()); |
| 44 | + |
| 45 | + System.out.println("Data is not loaded from invisible sheet"); |
| 46 | + } |
| 47 | +} |
| 48 | + |
0 commit comments