Çalışma Sayfasının Hücrelerine Erişme
Hücrelere Erişim
Aspose.Cells, bir Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlar. 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 koleksiyonuna sahiptir.
Hücrelere erişim için Cells koleksiyonu kullanılabilir. Aspose.Cells, çalışma sayfasındaki hücrelere erişmek için üç temel yaklaşım sağlar:
- Hücre adını kullanarak.
- Bir hücrenin satır ve sütun indisini kullanarak.
- Cells koleksiyonundaki bir hücre indeksini kullanarak.
- yaklaşımın en hızlı, 1. yaklaşımın ise en yavaş olduğunu belirttik. Yaklaşımlar arasındaki performans farkı çok küçüktür, bu nedenle hangi yaklaşımı kullanırsanız kullanın performans düşüşü konusunda endişelenmeyin.
Hücre Adı Kullanarak
Geliştiriciler, Cells koleksiyonuna hücre adını bir indeks olarak ileterek belirli bir hücreye erişebilir.
Boş bir çalışma sayfası oluşturursanız, Cells koleksiyonunun sayısı sıfır olacaktır. Bu yaklaşımı kullanarak bir hücreye erişmeye çalıştığınızda, bu hücrenin koleksiyonda var olup olmadığını kontrol eder. Eğer varsa, koleksiyondaki hücre nesnesini döndürür, aksi takdirde yeni bir Cell nesnesi oluşturur, bu nesneyi Cells koleksiyonuna ekler ve ardından bu nesneyi döndürür. Bu yaklaşım, Microsoft Excel ile tanışık olanlar için hücreye erişmenin en kolay yoludur ancak diğer yaklaşımlarla karşılaştırıldığında en yavaş olanıdır.
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 input excel file | |
U16String sampleData = dirPath + u"sampleData.xlsx"; | |
//Read input excel file | |
Workbook workbook(sampleData); | |
//Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Get cells from sheet | |
Cells cells = worksheet.GetCells(); | |
//Accessing a cell using its name | |
Cell cell = cells.Get(u"B3"); | |
//Write string value of the cell on console | |
std::cout << "Value of cell B3: " | |
<< cell.GetStringValue().ToUtf8() << std::endl; | |
Aspose::Cells::Cleanup(); |
Hücrenin Satır ve Sütun İndeksini Kullanma
Geliştiriciler, bir hücrenin satır ve sütun indeksleri ile Cells koleksiyonuna erişebilir. Bu yaklaşım, ilk yaklaşımınkinden aynı şekilde çalışmaktadır.
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 input excel file | |
U16String sampleData = dirPath + u"sampleData.xlsx"; | |
//Read input excel file | |
Workbook workbook(sampleData); | |
//Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Get cells from sheet | |
Cells cells = worksheet.GetCells(); | |
//Accessing cell B3 using its row and column index | |
Cell cell = cells.Get(2, 1); | |
//Write string value of the cell on console | |
std::cout << "Value of cell B3: " | |
<< cell.GetStringValue().ToUtf8() << std::endl; | |
Aspose::Cells::Cleanup(); |
Çalışsayfanın Maksimum Görüntü Aralığına Erişme
Aspose.Cells, geliştiricilere bir çalışma sayfasının maksimum görüntüleme aralığına erişim sağlar. Maksimum görüntüleme aralığı - içerikle dolu ilk ve son hücre aralığı - bir çalışma sayfasının tüm içeriğini bir resimde kopyalamak, seçmek veya göstermek istediğinizde kullanışlıdır.
MaxDisplayRange yöntemini kullanarak bir çalışma sayfasının maksimum görüntüleme aralığına erişebilirsiniz.
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 input excel file | |
U16String sampleData = dirPath + u"sampleData.xlsx"; | |
//Read input excel file | |
Workbook workbook(sampleData); | |
//Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Get cells from sheet | |
Cells cells = worksheet.GetCells(); | |
//Access the Maximum Display Range | |
Range range = cells.GetMaxDisplayRange(); | |
//Print string value of the cell on console | |
std::cout << "Maximum Display Range of Worksheet: " | |
<< range.GetRefersTo().ToUtf8() << std::endl; | |
Aspose::Cells::Cleanup(); |