Charger des feuilles de calcul spécifiques dans un classeur
Contents
[
Hide
]
Par défaut, Aspose.Cells charge l’intégralité de la feuille de calcul en mémoire. Il est possible de charger uniquement des feuilles spécifiques. Cela peut améliorer les performances et consommer moins de mémoire. Cette approche est utile lorsqu’on travaille avec un grand classeur composé de nombreuses feuilles de calcul.
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Define a new Workbook. | |
Workbook workbook; | |
// Load the workbook with the spcified worksheet only. | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx); | |
loadOptions.LoadFilter = new CustomLoad(); | |
// Creat the workbook. | |
workbook = new Workbook(dataDir+ "TestData.xlsx", loadOptions); | |
// Perform your desired task. | |
// Save the workbook. | |
workbook.Save(dataDir+ "outputFile.out.xlsx"); |
Voici l’implémentation de la classe CustomLoad.
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-.NET | |
class CustomLoad : LoadFilter | |
{ | |
public override void StartSheet(Worksheet sheet) | |
{ | |
if (sheet.Name == "Sheet2") | |
{ | |
// Load everything from worksheet "Sheet2" | |
this.LoadDataFilterOptions = LoadDataFilterOptions.All; | |
} | |
else | |
{ | |
// Load nothing | |
this.LoadDataFilterOptions = LoadDataFilterOptions.Structure; | |
} | |
} | |
} |