تخصيص إعدادات الخط باستخدام Node.js عبر C++
تكوين إعدادات الخط
توفر Aspose.Cells فئة Workbook، التي تمثل ملف إكسل من مايكروسوفت. تحتوي فئة Workbook على مجموعة Worksheets تتيح الوصول إلى كل ورقة عمل في ملف إكسل. تمثل ورقة العمل بواسطة فئة Worksheet. توفر فئة Worksheet مجموعة Cells. كل عنصر في مجموعة Cells يمثل كائنًا من فئة Cell.
توفر Aspose.Cells فئة Cell + طرق getStyle و setStyle التي تُستخدم للحصول على وتعيين أسلوب تنسيق الخلية. توفر فئة Style خصائص لضبط إعدادات الخط.
تعيين اسم الخط
يمكن للمطورين تطبيق أي خط على نص داخل خلية باستخدام طريقة {0} من كائن {1} setName.
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); |
تعيين نمط الخط إلى عريض
يمكن للمطورين جعل النص عريضًا عن طريق ضبط طريقة setIsBold لكائن Font على true.
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"); |
تعيين حجم الخط
ضبط حجم الخط باستخدام طريقة setSize من كائن Font.
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"); |
تعيين لون الخط
استخدم طريقة setColor من كائن Font لضبط لون الخط. اختر أي لون من تعداد الألوان (جزء من Node.js) وعيّنه في الطريقة setColor.
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"); |
تعيين نوع تسطير الخط
استخدم طريقة setUnderline لكائن Font لتحت underline النص. تقدم Aspose.Cells أنواعunderline للخط المعرفة مسبقًا في تعداد FontUnderlineType.
أنواع تسطير الخط | الوصف |
---|---|
Accounting | تسطير واحد للحساب |
Double | تسطير مزدوج |
DoubleAccounting | تسطير حسابي مزدوج |
None | بدون تسطير |
Single | تسطير واحد |
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); |
ضبط تأثير شطب
تطبيق الخط عبر تحديد طريقة setIsStrikeout لكائن Font إلى 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")); |
ضبط تأثير الرمز الفرعي
تطبيق الحالة الفرعية عبر تحديد طريقة setIsSubscript لكائن Font إلى 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")); |
ضبط تأثير الرمز العلوي على الخط
يمكن للمطورين تطبيق تأثير المرفوع على الخط عبر تعيين طريقة setIsSuperscript من كائن Font إلى 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 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")); |