Copia intervallo dati con stile.

Contents
[ ]

Aspose.Cells per Python via .NET fornisce una serie di classi e metodi per lavorare con gli intervalli, ad esempio, create_range(upper_left_cell, lower_right_cell), StyleFlag e apply_style(style, flag).

Questo esempio:

  1. Crea un workbook.
  2. Riempie un certo numero di celle nel primo foglio di lavoro con dati.
  3. Crea un Range.
  4. Crea un oggetto Style con attributi di formattazione specificati.
  5. Applica lo stile all’intervallo di dati.
  6. Crea un secondo intervallo di celle.
  7. Copia i dati con la formattazione dal primo intervallo al secondo.
from aspose.cells import BackgroundType, CellBorderType, StyleFlag, Workbook
from aspose.pydrawing import Color
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a new Workbook.
workbook = Workbook()
# Get the first Worksheet Cells.
cells = workbook.worksheets[0].cells
# Fill some sample data into the cells.
for i in range(50):
for j in range(10):
cells.get(i, j).put_value(str(i) + "," + str(j))
# Create a range (A1:D3).
range = cells.create_range("A1", "D3")
style = workbook.create_style()
# Specify the font attribute.
style.font.name = "Calibri"
# Specify the shading color.
style.foreground_color = Color.yellow
style.pattern = BackgroundType.SOLID
# Specify the border attributes.
style.borders.set_color(Color.blue)
style.borders.set_style(CellBorderType.THIN)
# Create the styleflag object.
flag1 = StyleFlag()
# Implement font attribute
flag1.font_name = True
# Implement the shading / fill color.
flag1.cell_shading = True
# Implment border attributes.
flag1.borders = True
# Set the Range style.
range.apply_style(style, flag1)
# Create a second range (C10:F12).
range2 = cells.create_range("C10", "F12")
# Copy the range data with formatting.
range2.copy(range)
dataDir = dataDir + "CopyRange.out.xlsx"
# Save the excel file.
workbook.save(dataDir)