الكشف عن الخلايا المدمجة في ورقة البيانات
يوفر هذا المقال معلومات حول كيفية الحصول على مناطق الخلايا المدمجة في ورقة العمل.
يتيح Aspose.Cells للبايثون via .NET لك الحصول على مناطق الخلايا المدمجة في ورقة العمل، ويمكنك أيضًا إلغاء دمجها (تقسيمها). تشرح هذه المقالة أبسط رمز باستخدام واجهة برمجة التطبيقات Aspose.Cells لأداء هذه المهمة.
يوفر المكون metodologia Cells.get_merged_areas() التي يمكنها الحصول على جميع الخلايا المدمجة. يعرض لك نموذج الشفرة التالي كيفية اكتشاف الخلايا المدمجة في ورقة العمل.
from aspose import pycore | |
from aspose.cells import CellArea, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Instantiate a new Workbook | |
# Open an existing excel file | |
wkBook = Workbook(dataDir + "SampleInput.xlsx") | |
# Get a worksheet in the workbook | |
wkSheet = wkBook.worksheets.get("Sheet2") | |
# Clear its contents | |
wkSheet.cells.clear() | |
# Create an arraylist object | |
al = [] | |
# Get the merged cells list to put it into the arraylist object | |
al = wkSheet.cells.merged_cells | |
# Loop through the arraylist and get each cellarea | |
# To unmerge it | |
for i in range(len(al)): | |
ca = CellArea() | |
ca = pycore.cast(CellArea, al[i]) | |
frow = ca.start_row | |
fcol = ca.start_column | |
erow = ca.end_row | |
ecol = ca.end_column | |
trows = erow - frow + 1 | |
tcols = ecol - fcol + 1 | |
wkSheet.cells.un_merge(frow, fcol, trows, tcols) | |
dataDir = dataDir + "MergeTrial.out.xlsx" | |
# Save the excel file | |
wkBook.save(dataDir) |