إظهار وإخفاء الصفوف والأعمدة وأشرطة التمرير

إظهار وإخفاء الصفوف والأعمدة

توفر Aspose.Cells فئة، Workbook، تمثل ملف Microsoft Excel. فئة Workbook تحتوي على مجموعة Worksheets تتيح للمطورين الوصول إلى كل ورق عمل في ملف Excel. يتم تمثيل ورقة العمل بفئة Worksheet. توفر فئة Worksheet مجموعة Cells تمثل جميع الخلايا في ورقة العمل. توفر مجموعة Cells العديد من الطرق لإدارة الصفوف أو الأعمدة في ورقة عمل. يتم مناقشة بعض هذه الطرق أدناه.

إظهار الصفوف والأعمدة

يمكن للمطورين عرض أي صف أو عمود مخفي عن طريق استدعاء طرق UnhideRow وUnhideColumn من مجموعة Cells على التوالي. تأخذ كلا الطريقين معلمتين:

  • فهرس الصف أو العمود - فهرس الصف أو العمود المستخدم لعرض الصف أو العمود المحدد.
  • ارتفاع الصف أو عرض العمود - ارتفاع الصف أو عرض العمود المعين للصف أو العمود بعد عرضه.
// 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);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Unhiding the 3rd row and setting its height to 13.5
worksheet.Cells.UnhideRow(2, 13.5);
// Unhiding the 2nd column and setting its width to 8.5
worksheet.Cells.UnhideColumn(1, 8.5);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();

إخفاء الصفوف والأعمدة

يمكن للمطورين إخفاء صف أو عمود عن طريق استدعاء طرق HideRow وHideColumn من مجموعة Cells على التوالي. تأخذ كلا الطريقين فهم فهرس الصف والعمود كمعلمة لإخفاء الصف أو العمود المحدد.

// 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);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Hiding the 3rd row of the worksheet
worksheet.Cells.HideRow(2);
// Hiding the 2nd column of the worksheet
worksheet.Cells.HideColumn(1);
// Saving the modified Excel file
workbook.Save(dataDir + "output.out.xls");
// Closing the file stream to free all resources
fstream.Close();

إخفاء صفوف وأعمدة متعددة

يمكن للمطورين إخفاء عدة صفوف أو أعمدة دفعة واحدة عن طريق استدعاء طرق HideRows وHideColumns من مجموعة Cells على التوالي. تأخذ كلا الطريقين فهرس الصف أو العمود البدء وعدد الصفوف أو الأعمدة التي يجب إخفاؤها كمعلمات.

// 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);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Hiding 3,4 and 5 rows in the worksheet
worksheet.Cells.HideRows(2, 3);
// Hiding 2 and 3 columns in the worksheet
worksheet.Cells.HideColumns(1, 2);
// Saving the modified Excel file
workbook.Save(dataDir + "outputxls");
// Closing the file stream to free all resources
fstream.Close();

إظهار وإخفاء شريط التمرير

يُستخدم شريط التمرير للتنقل في محتويات أي ملف. عادة ما تكون هناك نوعين من شرائط التمرير:

  • شرائط التمرير العمودية
  • شرائط التمرير الأفقية

توفر Microsoft Excel أيضًا شرائط تمرير أفقية وعمودية بحيث يمكن للمستخدمين التمرير من خلال محتويات ورقة العمل. باستخدام Aspose.Cells، يمكن للمطورين التحكم في رؤية كلا أنواع شرائط التمرير في ملفات Excel.

التحكم في رؤية شرائط التمرير

توفر Aspose.Cells فئة، Workbook تمثل ملف Excel. توفر فئة Workbook مجموعة واسعة من الخصائص والأساليب لإدارة ملف Excel. للتحكم في رؤية شرائط التمرير، استخدم خصائص فئة Workbook WorkbookSettings.IsVScrollBarVisible و WorkbookSettings.IsHScrollBarVisible. WorkbookSettings.IsVScrollBarVisible و WorkbookSettings.IsHScrollBarVisible هما خصائص منطقية، مما يعني أن هذه الخصائص يمكنها تخزين قيم صحيحة أو غير صحيحة فقط.

جعل أشرطة التمرير مرئية

اجعل شرائط التمرير مرئية عن طريق تعيين خصائص الفئة Workbook WorkbookSettings.IsVScrollBarVisible أو WorkbookSettings.IsHScrollBarVisible إلى صحيحة.

إخفاء أشرطة التمرير

إخفاء أشرطة التمرير عن طريق تعيين خصائص الصنف Workbook WorkbookSettings.IsVScrollBarVisible أو WorkbookSettings.IsHScrollBarVisible إلى false.

كود عينة

بالأسفل يوجد شيفرة كاملة تفتح ملف إكسل، book1.xls، ثم تخفي كلتي الشريطين وتحفظ الملف المعدل بشكل output.xls.

// 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);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Hiding the vertical scroll bar of the Excel file
workbook.Settings.IsVScrollBarVisible = false;
// Hiding the horizontal scroll bar of the Excel file
workbook.Settings.IsHScrollBarVisible = false;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();