تطبيق التنسيق الشرطي في ورقة العمل
سيتيح لك Aspose.Cells العمل مع الخصائص المضمنة والمخصصة للوثيقة. هذه هي واجهة Microsoft Excel لفتح خصائص الوثيقة فقط انقر فوق خصائص متقدمة كما هو موضح في لقطة الشاشة وقم بعرضها.
تتيح Aspose.Cells لك إضافة جميع أنواع التنسيق الشرطي مثل الصيغة، فوق المتوسط، مقياس الألوان، شريط البيانات، مجموعة الرموز، أعلى 10، وما إلى ذلك. توفر فئة FormatCondition (https://reference.aspose.com/cells/cpp/aspose.cells/formatcondition/) جميع الأساليب الضرورية لتطبيق التنسيق الشرطي الذي تختاره. إليك قائمة ببعض أساليب Get.
تطبيق التنسيق الشرطي في ورقة العمل
كود العينة التالي يوضح كيفية إضافة تنسيق خانة القيمة الشرطي على الخلايا A1 و B2. يرجى الاطلاع على الملف الإكسل المُنتَج بواسطة الكود والصورة التوضيحية التالية التي توضح تأثير الكود على الملف الإكسل الناتج. إذا قمت بإدخال قيمة أكبر من 100 في الخلية A2 و B2، ستختفي لون التعبئة الأحمر من الخلية A1 و B2.
الكود المثالي
Aspose::Cells::Startup(); | |
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input | |
U16String dirPath(u""); | |
//Path of output | |
U16String outPath(u""); | |
//Path of output excel file | |
U16String outputApplyConditionalFormattingInWorksheet = outPath + u"outputApplyConditionalFormattingInWorksheet.xlsx"; | |
//Create an empty workbook | |
Workbook wb; | |
//Access first worksheet | |
Worksheet ws = wb.GetWorksheets().Get(0); | |
//Adds an empty conditional formatting | |
int idx = ws.GetConditionalFormattings().Add(); | |
FormatConditionCollection fcs = ws.GetConditionalFormattings().Get(idx); | |
//Set the conditional format range | |
CellArea ca = CellArea::CreateCellArea(u"A1", u"A1"); | |
fcs.AddArea(ca); | |
ca = CellArea::CreateCellArea(u"B2", u"B2"); | |
fcs.AddArea(ca); | |
//Add condition and set the background color | |
idx = fcs.AddCondition(FormatConditionType::CellValue, OperatorType::Between, u"=A2", u"100"); | |
FormatCondition fc = fcs.Get(idx); | |
fc.GetStyle().SetBackgroundColor(Color{ 0xff,0xff ,0 ,0 });//Red | |
//User friendly message to test the output excel file. | |
U16String msgStr = u"Red color in cells A1 and B2 is because of Conditional Formatting. Put 101 or any value >100 in cell A2 and B2, you will see Red background color will be gone."; | |
ws.GetCells().Get(u"A10").PutValue(msgStr); | |
//Save the output excel file | |
wb.Save(outputApplyConditionalFormattingInWorksheet); | |
Aspose::Cells::Cleanup(); |