الحصول على نطاقات الخلايا
Contents
[
Hide
]
سيناريوهات الاستخدام المحتملة
عندما تحتاج فقط للتلاعب ببعض البيانات في ورقة العمل، تحتاج إلى معرفة مدى البيانات للورقة بأكملها. توفر Aspose.Cells هذه الميزة. يوفر Aspose.Cells الخصائص والطرق التالية لمساعدتك في تحقيق أهدافك.
الحصول على نطاقات الخلايا باستخدام Aspose.Cells
يوضح هذا المثال كيف:
- إنشاء دفتر عمل.
- إضافة بيانات إلى الخلايا في ورقة العمل الأولى.
- الحصول على الخلايا Range.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instantiating an Workbook object | |
Workbook workbook = new Workbook(); | |
//Obtaining the reference of the newly added worksheet | |
Worksheet ws = workbook.Worksheets[0]; | |
Aspose.Cells.Cells cells = ws.Cells; | |
//Setting the value to the cells | |
Aspose.Cells.Cell cell = cells["A1"]; | |
cell.PutValue("Fruit"); | |
cell = cells["B1"]; | |
cell.PutValue("Count"); | |
cell = cells["C1"]; | |
cell.PutValue("Price"); | |
cell = cells["A2"]; | |
cell.PutValue("Apple"); | |
cell = cells["A3"]; | |
cell.PutValue("Mango"); | |
cell = cells["A4"]; | |
cell.PutValue("Blackberry"); | |
cell = cells["A5"]; | |
cell.PutValue("Cherry"); | |
cell = cells["B2"]; | |
cell.PutValue(5); | |
cell = cells["B3"]; | |
cell.PutValue(3); | |
cell = cells["B4"]; | |
cell.PutValue(6); | |
cell = cells["B5"]; | |
cell.PutValue(4); | |
cell = cells["C2"]; | |
cell.PutValue(5); | |
cell = cells["C3"]; | |
cell.PutValue(20); | |
cell = cells["C4"]; | |
cell.PutValue(30); | |
cell = cells["C5"]; | |
cell.PutValue(60); | |
cell = cells["E10"]; | |
Style temp = workbook.CreateStyle(); | |
temp.Font.Color = Color.Red; | |
cell.SetStyle(temp); | |
// Get max display range of worksheet | |
Range range = cells.MaxDisplayRange; | |
//get maximum row index of cell which contains data or style. | |
Console.WriteLine(cells.MaxRow); | |
//get maximum row index of cell which contains data. | |
Console.WriteLine(cells.MaxDataRow); | |
//get maximum column index of cell which contains data or style. | |
Console.WriteLine(cells.MaxColumn); | |
//get maximum column index of cell which contains data. | |
Console.WriteLine(cells.MaxDataColumn); |