Node.js ile C++ kullanımıyla Font Ayarları

Font Ayarlarını Yapılandırma

Aspose.Cells, Workbook adlı bir sınıf sunar; bu, bir Microsoft Excel dosyasını temsil eder. Workbook sınıfı, her sayfaya erişimi sağlayan Worksheets koleksiyonunu içerir. Bir sayfa, Worksheet sınıfı ile temsil edilir. Worksheet sınıfı ise, Cells koleksiyonunu sağlar. Cells koleksiyonundaki her öğe, Cell sınıfı nesnesini temsil eder.

Aspose.Cells, Cell sınıfının getStyle ve setStyle metodlarını sağlar; bunlar, hücrenin biçimlendirme stilini almak ve ayarlamak içindir. Style sınıfı ise, font ayarlarını yapılandırmak için özellikler sağlar.

Yazı Tipi Adını Ayarlama

Geliştiriciler, herhangi bir fontu hücre içeriğine uygulamak için Font nesnesinin setName metodunu kullanabilir.

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);

Yazı Tipi Stilini Kalın Yapma

Geliştiriciler, Font nesnesinin setIsBold metodunu true olarak ayarlayarak metni kalın yapabilir.

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");

Yazı Tipi Boyutunu Ayarlama

Yazı tipi boyutunu Font nesnesinin setSize metoduyla ayarlayın.

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");

Yazı Tipi Rengini Ayarlama

Yazı tipi rengini Font nesnesinin setColor metodunu kullanarak ayarlayın. Renkleri, Node.js’in bir parçası olan Renk enumundan herhangi biriyle seçin ve setColor metoduna atayın.

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");

Yazı Tipi Altı Çizgi Türünü Ayarlama

Font nesnesinin setUnderline metodunu kullanarak metni altına çizin. Aspose.Cells, FontUnderlineType enumeration’unda çeşitli önceden tanımlanmış yazı tipi alt çizgi türleri sunar.

Yazı Tipi Altı Çizgi Tipleri Açıklama
Accounting Tek hesap çizgisi
Double Çift çizgi
DoubleAccounting Çift hesap çizgisi
None Çizgi yok
Single Tek çizgi
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);

Üstü Çizili Etkiyi Ayarlama

Font nesnesinin setIsStrikeout metodunu true olarak ayarlayarak çizili uygula.

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"));

Üst Simge Etkisini Ayarlama

Font nesnesinin setIsSubscript metodunu true olarak ayarlayarak alt simge uygula.

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"));

Yazı Tipi Üzerine Üst Simge Efekti Ayarlama

Geliştiriciler, setIsSuperscript yöntemini Font nesnesi üzerinde true olarak ayarlayarak üst simge efektini uygulayabilir.

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"));

Gelişmiş Konular