Stilobjekte wiederverwenden
Contents
[
Hide
]
Die Wiederverwendung von Stilobjekten kann Speicherplatz sparen und die Ausführung des Programms beschleunigen.
So wenden Sie einige Formatierungen auf einen großen Bereich von Zellen in einem Arbeitsblatt an:
- Erstellen Sie ein Stilobjekt.
- Geben Sie die Attribute an.
- Wenden Sie den Stil auf die Zellen im Bereich an.
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); |
Derselbe Prozess wie oben diskutiert könnte auch wie folgt durchgeführt werden.
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()); |
Weil derCell.getStyle undCell.setStyle-Methoden verwenden viel weniger Speicher und sind effizienter, je älterCell.getStyle() -Eigenschaft, die viel unnötigen Speicher verbrauchte, wurde mit der Veröffentlichung von entferntAspose.Cells 7.1.0.