Wiederverwendung von Style Objekten
Contents
[
Hide
]
Die Wiederverwendung von Style-Objekten kann Speicherplatz sparen und ein Programm schneller machen.
Um einige Formatierungen auf einen großen Zellenbereich in einem Arbeitsblatt anzuwenden:
- Erstellen Sie ein Style-Objekt.
- Geben Sie die Attribute an.
- Wenden Sie den Style auf die Zellen im Bereich an.
This file contains hidden or 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
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Access the first worksheet | |
const worksheet = workbook.getWorksheets().get(0); | |
// Access cells | |
const cell1 = worksheet.getCells().get("A1"); | |
const cell2 = worksheet.getCells().get("B1"); | |
// Set the styles of both cells to Times New Roman | |
const styleObject = workbook.createStyle(); | |
styleObject.getFont().setColor(AsposeCells.Color.Red); | |
styleObject.getFont().setName("Times New Roman"); | |
cell1.setStyle(styleObject); | |
cell2.setStyle(styleObject); | |
// Put the values inside the cell | |
cell1.putValue("Hello World!"); | |
cell2.putValue("Hello World!!"); | |
// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
workbook.save(path.join(dataDir, "SampleOutput_out.xlsx")); |
Da der Ansatz Cell.getStyle() / Cell.setStyle(Style) viel weniger Speicher benötigt und effizient ist, wurde die ältere Eigenschaft Cell.style mit der Freigabe von Aspose.Cells 7.1.0 entfernt.