إدراج وحذف الصفوف والأعمدة
مقدمة
سواء أكنت تنشئ ورقة عمل جديدة من البداية أو تعمل على ورقة عمل موجودة ، فقد نحتاج إلى إضافة صفوف أو أعمدة إضافية لاستيعاب المزيد من البيانات. بشكل عكسي ، قد نحتاج أيضًا إلى حذف الصفوف أو الأعمدة من المواضع المحددة في ورقة العمل. للوفاء بهذه المتطلبات ، يوفر Aspose.Cells أبسط مجموعة من الفئات والطرق الموضحة أدناه.
إدارة الصفوف والأعمدة
Aspose.Cells يوفر فصل دراسي ،IWorkbook ، يمثل ملف Excel Microsoft. الIWorkbook فئة تحتوي علىأوراق العمل مجموعة تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةIWorksheet صف دراسي. الIWorksheet فئة توفرآيسيلسمجموعة تمثل جميع الخلايا في ورقة العمل.
الآيسيلستوفر المجموعة عدة طرق لإدارة الصفوف والأعمدة في ورقة العمل. تمت مناقشة بعض هذه أدناه.
أدخل صفًا
أدخل صفًا في ورقة العمل في أي مكان عن طريق استدعاء ملفالصف إدراج طريقةآيسيلس مجموعة. الالصف إدراجتأخذ الطريقة فهرس الصف حيث سيتم إدراج الصف الجديد.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Inserting a row into the worksheet at 3rd position | |
worksheet->GetICells()->InsertRow(2); | |
//Save the Excel file. | |
workbook->Save(outputInsertingDeletingRowsAndColumns); | |
إدراج صفوف متعددة
لإدراج عدة صفوف في ورقة عمل ، قم باستدعاءإدراج صفوف طريقةآيسيلس مجموعة. الإدراج صفوفتأخذ الطريقة معلمتين:
- فهرس الصف ، فهرس الصف حيث سيتم إدراج الصفوف الجديدة.
- عدد الصفوف ، العدد الإجمالي للصفوف التي يجب إدراجها.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Inserting 10 rows into the worksheet starting from 3rd row | |
worksheet->GetICells()->InsertRows(2, 10); | |
//Save the Excel file. | |
workbook->Save(outputInsertingDeletingRowsAndColumns); |
حذف عدة صفوف
لحذف عدة صفوف من ورقة العمل ، قم باستدعاءDeleteRows طريقةآيسيلس مجموعة. الDeleteRowsتأخذ الطريقة معلمتين:
- فهرس الصف ، فهرس الصف الذي سيتم حذف الصفوف منه.
- عدد الصفوف ، العدد الإجمالي للصفوف التي يجب حذفها.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Deleting 10 rows from the worksheet starting from 3rd row | |
worksheet->GetICells()->DeleteRows(2, 10); | |
//Save the Excel file. | |
workbook->Save(outputInsertingDeletingRowsAndColumns); |
أدخل عمود
يمكن للمطورين أيضًا إدراج عمود في ورقة العمل في أي مكان عن طريق استدعاءإدراج العمود طريقةآيسيلس مجموعة.إدراج العمودتأخذ الطريقة فهرس العمود حيث سيتم إدراج العمود الجديد.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleInsertingDeletingRowsAndColumns = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputInsertingDeletingRowsAndColumns = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleInsertingDeletingRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Inserting a column into the worksheet at 2nd position | |
worksheet->GetICells()->InsertColumn(1); | |
//Save the Excel file. | |
workbook->Save(outputInsertingDeletingRowsAndColumns); |
احذف عمود
لحذف عمود من ورقة العمل في أي مكان ، قم باستدعاءDeleteColumn طريقةآيسيلس مجموعة. الDeleteColumnالأسلوب يأخذ فهرس العمود لحذفه.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleDeleteColumn = dirPath->StringAppend(new String("sampleInsertingDeletingRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputDeleteColumn = outPath->StringAppend(new String("outputInsertingDeletingRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleDeleteColumn); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Deleting a column from the worksheet at 2nd position | |
worksheet->GetICells()->DeleteColumn(4); | |
//Save the Excel file. | |
workbook->Save(outputDeleteColumn); |