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

نقل أو نسخ الأوراق باستخدام Microsoft Excel

فيما يلي الخطوات المتبعة لنسخ أوراق العمل ونقلها داخل المصنفات أو بينها في Microsoft Excel.

  1. لنقل الأوراق أو نسخها إلى مصنف آخر ، افتح المصنف الذي سيتلقى الأوراق.
  2. قم بالتبديل إلى المصنف الذي يحتوي على الأوراق التي تريد نقلها أو نسخها ، ثم حدد الأوراق.
  3. على التعديل القائمة ، انقر فوقنقل أو نسخ الورقة.
  4. في الللحجز الحوار ، انقر فوق المصنف لاستلام الأوراق.
  5. لنقل الأوراق المحددة أو نسخها إلى مصنف جديد ، انقر فوق “موافق”كتاب جديد.
  6. في القبل الورقة في المربع ، انقر فوق الورقة التي تريد إدراج الأوراق المنقولة أو المنسوخة قبلها.
  7. لنسخ الأوراق بدلاً من نقلها ، حدد ملفقم بإنشاء نسخة خانة الاختيار.

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

يوفر Aspose.Cells طريقة التحميل الزائد ،Aspose.Cells.WorksheetCollection.AddCopy ()، يتم استخدامها لإضافة ورقة عمل إلى المجموعة ونسخ البيانات من ورقة عمل موجودة. إصدار واحد من الأسلوب يأخذ فهرس ورقة العمل المصدر كمعامل. الإصدار الآخر يأخذ اسم ورقة العمل المصدر.

يوضح المثال التالي كيفية نسخ ورقة عمل موجودة داخل مصنف.

// 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);
string InputPath = dataDir + "book1.xls";
// Open an existing Excel file.
Workbook wb = new Workbook(InputPath);
// Create a Worksheets object with reference to
// the sheets of the Workbook.
WorksheetCollection sheets = wb.Worksheets;
// Copy data to a new sheet from an existing
// sheet within the Workbook.
sheets.AddCopy("Sheet1");
// Save the Excel file.
wb.Save(dataDir + "CopyWithinWorkbook_out.xls");

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

يوفر Aspose.Cells طريقة ،Aspose.Cells.Worksheet.Copy ()تُستخدم لنسخ البيانات والتنسيق من ورقة عمل مصدر إلى ورقة عمل أخرى داخل المصنفات أو بينها. تأخذ الطريقة كائن ورقة العمل المصدر كمعلمة.

يوضح المثال التالي كيفية نسخ ورقة عمل من مصنف إلى مصنف آخر.

// 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);
string InputPath = dataDir + "book1.xls";
// Create a Workbook.
// Open a file into the first book.
Workbook excelWorkbook0 = new Workbook(InputPath);
// Create another Workbook.
Workbook excelWorkbook1 = new Workbook();
// Copy the first sheet of the first book into second book.
excelWorkbook1.Worksheets[0].Copy(excelWorkbook0.Worksheets[0]);
// Save the file.
excelWorkbook1.Save(dataDir + "CopyWorksheetsBetweenWorkbooks_out.xls");

يوضح المثال التالي كيفية نسخ ورقة عمل من مصنف إلى آخر.

// 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 a new Workbook.
Workbook excelWorkbook0 = new Workbook();
// Get the first worksheet in the book.
Worksheet ws0 = excelWorkbook0.Worksheets[0];
// Put some data into header rows (A1:A4)
for (int i = 0; i < 5; i++)
{
ws0.Cells[i, 0].PutValue(string.Format("Header Row {0}", i));
}
// Put some detail data (A5:A999)
for (int i = 5; i < 1000; i++)
{
ws0.Cells[i, 0].PutValue(string.Format("Detail Row {0}", i));
}
// Define a pagesetup object based on the first worksheet.
PageSetup pagesetup = ws0.PageSetup;
// The first five rows are repeated in each page...
// It can be seen in print preview.
pagesetup.PrintTitleRows = "$1:$5";
// Create another Workbook.
Workbook excelWorkbook1 = new Workbook();
// Get the first worksheet in the book.
Worksheet ws1 = excelWorkbook1.Worksheets[0];
// Name the worksheet.
ws1.Name = "MySheet";
// Copy data from the first worksheet of the first workbook into the
// first worksheet of the second workbook.
ws1.Copy(ws0);
// Save the excel file.
excelWorkbook1.Save(dataDir + "CopyWorksheetFromWorkbookToOther_out.xls");

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

يوفر Aspose.Cells طريقةAspose.Cells.Worksheet.MoveTo () والذي يستخدم لنقل ورقة العمل إلى موقع آخر في نفس جدول البيانات. تأخذ الطريقة فهرس ورقة العمل الهدف كمعامل.

يوضح المثال التالي كيفية نقل ورقة عمل إلى موقع آخر داخل المصنف.

// 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);
string InputPath = dataDir + "book1.xls";
// Open an existing excel file.
Workbook wb = new Workbook(InputPath);
// Create a Worksheets object with reference to
// the sheets of the Workbook.
WorksheetCollection sheets = wb.Worksheets;
// Get the first worksheet.
Worksheet worksheet = sheets[0];
// Move the first sheet to the third position in the workbook.
worksheet.MoveTo(2);
// Save the excel file.
wb.Save(dataDir + "MoveWorksheet_out.xls");