Wiederverwendung von Style Objekten

Contents
[ ]

Um einige Formatierungen auf einen großen Zellenbereich in einem Arbeitsblatt anzuwenden:

  1. Erstellen Sie ein Style-Objekt.
  2. Geben Sie die Attribute an.
  3. Wenden Sie den Style auf die Zellen im Bereich an.
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"));