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

نقل أو نسخ الأوراق باستخدام 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");