نسخ نطاقات اكسل

مقدمة

في اكسل، يمكنك تحديد نطاق، ونسخ النطاق، ثم لصقه بخيارات محددة إلى نفس ورقة العمل، أوراق العمل الأخرى، أو ملفات أخرى.

نسخ النطاقات باستخدام Aspose.Cells

توفر Aspose.Cells بعض أشكال تحميل زائد نطاق.نسخ لنسخ النطاق. و نطاق.نسخنمط النسخ فقط النمط من النطاق؛ نطاق.نسخالبيانات فقط نسخ قيمة النطاق

نسخ النطاق

إنشاء نطاقين: النطاق المصدر، النطاق الهدف، ثم نسخ النطاق المصدر إلى النطاق الهدف باستخدام طريقة نطاق.نسخ.

انظر الكود التالي:

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.Worksheets[0];
// Create a range of cells.
Range sourceRange = worksheet.Cells.CreateRange("A1", "A2");
// Input some data with some formattings into
// A few cells in the range.
sourceRange[0, 0].PutValue("Test");
sourceRange[1, 0].PutValue("123");
// Create target range of cells.
Range targetRange = worksheet.Cells.CreateRange("B1", "B2");
// Copy source range to target range in the same workhseet
targetRange.Copy(sourceRange);
// Create target range of cells.
workbook.Worksheets.Add();
worksheet = workbook.Worksheets[1];
targetRange = worksheet.Cells.CreateRange("A1", "A2");
// Copy source range to target range in another workhseet
targetRange.Copy(sourceRange);
//Copy to another workbook
Workbook anotherWorkbook = new Workbook();
worksheet = workbook.Worksheets[0];
targetRange = worksheet.Cells.CreateRange("A1", "A2");
// Copy source range to target range in another workbook
targetRange.Copy(sourceRange);
view raw Copy-Range.cs hosted with ❤ by GitHub

لصق النطاق مع الخيارات

تدعم Aspose.Cells لصق النطاق بنوع محدد.

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.Worksheets[0];
// Create a range of cells.
Range sourceRange = worksheet.Cells.CreateRange("A1", "A2");
// Input some data with some formattings into
// A few cells in the range.
sourceRange[0, 0].PutValue("Test");
sourceRange[1, 0].PutValue("123");
// Create target range of cells.
Range targetRange = worksheet.Cells.CreateRange("B1", "B2");
// Init paste options.
PasteOptions options = new PasteOptions();
// Set paste type.
options.PasteType = PasteType.ValuesAndFormats;
options.SkipBlanks = true;
// Copy source range to target range
targetRange.Copy(sourceRange, options);
view raw Paste-Range.cs hosted with ❤ by GitHub

نسخ بيانات النطاق فقط

أيضا يمكنك نسخ البيانات مع طريقة نطاق.نسخالبيانات كما في الشفرات التالية:

// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get all the worksheets in the book.
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first worksheet in the worksheets collection.
Worksheet worksheet = workbook.Worksheets[0];
// Create a range of cells.
Range sourceRange = worksheet.Cells.CreateRange("A1", "A2");
// Input some data with some formattings into
// A few cells in the range.
sourceRange[0, 0].PutValue("Test");
sourceRange[1, 0].PutValue("123");
// Create target range of cells.
Range targetRange = worksheet.Cells.CreateRange("B1", "B2");
// Copy the data of source range to target range
targetRange.CopyData(sourceRange);

مواضيع متقدمة