Excel in Kopyalanması

Giriş

Excel’de bir aralığı seçebilir, ardından bu aralığı belirli seçeneklerle aynı çalışma sayfasına, diğer çalışma sayfalarına veya diğer dosyalara yapıştırabilirsiniz.

Python Excel Kütüphanesi Aspose.Cells for Python ile Aralıkları Kopyalama

Aspose.Cells for Python via .NET, aralığı kopyalamak için bazı aşırı yükleme Range.copy yöntemleri sağlar. Ve Range.copy_style sadece aralık kopyalama stili; Range.copy_data sadece aralık kopyalama değeri

Aralık Kopyalama

İki aralık oluşturarak: kaynak aralık, hedef aralık, ardından kaynak aralığı hedef aralığına Range.copy yöntemi ile kopyalama.

Aşağıdaki kodu görün:

from aspose.cells import Workbook
# Instantiate a new Workbook.
workbook = Workbook()
# Get all the worksheets in the book.
worksheets = workbook.worksheets
# Get the first worksheet in the worksheets collection.
worksheet = workbook.worksheets[0]
# Create a range of cells.
sourceRange = worksheet.cells.create_range("A1", "A2")
# Input some data with some formattings into
# A few cells in the range.
sourceRange.get(0, 0).put_value("Test")
sourceRange.get(1, 0).put_value("123")
# Create target range of cells.
targetRange = worksheet.cells.create_range("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.create_range("A1", "A2")
# Copy source range to target range in another workhseet
targetRange.copy(sourceRange)
# Copy to another workbook
anotherWorkbook = Workbook()
worksheet = workbook.worksheets[0]
targetRange = worksheet.cells.create_range("A1", "A2")
# Copy source range to target range in another workbook
targetRange.copy(sourceRange)

Seçeneklerle Aralık Yapıştırma

Aspose.Cells for Python via .NET, belirli bir türde aralığı yapıştırmayı destekler.

from aspose.cells import PasteOptions, PasteType, Workbook
# Instantiate a new Workbook.
workbook = Workbook()
# Get all the worksheets in the book.
worksheets = workbook.worksheets
# Get the first worksheet in the worksheets collection.
worksheet = workbook.worksheets[0]
# Create a range of cells.
sourceRange = worksheet.cells.create_range("A1", "A2")
# Input some data with some formattings into
# A few cells in the range.
sourceRange.get(0, 0).put_value("Test")
sourceRange.get(1, 0).put_value("123")
# Create target range of cells.
targetRange = worksheet.cells.create_range("B1", "B2")
# Init paste options.
options = PasteOptions()
# Set paste type.
options.paste_type = PasteType.VALUES_AND_FORMATS
options.skip_blanks = True
# Copy source range to target range
targetRange.copy(sourceRange, options)

Yalnızca Aralık Verilerini Kopyalama

Ayrıca aşağıdaki kodlarla verileri Range.copy_data yöntemi ile kopyalayabilirsiniz.

from aspose.cells import Workbook
# Instantiate a new Workbook.
workbook = Workbook()
# Get all the worksheets in the book.
worksheets = workbook.worksheets
# Get the first worksheet in the worksheets collection.
worksheet = workbook.worksheets[0]
# Create a range of cells.
sourceRange = worksheet.cells.create_range("A1", "A2")
# Input some data with some formattings into
# A few cells in the range.
sourceRange.get(0, 0).put_value("Test")
sourceRange.get(1, 0).put_value("123")
# Create target range of cells.
targetRange = worksheet.cells.create_range("B1", "B2")
# Copy the data of source range to target range
targetRange.copy_data(sourceRange)

Gelişmiş Konular