تنسيق الصفوف والأعمدة
العمل مع الصفوف
كيفية ضبط ارتفاع الصف
توفر Aspose.Cells for Python via .NET فئة، Workbook، التي تمثل ملف Microsoft Excel. تحتوي فئة Workbook على WorksheetCollection يسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطة فئة Worksheet. توفر فئة Worksheet مجموعة Cells تمثل جميع الخلايا في ورقة العمل.
توفر مجموعة Cells العديد من الطرق لإدارة الصفوف أو الأعمدة في ورقة عمل. يتم مناقشة بعض هذه الطرق أدناه بتفصيل أكثر.
كيفية ضبط ارتفاع الصف
من الممكن ضبط ارتفاع صف واحد عن طريق استدعاء set_row_height الـCells مجموعة set_row_height الـCells الطريقة. تأخذ الطريقة set_row_height المعلمات التالية على النحو التالي:
- الصف, مؤشر الصف الذي تغيير ارتفاعه.
- الارتفاع, ارتفاع الصف المطلوب تطبيقه على الصف.
from aspose.cells import 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(".") | |
# Creating a file stream containing the Excel file to be opened | |
fstream = open(dataDir + "book1.xls", "rb") | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(fstream) | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Setting the height of the second row to 13 | |
worksheet.cells.set_row_height(1, 13) | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.out.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |
كيفية ضبط ارتفاع كل الصفوف في ورقة عمل
إذا كان لدى المطورين حاجة لتعيين نفس ارتفاع الصف لكافة الصفوف في ورقة العمل، فيمكنهم القيام بذلك باستخدام standard_height خاصية مجموعة Cells.
مثال:
from aspose.cells import 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(".") | |
# Creating a file stream containing the Excel file to be opened | |
fstream = open(dataDir + "book1.xls", "rb") | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(fstream) | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Setting the height of all rows in the worksheet to 15 | |
worksheet.cells.standard_height = 15.0 | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.out.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |
العمل مع الأعمدة
كيفية ضبط عرض العمود
قم بتعيين عرض عمود بالاستدعاء set_column_width الـCells مجموعة set_column_width الـCells الطريقة. تأخذ الطريقة set_column_width المعلمات التالية:
- العمود, مؤشر العمود الذي تغيير عرضه.
- العرض, العرض المطلوب للعمود.
from aspose.cells import 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(".") | |
# Creating a file stream containing the Excel file to be opened | |
fstream = open(dataDir + "book1.xls", "rb") | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(fstream) | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Setting the width of the second column to 17.5 | |
worksheet.cells.set_column_width(1, 17.5) | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.out.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |
كيفية تعيين عرض العمود بالبكسل
قم بتعيين عرض عمود بالاستدعاء set_column_width_pixel الـCells مجموعة set_column_width_pixel الـCells الطريقة. تأخذ الطريقة set_column_width_pixel المعلمات التالية:
- العمود, مؤشر العمود الذي تغيير عرضه.
- البكسلات، عرض العمود المطلوب بالبكسل.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
outDir = RunExamples.Get_OutputDirectory() | |
# Load source Excel file | |
workbook = Workbook(sourceDir + "Book1.xlsx") | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Set the width of the column in pixels | |
worksheet.cells.set_column_width_pixel(7, 200) | |
workbook.save(outDir + "SetColumnWidthInPixels_Out.xlsx") |
كيفية ضبط عرض جميع الأعمدة في ورقة العمل
لضبط نفس عرض العمود لجميع الأعمدة في ورقة العمل، استخدم خاصية standard_width لمجموعة Cells.
from aspose.cells import Workbook | |
from os import os, path | |
# 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(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Creating a file stream containing the Excel file to be opened | |
fstream = open(dataDir + "book1.xls", "rb") | |
# Instantiating a Workbook object | |
# Opening the Excel file through the file stream | |
workbook = Workbook(fstream) | |
# Accessing the first worksheet in the Excel file | |
worksheet = workbook.worksheets[0] | |
# Setting the width of all columns in the worksheet to 20.5 | |
worksheet.cells.standard_width = 20.5 | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.out.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |
مواضيع متقدمة
- تكييف صفوف وأعمدة تلقائيًا
- تحويل النص إلى أعمدة باستخدام Aspose.Cells
- نسخ الصفوف والأعمدة
- حذف الصفوف والأعمدة الفارغة في ورقة العمل
- تجميع وفك تجميع الصفوف والأعمدة
- إخفاء وإظهار الصفوف والأعمدة
- إدراج أو حذف الصفوف في ورقة عمل Excel
- إدراج وحذف الصفوف والأعمدة من ملف Excel
- إزالة الصفوف المكررة في ورقة العمل
- تحديث المراجع في ورقات العمل الأخرى أثناء حذف الأعمدة والصفوف الفارغة في ورقة العمل