تصفية البيانات
بيانات التصفية التلقائية
التصفية التلقائية هي أسرع طريقة لتحديد العناصر فقط من ورقة العمل التي تريد عرضها في قائمة. تتيح ميزة التصفية التلقائية للمستخدمين تصفية العناصر في قائمة وفقًا لمعايير محددة. تصفية على أساس النص أو الأرقام أو التواريخ.
التصفية التلقائية في Microsoft Excel
لتنشيط ميزة التصفية التلقائية في Microsoft Excel:
- انقر فوق صف العنوان في ورقة العمل.
- منبيانات القائمة ، حددمنقي وثمفلتر السيارات.
عندما تقوم بتطبيق عامل التصفية التلقائي على ورقة عمل ، تظهر مفاتيح التصفية (الأسهم السوداء) على يمين عناوين الأعمدة.
- انقر فوق سهم عامل التصفية لرؤية قائمة بخيارات التصفية.
بعض خيارات التصفية التلقائية هي:
خيارات | وصف |
---|---|
الجميع | إظهار كافة العناصر في القائمة مرة واحدة. |
العادة | تخصيص معايير التصفية مثل يحتوي على / لا يحتوي |
تصفية حسب اللون | المرشحات على أساس اللون المعبأ |
مرشحات التاريخ | يتم ترشيح الصفوف بناءً على معايير مختلفة في التاريخ |
مرشحات الرقم | أنواع مختلفة من التصفية على الأرقام مثل المقارنة والمتوسطات وأعلى 10 إلخ. |
مرشحات النص | مرشحات مختلفة مثل يبدأ بـ ، وينتهي بـ ، يحتوي على إلخ ، |
الفراغات / غير الفراغات | يمكن تنفيذ هذه المرشحات من خلال Text Filter Blank |
يقوم المستخدمون يدويًا بتصفية بيانات ورقة العمل الخاصة بهم في Microsoft Excel باستخدام هذه الخيارات.
مرشح تلقائي مع Aspose.Cells
يوفر Aspose.Cells فئة ، مصنف يمثل ملف Excel. تحتوي فئة المصنف على مجموعة أوراق عمل تتيح الوصول إلى كل ورقة عمل في ملف Excel.
يتم تمثيل ورقة العمل بواسطة فئة ورقة العمل. توفر فئة ورقة العمل نطاقًا واسعًا من الخصائص والأساليب لإدارة أوراق العمل. لإنشاء عامل تصفية تلقائي ، استخدم خاصية التصفية التلقائية لفئة ورقة العمل. خاصية التصفية التلقائية هي كائن من فئة التصفية التلقائية ، والتي توفر خاصية النطاق لتحديد نطاق الخلايا التي تشكل صف عنوان. يتم تطبيق عامل التصفية التلقائي على نطاق الخلايا الذي يمثل صف العنوان.
في كل ورقة عمل ، يمكنك تحديد نطاق تصفية واحد فقط. هذا مقيد بـ Microsoft Excel. لتصفية البيانات المخصصة ، استخدم طريقة AutoFilter.Custom.
في المثال الموضح أدناه ، قمنا بإنشاء نفس التصفية التلقائية باستخدام Aspose.Cells كما أنشأنا باستخدام Microsoft 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); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Creating AutoFilter by giving the cells range of the heading row | |
worksheet.AutoFilter.Range = "A1:B1"; | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.out.xls"); |
أنواع مختلفة من الفلاتر
يوفر Aspose.Cells خيارات متعددة لتطبيق أنواع مختلفة من المرشحات مثل مرشح اللون ومرشح التاريخ ومرشح الأرقام ومرشح النص والمرشحات الفارغة ومرشحات لا شيء فارغ.
لون التعبئة
يوفر Aspose.Cells الوظيفة AddFillColorFilter لترشيح البيانات بناءً على خاصية لون التعبئة للخانات. في المثال الموضح أدناه ، يتم استخدام ملف قالب به ألوان تعبئة مختلفة في العمود الأول من الورقة لاختبار وظيفة تصفية الألوان. يمكن تنزيل ملفات نموذجية من الروابط التالية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(sourceDir + "ColouredCells.xlsx"); | |
// Instantiating a CellsColor object for foreground color | |
CellsColor clrForeground = workbook.CreateCellsColor(); | |
clrForeground.Color = Color.Red; | |
// Instantiating a CellsColor object for background color | |
CellsColor clrBackground = workbook.CreateCellsColor(); | |
clrBackground.Color = Color.White; | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call AddFillColorFilter function to apply the filter | |
worksheet.AutoFilter.AddFillColorFilter(0, BackgroundType.Solid, clrForeground, clrBackground); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "FilteredColouredCells.xlsx"); |
تاريخ
يمكن تنفيذ نوع مختلف من عوامل تصفية التاريخ مثل تصفية جميع الصفوف التي لها تواريخ في يناير 2018. يوضح نموذج التعليمات البرمجية التالي عامل التصفية هذا باستخدام وظيفة AddDateFilter. يتم إعطاء ملفات عينة أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(sourceDir + "Date.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call AddDateFilter function to apply the filter | |
worksheet.AutoFilter.AddDateFilter(0, DateTimeGroupingType.Month, 2018, 1, 0, 0, 0, 0); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "FilteredDate.xlsx"); |
التاريخ الديناميكي
في بعض الأحيان ، تكون المرشحات الديناميكية مطلوبة بناءً على التاريخ مثل جميع الخلايا التي لها تواريخ في يناير بغض النظر عن السنة. في هذه الحالة ، يتم استخدام دالة DynamicFilter كما هو موضح في نموذج التعليمات البرمجية التالي. يتم إعطاء ملفات عينة أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(sourceDir + "Date.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call DynamicFilter function to apply the filter | |
worksheet.AutoFilter.DynamicFilter(0, DynamicFilterType.January); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "FilteredDynamicDate.xlsx"); |
عدد
يمكن تطبيق المرشحات المخصصة باستخدام Aspose.Cells مثل اختيار الخلايا التي تحتوي على رقم بين نطاق معين. يوضح المثال التالي استخدام وظيفة Custom () لتصفية الأرقام. يتم إعطاء ملفات عينة أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(sourceDir + "Number.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call Custom function to apply the filter | |
worksheet.AutoFilter.Custom(0, FilterOperatorType.GreaterOrEqual, 5, true, FilterOperatorType.LessOrEqual, 10); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "FilteredNumber.xlsx"); |
نص
إذا كان العمود يحتوي على نص وخلايا سيتم تحديدها تحتوي على نص معين ، فيمكن استخدام وظيفة Filter (). في المثال التالي ، يحتوي ملف القالب على قائمة بالبلدان وسيتم تحديد صف يحتوي على اسم بلد معين. يوضح الكود التالي ترشيح النص. يتم إعطاء ملفات عينة أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(sourceDir + "Text.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call Filter function to apply the filter | |
worksheet.AutoFilter.Filter(0, "Angola"); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "FilteredText.xlsx"); |
الفراغات
إذا كان العمود يحتوي على نص بحيث تكون بعض الخلايا فارغة ، وكان المرشح مطلوبًا لتحديد تلك الصفوف فقط حيث توجد خلايا فارغة ، فيمكن استخدام وظيفة MatchBlanks () كما هو موضح أدناه. يتم إعطاء ملفات عينة أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(sourceDir + "Blank.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call MatchBlanks function to apply the filter | |
worksheet.AutoFilter.MatchBlanks(0); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "FilteredBlank.xlsx"); |
غير الفراغات
عند تصفية الخلايا التي تحتوي على أي نص ، استخدم وظيفة عامل التصفية MatchNonBlanks كما هو موضح أدناه. يتم إعطاء ملفات عينة أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(sourceDir + "Blank.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Call MatchNonBlanks function to apply the filter | |
worksheet.AutoFilter.MatchNonBlanks(0); | |
// Call refresh function to update the worksheet | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "FilteredNonBlank.xlsx"); |
مرشح مخصص يحتوي على
يوفر Excel عوامل تصفية مخصصة مثل صفوف التصفية التي تحتوي على بعض السلاسل المحددة. تتوفر هذه الميزة في Aspose.Cells والموضحة أدناه من خلال تصفية الأسماء في نموذج الملف. يتم إعطاء ملفات عينة أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object containing sample data | |
Workbook workbook = new Workbook("sourseSampleCountryNames.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Creating AutoFilter by giving the cells range | |
worksheet.AutoFilter.Range = "A1:A18"; | |
// Initialize filter for rows containing string "Ba" | |
worksheet.AutoFilter.Custom(0, FilterOperatorType.Contains, "Ba"); | |
//Refresh the filter to show/hide filtered rows | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save("outSourseSampleCountryNames.xlsx"); |
مرشح مخصص مع NotContains
يوفر Excel عوامل تصفية مخصصة مثل صفوف التصفية التي لا تحتوي على سلسلة معينة. تتوفر هذه الميزة في Aspose.Cells والموضحة أدناه من خلال تصفية الأسماء في نموذج الملف أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object containing sample data | |
Workbook workbook = new Workbook("sourseSampleCountryNames.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Creating AutoFilter by giving the cells range | |
worksheet.AutoFilter.Range = "A1:A18"; | |
// Initialize filter for rows containing string "Ba" | |
worksheet.AutoFilter.Custom(0, FilterOperatorType.NotContains, "Be"); | |
//Refresh the filter to show/hide filtered rows | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save("outSourseSampleCountryNames.xlsx"); |
مرشح مخصص بـ BeginsWith
يوفر Excel عوامل تصفية مخصصة مثل صفوف التصفية التي تبدأ ببعض السلاسل المحددة. تتوفر هذه الميزة في Aspose.Cells والموضحة أدناه من خلال تصفية الأسماء في نموذج الملف أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object containing sample data | |
Workbook workbook = new Workbook(sourceDir + "sourseSampleCountryNames.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Creating AutoFilter by giving the cells range | |
worksheet.AutoFilter.Range = "A1:A18"; | |
// Initialize filter for rows starting with string "Ba" | |
worksheet.AutoFilter.Custom(0, FilterOperatorType.BeginsWith, "Ba"); | |
//Refresh the filter to show/hide filtered rows | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "outSourseSampleCountryNames.xlsx"); |
مرشح مخصص مع EndsWith
يوفر Excel عوامل تصفية مخصصة مثل صفوف التصفية التي تنتهي بسلسلة معينة. تتوفر هذه الميزة في Aspose.Cells والموضحة أدناه من خلال تصفية الأسماء في نموذج الملف أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object containing sample data | |
Workbook workbook = new Workbook(sourceDir + "sourseSampleCountryNames.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Creating AutoFilter by giving the cells range | |
worksheet.AutoFilter.Range = "A1:A18"; | |
// Initialize filter for rows end with string "ia" | |
worksheet.AutoFilter.Custom(0, FilterOperatorType.BeginsWith, "ia"); | |
//Refresh the filter to show/hide filtered rows | |
worksheet.AutoFilter.Refresh(); | |
// Saving the modified Excel file | |
workbook.Save(outputDir + "outSourseSampleCountryNames.xlsx"); |