Riutilizzo degli oggetti stile
Contents
[
Hide
]
Il riutilizzo degli oggetti stile può risparmiare memoria e rendere un programma più veloce.
Per applicare una formattazione a un’ampia gamma di celle in un foglio di lavoro:
- Creare un oggetto stile.
- Specificare gli attributi.
- Applicare lo stile alle celle nell’intervallo.
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")); |
Poiché il metodo Cell.getStyle() / Cell.setStyle(Style) utilizza molto meno memoria, ed è più efficiente, il vecchio metodo Cell.style che consumava molta memoria inutile è stato rimosso con il rilascio di Aspose.Cells 7.1.0.