التعامل مع إعدادات الخط
يمكن التحكم في شكل النص وأسلوبه من خلال تغيير إعدادات الخط. قد تتضمن إعدادات الخط هذه الاسم والنمط والحجم واللون والتأثيرات الأخرى للخطوط كما هو موضح أدناه في الشكل:
إعدادات الخط في Microsoft Excel
تمامًا مثل Microsoft Excel ، يدعم Aspose.Cells أيضًا تكوين إعدادات الخط للخلايا.
تكوين إعدادات الخط
Aspose.Cells يوفر فصل دراسي ،دفتر العمل يمثل ملف Excel Microsoft. الدفتر العمل فئة تحتوي علىورقة العمل يسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عملصف دراسي. الورقة عمل فئة توفر أCells مجموعة. كل عنصر فيCells تمثل المجموعة كائنًا منCellصف دراسي.
يوفر Aspose.Cells ملفCell صف دراسي'مجموعة الطريقة المستخدمة لتعيين تنسيق الخلية. أيضا ، موضوعأسلوبتوفر فئة خصائص لتكوين إعدادات الخط.
يوضح هذا المقال كيفية:
- تطبيق خط معين على النص.
- تعيين النص إلى غامق.
- اضبط حجم الخط.
- اضبط لون الخط.
- تسطير النص.
- نص مشطوب.
- تعيين النص إلى منخفض.
- تعيين النص إلى نص مرتفع.
تعيين اسم الخط
تطبيق خط معين على النص في الخلايا باستخدامالخط أشياءاسم مجموعةخاصية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingFontName.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font name to "Times New Roman" | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setName("Times New Roman"); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "SettingFontName_out.xls"); |
تعيين نمط الخط إلى غامق
قم بتعيين النص إلى غامق عن طريق تعيينالخط أشياءsetBold ملكية لحقيقي.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the output directory. | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.getStyle(); | |
// Setting the font weight to bold | |
style.getFont().setBold(true); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(outputDir + "book1.out.xlsx", SaveFormat.XLSX); |
ضبط حجم الخط
اضبط حجم الخط باستخدام ملفالخط أشياءضبط الحجمخاصية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetFontSize.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font weight to bold | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSize(14); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "SetFontSize_out.xls"); |
تعيين نوع تسطير الخط
تسطير النص بامتدادالخط أشياءوضع السطر خاصية. يوفر Aspose.Cells أنواعًا مختلفة من تسطير الخط المعرفة مسبقًا في تنسيقFontUnderlineTypeتعداد.
أنواع تسطير الخط | وصف | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
لا أحد | بدون تسطير | ||||||||||||||||||||||||||||||||||||||||||||||||||
غير متزوج | تسطير واحد | ||||||||||||||||||||||||||||||||||||||||||||||||||
مزدوج | تسطير مزدوج | ||||||||||||||||||||||||||||||||||||||||||||||||||
محاسبة | تسطير محاسبة واحد | ||||||||||||||||||||||||||||||||||||||||||||||||||
DOUBLE_ACCOUNTING | تسطير مزدوج المحاسبة | ||||||||||||||||||||||||||||||||||||||||||||||||||
اندفاع | تسطير متقطع | ||||||||||||||||||||||||||||||||||||||||||||||||||
اندفاع_نقطة_DOT_HEAVY | تسطير ثخين - نقطة - نقطة | ||||||||||||||||||||||||||||||||||||||||||||||||||
اندفاع_نقطة_ثقيل | تسطير نقطي سميك | ||||||||||||||||||||||||||||||||||||||||||||||||||
DASHED_HEAVY | تسطير متقطع سميك | ||||||||||||||||||||||||||||||||||||||||||||||||||
DASH_LONG | تسطير متقطع طويل | ||||||||||||||||||||||||||||||||||||||||||||||||||
اندفاع_طويل_ثقيل | تسطير متقطع سميك طويل | ||||||||||||||||||||||||||||||||||||||||||||||||||
نقطة شرطة | تسطير شرطة نقطة | ||||||||||||||||||||||||||||||||||||||||||||||||||
نقطة_نقطة_اندفاع | تسطير شرطة نقطية | ||||||||||||||||||||||||||||||||||||||||||||||||||
منقط | تسطير منقط | ||||||||||||||||||||||||||||||||||||||||||||||||||
DOTTED_HEAVY | تسطير منقط سميك | ||||||||||||||||||||||||||||||||||||||||||||||||||
ثقيل | تسطير سميك | ||||||||||||||||||||||||||||||||||||||||||||||||||
لوح | تسطير الموجة | ||||||||||||||||||||||||||||||||||||||||||||||||||
WAVY_DOUBLE | تسطير موجة مزدوجة | ||||||||||||||||||||||||||||||||||||||||||||||||||
WAVY_HEAVY | تسطير مموج كثيف | ||||||||||||||||||||||||||||||||||||||||||||||||||
كلمات |
تسطير الأحرف بدون مسافة فقط | ||||||||||||||||||||||||||||||||||||||||||||||||||
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
|
ضبط لون الخط
اضبط لون الخط بامتدادالخط أشياءمجموعة خاصية. حدد أي لون من ملفاللون تعداد وتعيين اللون المحدد إلىالخط أشياءمجموعة.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetFontColor.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font color to blue | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setColor(Color.getBlue()); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "SetFontColor_out.xls"); |
ضبط تأثير الشطب على النص
نص مشطوب بامتدادالخط أشياءsetStrikeoutخاصية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingStrikeOutEffect.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the strike out effect on the font | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setStrikeout(true); | |
cell.setStyle(style); |
إعداد منخفض
جعل النص مرتفعًا باستخدامالخط أشياءتعيينخاصية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetSubscript.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting subscript effect | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSubscript(true); | |
cell.setStyle(style); |
إعداد مرتفع
تطبيق نص مرتفع على النص بامتدادالخط أشياءتعيينخاصية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetSubscript.class) + "data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting superscript effect | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSuperscript(true); | |
cell.setStyle(style); |