تنسيق الصفوف والأعمدة
العمل مع الصفوف
كيفية ضبط ارتفاع الصف
توفر Aspose.Cells فئة تُسمى Workbook تمثل ملف Microsoft Excel. تحتوي الفئة Workbook على WorksheetCollection تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطة فئة Worksheet. توفر الفئة Worksheet مجموعة Cells تمثل جميع الخلايا في ورقة العمل.
توفر مجموعة Cells العديد من الطرق لإدارة الصفوف أو الأعمدة في ورقة عمل. يتم مناقشة بعض هذه الطرق أدناه بتفصيل أكثر.
كيفية ضبط ارتفاع الصف
من الممكن ضبط ارتفاع صف واحد عن طريق استدعاء SetRowHeight الـCells مجموعة SetRowHeight الـCells الطريقة. تأخذ الطريقة SetRowHeight المعلمات التالية على النحو التالي:
- مؤشر الصف, مؤشر الصف الذي كنت تغير ارتفاعه.
- ارتفاع الصف, ارتفاع الصف المطبق على الصف.
// 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]; | |
// Setting the height of the second row to 13 | |
worksheet.Cells.SetRowHeight(1, 13); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.out.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
كيفية ضبط ارتفاع كل الصفوف في ورقة عمل
إذا كان لدى المطورين حاجة لتعيين نفس ارتفاع الصف لكافة الصفوف في ورقة العمل، فيمكنهم القيام بذلك باستخدام StandardHeight خاصية مجموعة Cells.
مثال:
// 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]; | |
// Setting the height of all rows in the worksheet to 15 | |
worksheet.Cells.StandardHeight = 15; | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.out.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
العمل مع الأعمدة
كيفية ضبط عرض العمود
قم بتعيين عرض عمود بالاستدعاء SetColumnWidth الـCells مجموعة SetColumnWidth الـCells الطريقة. تأخذ الطريقة SetColumnWidth المعلمات التالية:
- فهرس العمود, فهرس العمود الذي تريد تغيير عرضه.
- عرض العمود, العرض المطلوب للعمود.
// 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]; | |
// Setting the width of the second column to 17.5 | |
worksheet.Cells.SetColumnWidth(1, 17.5); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.out.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
كيفية تعيين عرض العمود بالبكسل
قم بتعيين عرض عمود بالاستدعاء SetColumnWidthPixel الـCells مجموعة SetColumnWidthPixel الـCells الطريقة. تأخذ الطريقة SetColumnWidthPixel المعلمات التالية:
- فهرس العمود, فهرس العمود الذي تريد تغيير عرضه.
- عرض العمود, عرض العمود المطلوب بالبكسل.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
string outDir = RunExamples.Get_OutputDirectory(); | |
//Load source Excel file | |
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Set the width of the column in pixels | |
worksheet.Cells.SetColumnWidthPixel(7, 200); | |
workbook.Save(outDir + "SetColumnWidthInPixels_Out.xlsx"); |
كيفية ضبط عرض جميع الأعمدة في ورقة العمل
لضبط نفس عرض العمود لجميع الأعمدة في ورقة العمل، استخدم خاصية StandardWidth لمجموعة Cells.
// 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); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// 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]; | |
// Setting the width of all columns in the worksheet to 20.5 | |
worksheet.Cells.StandardWidth = 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
- إزالة الصفوف المكررة في ورقة العمل
- تحديث المراجع في ورقات العمل الأخرى أثناء حذف الأعمدة والصفوف الفارغة في ورقة العمل