ضبط ارتفاع الصف وعرض العمود
العمل مع الصفوف
ضبط ارتفاع الصف
توفر Aspose.Cells فئة Workbook التي تمثل ملف Microsoft Excel. تحتوي فئة Workbook على مجموعة WorksheetCollection التي تسمح بالوصول إلى كل ورقة عمل في ملف Excel. تمثل ورقة عمل بواسطة فئة Worksheet. توفر فئة Worksheet مجموعة Cells التي تمثل جميع الخلايا في ورقة العمل.
توفر مجموعة Cells العديد من الطرق لإدارة الصفوف أو الأعمدة في ورقة عمل. يتم مناقشة بعض هذه الطرق أدناه بمزيد من التفصيل.
ضبط ارتفاع الصف
من الممكن تعيين ارتفاع صف واحد بالاتصال بطريقة setRowHeight. تأخذ طريقة setRowHeight المعلمات التالية:
- مؤشر الصف, مؤشر الصف الذي كنت تغير ارتفاعه.
- ارتفاع الصف, ارتفاع الصف المطبق على الصف.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightOfRow.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of the second row to 13 | |
cells.setRowHeight(1, 13); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightOfRow_out.xls"); |
ضبط ارتفاع جميع الصفوف
لتعيين نفس ارتفاع الصف لكافة الصفوف في ورقة العمل، استخدم أسلوب setStandardHeight في مجموعة Cells
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightAllRows.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of all rows in the worksheet to 15 | |
worksheet.getCells().setStandardHeight(15f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightAllRows_out.xls"); |
العمل مع الأعمدة
ضبط عرض العمود
قم بتعيين عرض العمود عن طريق استدعاء أسلوب setColumnWidth في مجموعة Cells. يأخذ أسلوب setColumnWidth الباراميترات التالية:
- فهرس العمود, فهرس العمود الذي تريد تغيير عرضه.
- عرض العمود, العرض المطلوب للعمود.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfColumn.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of the second column to 17.5 | |
cells.setColumnWidth(1, 17.5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfColumn_out.xls"); |
ضبط عرض كافة الأعمدة
لتعيين نفس عرض العمود لكافة الأعمدة في ورقة العمل، استخدم أسلوب setStandardWidth في مجموعة Cells
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfAllColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of all columns in the worksheet to 20.5 | |
worksheet.getCells().setStandardWidth(20.5f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfAllColumns_out.xls"); |