Schrift Einstellungen mit Node.js über C++
Konfigurieren von Schriftarteinstellungen
Aspose.Cells bietet eine Klasse, Workbook, die eine Microsoft Excel-Datei repräsentiert. Die Workbook-Klasse enthält eine Worksheets-Sammlung, die den Zugriff auf jedes Arbeitsblatt in einer Excel-Datei ermöglicht. Ein Arbeitsblatt wird durch die Worksheet-Klasse dargestellt. Die Worksheet-Klasse bietet eine Cells-Sammlung. Jedes Element in der Cells-Sammlung stellt ein Objekt der Cell-Klasse dar.
Aspose.Cells bietet die Cell-Klasse mit den getStyle und setStyle-Methoden, die zum Abrufen und Festlegen des Formatierungsstils einer Zelle verwendet werden. Die Style-Klasse bietet Eigenschaften zum Konfigurieren der Schriftarteinstellungen.
Schriftartname festlegen
Entwickler können jede Schriftart auf Text innerhalb einer Zelle anwenden, indem sie die Font-Objekt-setName Methode verwenden.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create directory if it is not already present. | |
const fs = require("fs"); | |
if (!fs.existsSync(dataDir)) { | |
fs.mkdirSync(dataDir); | |
} | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting the font name to "Times New Roman" | |
style.getFont().setName("Times New Roman"); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(path.join(dataDir, "book1.out.xls"), AsposeCells.SaveFormat.Excel97To2003); |
Schriftschnitt auf Fett setzen
Entwickler können den Text fett machen, indem sie die Font-Objekt setIsBold Methode auf true setzen.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
const filePath = path.join(dataDir, "sample.xlsx"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting the font weight to bold | |
style.getFont().setIsBold(true); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("out.xlsx"); |
Schriftgröße festlegen
Stellen Sie die Schriftgröße mit der Font-Objekt setSize-Methode ein.
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
const filePath = path.join(dataDir, "sample.xlsx"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().getCount(); | |
workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting the font size to 14 | |
style.getFont().setSize(14); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("out.xlsx"); |
Schriftfarbe festlegen
Verwenden Sie die Font-Objekt setColor-Methode, um die Schriftfarbe festzulegen. Wählen Sie eine beliebige Farbe aus der Enum-Collection Color (Teil von Node.js) und weisen Sie sie der Methode setColor zu.
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
const filePath = path.join(dataDir, "sample.xlsx"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting the font color to blue | |
style.getFont().setColor(AsposeCells.Color.Blue); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("out.xlsx"); |
Schriftart-Unterstrich-Typ festlegen
Verwenden Sie die Font Objekt- setUnderline Methode, um Text zu unterstreichen. Aspose.Cells bietet verschiedene vordefinierte Unterstreichungstypen in der FontUnderlineType Enumeration.
Schriftart-Unterstreichungstypen | Beschreibung |
---|---|
Accounting | Einzelne Buchhaltungsunterstreichung |
Double | Doppelte Unterstreichung |
DoubleAccounting | Doppelte Buchhaltungsunterstreichung |
None | Keine Unterstreichung |
Single | Einfache Unterstreichung |
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
const outputPath = path.join(dataDir, "out.xlsx"); | |
// Create directory if it is not already present. | |
if (!require("fs").existsSync(dataDir)){ | |
require("fs").mkdirSync(dataDir); | |
} | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting the font to be underlined | |
style.getFont().setUnderline(AsposeCells.FontUnderlineType.Single); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(outputPath); |
Einstellung des Durchgestrichen-Effekts
Strichen Sie durch, indem Sie die Font Objekt- setIsStrikeout Methode auf true setzen.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting the strike out effect on the font | |
style.getFont().setIsStrikeout(true); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(path.join(dataDir, "out.xlsx")); |
Einstellen des Tiefgestellt-Effekts
Apply subscript by setting the Font object’s setIsSubscript method to true.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting the strike out effect on the font | |
style.getFont().setIsStrikeout(true); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(path.join(dataDir, "out.xlsx")); |
Einstellen des Hochgestellt-Effekts auf Schriftart
Entwickler können den Hochstelleneffekt auf die Schriftart anwenden, indem sie die setIsSuperscript Methode des Font Objekts auf true setzen.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
const style = cell.getStyle(); | |
// Setting superscript effect | |
style.getFont().setIsSuperscript(true); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(path.join(dataDir, "out.xlsx")); |