سمات وألوان Excel
سمات وألوان Excel
توفر النسق مظهرًا موحدًا مع أنماط مسماة وتأثيرات رسومية وكائنات أخرى مستخدمة في مصنف. على سبيل المثال ، يبدو نمط Accent1 ، على سبيل المثال ، مختلفًا في نسق Office و Apex. غالبًا ما تقوم بتطبيق نسق مستند ثم تعديله بالطريقة التي تريدها.
يوفر Aspose.Cells ميزات لتخصيص السمات والألوان.
الحصول على ألوان النسق وتعيينها
فيما يلي بعض الطرق والخصائص التي تنفذ ألوان النسق.
- Style.ForegroundThemeColor: يستخدم لضبط لون المقدمة.
- النمط ، الخلفية ، الموضوع ، اللون: يستخدم لضبط لون الخلفية.
- الخط: يستخدم لضبط لون الخط.
- المصنف: يُستخدم للحصول على لون نسق.
- المصنف. SetThemeColor: يُستخدم لتعيين لون النسق.
يوضح المثال التالي كيفية الحصول على ألوان النسق وتعيينها.
يستخدم المثال التالي ملف قالب XLSX ، ويحصل على ألوان لأنواع مختلفة من ألوان النسق ، ويغير الألوان ويحفظ ملف Excel Microsoft.
// 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); | |
// Instantiate Workbook object. | |
// Open an exiting excel file. | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
// Get the Background1 theme color. | |
Color c = workbook.GetThemeColor(ThemeColorType.Background1); | |
// Print the color. | |
Console.WriteLine("theme color Background1: " + c); | |
// Get the Accent2 theme color. | |
c = workbook.GetThemeColor(ThemeColorType.Accent2); | |
// Print the color. | |
Console.WriteLine("theme color Accent2: " + c); | |
// Change the Background1 theme color. | |
workbook.SetThemeColor(ThemeColorType.Background1, Color.Red); | |
// Get the updated Background1 theme color. | |
c = workbook.GetThemeColor(ThemeColorType.Background1); | |
// Print the updated color for confirmation. | |
Console.WriteLine("theme color Background1 changed to: " + c); | |
// Change the Accent2 theme color. | |
workbook.SetThemeColor(ThemeColorType.Accent2, Color.Blue); | |
// Get the updated Accent2 theme color. | |
c = workbook.GetThemeColor(ThemeColorType.Accent2); | |
// Print the updated color for confirmation. | |
Console.WriteLine("theme color Accent2 changed to: " + c); | |
// Save the updated file. | |
workbook.Save(dataDir + "output.out.xlsx"); |
تخصيص السمات
يوضح المثال التالي كيفية تطبيق السمات المخصصة بالألوان التي تريدها. نستخدم نموذج ملف تم إنشاؤه يدويًا في Microsoft Excel 2007.
يقوم المثال التالي بتحميل ملف قالب XLSX ، وتحديد الألوان لأنواع ألوان السمة المختلفة ، وتطبيق الألوان المخصصة وحفظ ملف Excel.
// 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); | |
// Define Color array (of 12 colors) for Theme. | |
Color[] carr = new Color[12]; | |
carr[0] = Color.AntiqueWhite; // Background1 | |
carr[1] = Color.Brown; // Text1 | |
carr[2] = Color.AliceBlue; // Background2 | |
carr[3] = Color.Yellow; // Text2 | |
carr[4] = Color.YellowGreen; // Accent1 | |
carr[5] = Color.Red; // Accent2 | |
carr[6] = Color.Pink; // Accent3 | |
carr[7] = Color.Purple; // Accent4 | |
carr[8] = Color.PaleGreen; // Accent5 | |
carr[9] = Color.Orange; // Accent6 | |
carr[10] = Color.Green; // Hyperlink | |
carr[11] = Color.Gray; // Followed Hyperlink | |
// Instantiate a Workbook. | |
// Open the template file. | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
// Set the custom theme with specified colors. | |
workbook.CustomTheme("CustomeTheme1", carr); | |
// Save as the excel file. | |
workbook.Save(dataDir + "output.out.xlsx"); |
استخدم ألوان النسق
يطبق المثال التالي ألوان المقدمة والخط للخلية بناءً على أنواع ألوان النسق الافتراضي (للمصنف). كما أنه يحفظ ملف Excel على القرص.
// 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); | |
// Instantiate a Workbook. | |
Workbook workbook = new Workbook(); | |
// Get cells collection in the first (default) worksheet. | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Get the D3 cell. | |
Aspose.Cells.Cell c = cells["D3"]; | |
// Get the style of the cell. | |
Style s = c.GetStyle(); | |
// Set foreground color for the cell from the default theme Accent2 color. | |
s.ForegroundThemeColor = new ThemeColor(ThemeColorType.Accent2, 0.5); | |
// Set the pattern type. | |
s.Pattern = BackgroundType.Solid; | |
// Get the font for the style. | |
Aspose.Cells.Font f = s.Font; | |
// Set the theme color. | |
f.ThemeColor = new ThemeColor(ThemeColorType.Accent4, 0.1); | |
// Apply style. | |
c.SetStyle(s); | |
// Put a value. | |
c.PutValue("Testing1"); | |
// Save the excel file. | |
workbook.Save(dataDir + "output.out.xlsx"); |