Reutilización de Objetos de Estilo
Contents
[
Hide
]
La reutilización de objetos de estilo puede ahorrar memoria y hacer que el programa se ejecute más rápido.
Para aplicar un formato a un gran rango de celdas en una hoja de cálculo:
- Cree un objeto de estilo.
- Especifique los atributos.
- Aplique el estilo a las celdas en el rango.
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); |
El mismo proceso que se discutió anteriormente también se puede realizar de la siguiente manera.
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()); |
Debido a que los métodos Cell.getStyle y Cell.setStyle utilizan mucha menos memoria y son eficientes, la antigua propiedad Cell.getStyle() que consumía mucha memoria innecesaria, se eliminó con el lanzamiento de Aspose.Cells 7.1.0.