Réutilisation d objets de style
Contents
[
Hide
]
Réutiliser les objets de style peut économiser de la mémoire et rendre le programme plus rapide à exécuter.
Pour appliquer une mise en forme à une grande plage de cellules dans une feuille de calcul :
- Créer un objet de style.
- Spécifier les attributs.
- Appliquer le style aux cellules dans la plage.
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.getDataDir(ReuseStyleObjects.class); | |
// Create an instance of Workbook & load an existing spreadsheet | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Retrieve the Cell Collection of the first Worksheet | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
// Create an instance of Style and add it to the pool of styles | |
Style styleObject = workbook.createStyle(); | |
// Retrieve the Font object of newly created style | |
Font font = styleObject.getFont(); | |
// Set the font color to Red | |
font.setColor(Color.getRed()); | |
// Set the newly created style on two different cells | |
cells.get("A1").setStyle(styleObject); | |
cells.get("A2").setStyle(styleObject); |
Le même processus que celui discuté ci-dessus pourrait également être accompli comme suit.
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
cells.get("A1").getStyle().getFont().setColor(Color.getRed()); | |
cells.get("A2").getStyle().getFont().setColor(Color.getRed()); |
Parce que les méthodes Cell.getStyle et Cell.setStyle utilisent beaucoup moins de mémoire et sont efficaces, l’ancienne propriété Cell.getStyle() qui consommait beaucoup de mémoire inutile, a été supprimée avec la version Aspose.Cells 7.1.0.