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

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

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

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

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

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

  • SecondWorkbook.xls (1 ورقة عمل).

    FirstWorkbook.xls

todo:image_alt_text

SecondWorkbook.xls

todo:image_alt_text

  1. قم بتنزيل وتثبيت Aspose.Cells:
    1. تحميل Aspose.Cells for Java.
    2. قم بفك الضغط عنها في جهاز التطوير الخاص بك. جميع مكونات Aspose ، عند التثبيت، تعمل في وضع التقييم. وضع التقييم ليس له حد زمني ولكنه يضيف علامات مائية فقط إلى المستندات المنتجة.
  2. أنشئ مشروعًا:
    1. إنشاء مشروع باستخدام محرر جافا مثل Eclipse أو إنشاء برنامج بسيط باستخدام محرر نصي.
  3. إضافة مسار فئة:
    1. استخراج Aspose.Cells.jar و dom4j_1.6.1.jar من Aspose.Cells.zip.
    2. ضبط مسار الفئة للمشروع في Eclipse:
      1. حدد مشروعك في Eclipse وانقر على القوائم Project, ثم Properties.
      2. حدد Java Build Path في الجهة اليسرى من الصندوق، ثم حدد علامة التبويب Libraries،
      3. انقر على Add JARs أو Add External JARs لتحديد Aspose.Cells.jar و dom4j_1.6.1.jar وإضافتهما إلى مسارات البناء.
  1. نسخ ورقة العمل داخل كتاب عمل: أدناه الكود المستخدم لإنجاز المهمة. يقوم بنسخ ورقة العمل النسخ داخل FirstWorkbook.xls.

تنفيذ الكود ينقل ورقة العمل بالاسم نسخة داخل FirstWorkbook.xls بالاسم الجديد الورقة الأخيرة.

ملف الإخراج

todo:image_alt_text

// 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");

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

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

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

ملف الإخراج

todo:image_alt_text

// 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");

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

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

ملف الإخراج

todo:image_alt_text

// 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);

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

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

ملف FirstWorkbook.xls الإخراج

todo:image_alt_text

ملف SecondWorkbook.xls الإخراج

todo:image_alt_text

// 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");

الاستنتاج