نسخ ونقل أوراق العمل داخل وبين المصنفات

نسخ أوراق العمل ونقلها

تشرح هذه المقالة كيفية استخدام Aspose.Cells من أجل:

نسخ ورقة عمل داخل مصنف

الخطوات الأولية هي نفسها لجميع الأمثلة.

  1. قم بإنشاء مصنفين مع بعض البيانات في Microsoft Excel. لأغراض هذا المثال ، أنشأنا مصنفين جديدين في Microsoft Excel وأدخلنا بعض البيانات في أوراق العمل.
  • FirstWorkbook.xls (3 أوراق عمل)

  • SecondWorkbook.xls (ورقة عمل واحدة).

    FirstWorkbook.xls

ما يجب القيام به: image_بديل_نص

SecondWorkbook.xls

ما يجب القيام به: image_بديل_نص

  1. قم بتنزيل وتثبيت Aspose.Cells:
    1. تحميل Aspose.Cells for Java.
  2. قم بفك ضغطه على جهاز الكمبيوتر الخاص بك. الجميعAspose المكونات ، عند تثبيتها ، تعمل في وضع التقييم. لا يوجد حد زمني لوضع التقييم ويقوم فقط بحقن العلامات المائية في المستندات المنتجة.
  3. أنشئ مشروعًا:
  4. قم بإنشاء مشروع باستخدام محرر Java مثل Eclipse أو قم بإنشاء برنامج بسيط باستخدام محرر نصوص.
  5. أضف مسار الفصل:
  6. قم باستخراج Aspose.Cells.jar و dom4j_1.6.1.jar من Aspose.Cells.zip.
  7. قم بتعيين مسار الفصل للمشروع في Eclipse:
  8. حدد مشروعك في Eclipse وانقر فوق القوائممشروع ، ومن بعدملكيات.
  9. حددJava بناء مسار في الجانب الأيسر من مربع الحوار ، ثم حدد علامة التبويب المكتبات ،
  10. انقر فوقأضف الجرار أوإضافة JARs خارجية لاختيار Aspose.Cells.jar و dom4j_1.6.1.jar وإضافتهم إلى مسارات البناء.
  1. نسخ ورقة العمل داخل مصنف: يوجد أدناه الكود المستخدم لإنجاز المهمة. يقوم بنسخ ورقة العمل داخل FirstWorkbook.xls.

يؤدي تنفيذ التعليمات البرمجية إلى نقل ورقة العمل المسماة “نسخ” ضمن FirstWorkbook.xls بالاسم الجديد “الورقة الأخيرة”.

ملف إلاخراج

ما يجب القيام به: image_بديل_نص

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getDataDir(CopyWithinWorkbook.class);
// Create a new Workbook by excel file path
Workbook wb = new Workbook(dataDir + "book1.xls");
// Create a Worksheets object with reference to the sheets of the Workbook.
WorksheetCollection sheets = wb.getWorksheets();
// Copy data to a new sheet from an existing sheet within the Workbook.
sheets.addCopy("Sheet1");
// Save the excel file.
wb.save(dataDir + "mybook.xls");

نقل ورقة العمل في مصنف

يوجد أدناه الكود المستخدم لإنجاز المهمة.

يؤدي تنفيذ التعليمات البرمجية إلى نقل ورقة العمل الانتقال من الفهرس 1 إلى الفهرس 2 في FirstWorkbook.xls.

ملف إلاخراج

ما يجب القيام به: image_بديل_نص

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getDataDir(MoveWorksheet.class);
// Create a new Workbook.
Workbook wb = new Workbook(dataDir + "BkFinance.xls");
// Get the first worksheet in the book.
Worksheet sheet = wb.getWorksheets().get(0);
// Move the first sheet to the third position in the workbook.
sheet.moveTo(2);
// Save the Excel file.
wb.save(dataDir + "BkFinance.xls");

نسخ ورقة عمل بين المصنفات

يؤدي تنفيذ التعليمات البرمجية إلى نسخ ورقة العمل إلى SecondWorkbook.xls بالاسم الجديد Sheet2.

ملف إلاخراج

ما يجب القيام به: image_بديل_نص

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getDataDir(CopyWorksheetsBetweenWorkbooks.class);
// Create a Workbook.
Workbook excelWorkbook0 = new Workbook(dataDir + "book1.xls");
// Create another Workbook.
Workbook excelWorkbook1 = new Workbook();
// Copy the first sheet of the first book into second book.
excelWorkbook1.getWorksheets().get(0).copy(excelWorkbook0.getWorksheets().get(0));
// Save the file.
excelWorkbook1.save(dataDir + "FinalBook.xls", FileFormatType.EXCEL_97_TO_2003);

نقل ورقة العمل بين المصنفات

يؤدي تنفيذ التعليمات البرمجية إلى نقل ورقة العمل من FirstWorkbook.xls إلى SecondWorkbook.xls بالاسم الجديد Sheet3.

إخراج FirstWorkbook.xls

ما يجب القيام به: image_بديل_نص

إخراج SecondWorkbook.xls

ما يجب القيام به: image_بديل_نص

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getDataDir(MoveWorksheet.class);
// Create a new Workbook.
Workbook wb = new Workbook(dataDir + "BkFinance.xls");
// Get the first worksheet in the book.
Worksheet sheet = wb.getWorksheets().get(0);
// Move the first sheet to the third position in the workbook.
sheet.moveTo(2);
// Save the Excel file.
wb.save(dataDir + "BkFinance.xls");

استنتاج