Satır ve Sütunları Gruplandırma ve Grubu Çözme

Giriş

Bir Microsoft Excel dosyasında, veriler için bir biçim oluşturarak tek bir fare tıklamasıyla ayrıntı seviyelerini gösterip gizleyebilirsiniz.

Yalnızca özetler veya başlıkların bulunduğu satırları veya sütunları hızlı bir şekilde görüntülemek için Özet Sembolleri, 1,2,3, + ve - simgelerine tıklayabilirsiniz veya simgeleri kullanarak bir çalışma sayfasındaki bir bölümün altındaki ayrıntıları görebilirsiniz, aşağıdaki şekilde gösterildiği gibi:

Satır ve Sütun Gruplama.
todo:image_alt_text

Satır ve Sütun Grubu Yönetimi

Aspose.Cells, bir Microsoft Excel dosyasını temsil eden bir sınıf olan Workbook sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan bir WorksheetCollection içerir. Bir çalışma sayfası, Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, çalışma sayfasındaki tüm hücreleri temsil eden bir Cells koleksiyonu sağlar.

Cells koleksiyonu, çalışma sayfasındaki satırları veya sütunları yönetmek için birkaç yöntem sağlar, bunlardan bazıları aşağıda daha detaylı olarak tartışılmıştır.

Satır ve Sütun Gruplama

Cells koleksiyonunun GroupRows ve GroupColumns yöntemlerini çağırarak satırları veya sütunları gruplamak mümkündür. Her iki yöntem de aşağıdaki parametreleri alır:

  • İlk satır/sütun indeksi, grup içindeki ilk satır veya sütun.
  • Son satır/sütun indeksi, grup içindeki son satır veya sütun.
  • Gizli mi, satırları/sütunları gruplandırmadan sonra gizlemek için bir Boolean parametre.
// 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);
// 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];
// Grouping first six rows (from 0 to 5) and making them hidden by passing true
worksheet.Cells.GroupRows(0, 5, true);
// Grouping first three columns (from 0 to 2) and making them hidden by passing true
worksheet.Cells.GroupColumns(0, 2, true);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();

Grup Ayarları

Microsoft Excel, görüntüleme için grup ayarlarını yapılandırmanıza izin verir:

  • Detayın altında özet satırlar.
  • Ayrıntının sağında özet sütunlar.

Geliştiriciler, Worksheet sınıfının Outline özelliğini kullanarak bu grup ayarlarını yapılandırabilir.

Detaydan Aşağı Özet Satırlar

Özet satırların detayın altında gösterilip gösterilmeyeceğini kontrol etmek de true veya false olarak SummaryRowBelow sınıfının Outline özelliğini ayarlayarak mümkündür.

// 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);
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows and first three columns
worksheet.Cells.GroupRows(0, 5, true);
worksheet.Cells.GroupColumns(0, 2, true);
// Setting SummaryRowBelow property to false
worksheet.Outline.SummaryRowBelow = false;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");

Detayın Sağına Özet Sütunlar

Geliştiriciler, ayrıntının sağında özet sütunları göstermek veya gizlemek için Outline sınıfının SummaryColumnRight özelliğini true veya false olarak ayarlayabilirler.

// 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);
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows and first three columns
worksheet.Cells.GroupRows(0, 5, true);
worksheet.Cells.GroupColumns(0, 2, true);
worksheet.Outline.SummaryColumnRight = true;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");

Satır ve Sütunların Gruplandırılmasını Kaldırma

Gruplanmış herhangi bir satır veya sütunu ayırmak için, Cells koleksiyonunun UngroupRows ve UngroupColumns metodlarını çağırın. Her iki metod da iki parametre alır:

  • İlk satır veya sütun dizini, ayrılmak istenen ilk satır/sütun.
  • Son satır veya sütun dizini, ayrılmak istenen son satır/sütun.

UngroupRows, üçüncü bir Boolean parametresi alan bir aşırı yüklemesi vardır. true olarak ayarlayarak tüm gruplanmış bilgileri kaldırabilirsiniz. Aksi takdirde, yalnızca dış grup bilgileri kaldırılır.

// 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];
// Ungrouping first six rows (from 0 to 5)
worksheet.Cells.UngroupRows(0, 5);
// Ungrouping first three columns (from 0 to 2)
worksheet.Cells.UngroupColumns(0, 2);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();