إعدادات الحدود
إضافة الحدود إلى Cells
Microsoft يسمح Excel للمستخدمين بتنسيق الخلايا عن طريق إضافة حدود. يعتمد نوع الحد على مكان إضافته. على سبيل المثال ، الحد العلوي هو الحد الذي يتم إضافته إلى الموضع العلوي للخلية. يمكن للمستخدمين أيضًا تعديل نمط خط الحدود ولونه.
باستخدام Aspose.Cells ، يمكن للمطورين إضافة حدود وتخصيص شكلها بنفس الطريقة المرنة كما في Microsoft Excel.
إضافة الحدود إلى Cells
Aspose.Cells يوفر فصل دراسي ،دفتر العمل يمثل ملف Excel Microsoft. الدفتر العمل فئة تحتوي علىأوراق عمل مجموعة تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عمل صف دراسي. الورقة عمل فئة توفرCells مجموعة. كل عنصر فيCells تمثل المجموعة كائنًا منCellصف دراسي.
يوفر Aspose.Cells ملفGetStyleالطريقة فيCellصف دراسي. الSetStyleالطريقة المستخدمة لتعيين نمط تنسيق الخلية. الأسلوبتوفر class خصائص لإضافة حدود إلى الخلايا.
إضافة حدود إلى Cell
يمكن للمطورين إضافة حدود إلى خلية باستخدام امتدادأسلوب أشياءالحدود مجموعة. يتم تمرير نوع الحد كفهرس إلى ملفالحدود مجموعة. جميع أنواع الحدود محددة مسبقًا في ملفنوع الحدود تعداد.
تعداد الحدود
أنواع الحدود | وصف |
---|---|
الحد السفلي | خط الحد السفلي |
قطري إلى الأسفل | خط قطري من أعلى اليسار إلى أسفل اليمين |
قطري | خط قطري من أسفل اليسار إلى أعلى اليمين |
يسار | خط حد أيسر |
الحد الأيمن | خط حد صحيح |
TopBorder | خط حد علوي |
الالحدودجمع يخزن جميع الحدود. كل حد فيالحدود المجموعة يمثلهاالحدود كائن يوفر خاصيتين ،اللون وأسلوب الخطلتعيين لون خط الحدود ونمطه على التوالي.
لضبط لون خط الحد ، حدد لونًا باستخدام تعداد اللون (جزء من .NET Framework) وقم بتعيينه لخاصية Color الخاصة بكائن Border.
يتم تعيين نمط خط الحدود عن طريق تحديد نمط خط من ملفCellBorderTypeتعداد.
تعداد CellBorderType
أنماط الخط | وصف |
---|---|
داش دوت | خط رفيع منقّط بشرطة |
DashDotDot | خط رفيع منقّط بشرطة |
متقطع | خط متقطع |
منقط | خط منقط |
مزدوج | خط مزدوج |
شعر | شعري |
متوسط | خط متوسط منقّط بشرطة |
متوسط | خط متوسط منقّط بشرطة |
متوسط متقطع | خط متقطع متوسط |
لا أحد | لا خط |
متوسط | خط متوسط |
مائل | خط مائل منقط بشرطة متوسطة |
سميك | خط سميك |
رفيع | خيط رفيع |
حدد أحد أنماط الخطوط ثم قم بتعيينه إلى ملفالحدود أشياءأسلوب الخط خاصية. |
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first (default) worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Visit Aspose!"); | |
// Create a style object | |
Style style = cell.GetStyle(); | |
// Setting the line style of the top border | |
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick; | |
// Setting the color of the top border | |
style.Borders[BorderType.TopBorder].Color = Color.Black; | |
// Setting the line style of the bottom border | |
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick; | |
// Setting the color of the bottom border | |
style.Borders[BorderType.BottomBorder].Color = Color.Black; | |
// Setting the line style of the left border | |
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick; | |
// Setting the color of the left border | |
style.Borders[BorderType.LeftBorder].Color = Color.Black; | |
// Setting the line style of the right border | |
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick; | |
// Setting the color of the right border | |
style.Borders[BorderType.RightBorder].Color = Color.Black; | |
// Apply the border styles to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls"); |
إضافة حدود إلى مدى من Cells
من الممكن أيضًا إضافة حدود إلى نطاق من الخلايا بدلاً من مجرد خلية واحدة. للقيام بذلك ، أولاً ، قم بإنشاء نطاق من الخلايا عن طريق استدعاءCells المجموعةCreateRange طريقة. يأخذ المعلمات التالية:
- الصف الأول ، الصف الأول من النطاق.
- العمود الأول ، يمثل العمود الأول من النطاق.
- عدد الصفوف ، عدد الصفوف في النطاق.
- عدد الأعمدة ، عدد الأعمدة في النطاق.
الCreateRange طريقة إرجاع أنطاق الكائن الذي يحتوي على نطاق محدد من الخلايا. النطاق كائن يوفرSetOutlineBorder طريقة تأخذ المعلمات التالية لإضافة حد إلى نطاق الخلايا:
- نوع الحدود ، نوع الحد المحدد من ملفنوع الحدودتعداد.
- أسلوب الخط ، نمط خط الحدود المحدد من ملفCellBorderTypeتعداد.
- اللون، لون الخط المحدد من تعداد الألوان.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first (default) worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello World From Aspose"); | |
// Creating a range of cells starting from "A1" cell to 3rd column in a row | |
Range range = worksheet.Cells.CreateRange(0, 0, 1, 3); | |
// Adding a thick top border with blue line | |
range.SetOutlineBorder(BorderType.TopBorder, CellBorderType.Thick, Color.Blue); | |
// Adding a thick bottom border with blue line | |
range.SetOutlineBorder(BorderType.BottomBorder, CellBorderType.Thick, Color.Blue); | |
// Adding a thick left border with blue line | |
range.SetOutlineBorder(BorderType.LeftBorder, CellBorderType.Thick, Color.Blue); | |
// Adding a thick right border with blue line | |
range.SetOutlineBorder(BorderType.RightBorder, CellBorderType.Thick, Color.Blue); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls"); |
الألوان واللوحة
اللوح هو عدد الألوان المتاحة للاستخدام في إنشاء صورة. يتيح استخدام لوحة قياسية في عرض تقديمي للمستخدم إنشاء مظهر متناسق. يحتوي كل ملف Microsoft Excel (97-2003) على لوحة من 56 لونًا يمكن تطبيقها على الخلايا والخطوط وخطوط الشبكة والكائنات الرسومية والتعبئة والخطوط في المخطط.
مع Aspose.Cells لا يمكن فقط استخدام الألوان الموجودة في اللوحة ولكن أيضًا الألوان المخصصة. قبل استخدام لون مخصص ، قم بإضافته إلى اللوحة أولاً.
يناقش هذا الموضوع كيفية إضافة ألوان مخصصة إلى اللوحة.
إضافة ألوان مخصصة إلى لوحة الألوان
Aspose.Cells يدعم Microsoft لوحة الألوان 56 في Excel. لاستخدام لون مخصص غير محدد في اللوحة ، أضف اللون إلى اللوحة.
Aspose.Cells يوفر فصل دراسي ،دفتر العمل ، يمثل ملف Excel Microsoft. الدفتر العمل فئة توفر أChangePalette طريقة تأخذ المعلمات التالية لإضافة لون مخصص لتعديل اللوحة:
- لون مخصص ، اللون المخصص المراد إضافته.
- الفهرس ، فهرس اللون في اللوحة الذي سيحل محله اللون المخصص. يجب أن يكون بين 0-55.
يضيف المثال أدناه لونًا مخصصًا (Orchid) إلى اللوحة قبل تطبيقه على الخط.
// Instantiating an Workbook object | |
Workbook workbook = new Workbook(); | |
//Checks if a color is in the palette for the spreadsheet. | |
Console.WriteLine(workbook.IsColorInPalette(Color.Orchid)); | |
// Adding Orchid color to the palette at 55th index | |
workbook.ChangePalette(Color.Orchid, 55); | |
Console.WriteLine(workbook.IsColorInPalette(Color.Orchid)); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Defining new Style object | |
Style styleObject = workbook.CreateStyle(); | |
// Setting the Orchid (custom) color to the font | |
styleObject.Font.Color = workbook.Colors[55]; | |
// Applying the style to the cell | |
cell.SetStyle(styleObject); | |
// Saving the Excel file | |
workbook.Save("out.xlsx"); |