Unione e separazione di celle
Introduzione
Non si desidera sempre lo stesso numero di celle in ogni riga o colonna. Ad esempio, si potrebbe voler inserire un titolo in una cella che si estende su diverse colonne. Oppure, se si crea una fattura, potrebbe essere necessario meno colonne per il totale. Per rendere una cella da due o più celle, unirle. Microsoft Excel consente agli utenti di selezionare i file e unirli per strutturare il foglio di calcolo nel modo desiderato.
Unione di celle in un foglio di lavoro
Unione di celle in Microsoft Excel
I seguenti passaggi descrivono come unire celle nel foglio di lavoro utilizzando MS Excel.
- Copiare i dati che si desidera nella cella in alto a sinistra nell’intervallo.
- Selezionare le celle che si desidera unire.
- Per unire le celle in una riga o colonna e centrare i contenuti della cella, fare clic sull’icona Unisci e centrato sulla barra degli strumenti Formattazione.
Unione di celle con Aspose.Cells per Python via .NET
La classe Aspose.Cells.Cells dispone di alcuni metodi utili per il compito. Ad esempio, il metodo Merge() unisce le celle in una singola cella all’interno di un intervallo specificato.
Nell’esempio seguente viene mostrato come unire le celle (C6:E7) in un foglio di lavoro.
from aspose.cells import BackgroundType, Workbook | |
from aspose.pydrawing import Color | |
from os import os, path | |
# 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(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Create a Workbook. | |
wbk = Workbook() | |
# Create a Worksheet and get the first sheet. | |
worksheet = wbk.worksheets[0] | |
# Create a Cells object ot fetch all the cells. | |
cells = worksheet.cells | |
# Merge some Cells (C6:E7) into a single C6 Cell. | |
cells.merge(5, 2, 2, 3) | |
# Input data into C6 Cell. | |
worksheet.cells.get(5, 2).put_value("This is my value") | |
# Create a Style object to fetch the Style of C6 Cell. | |
style = worksheet.cells.get(5, 2).get_style() | |
# Create a Font object | |
font = style.font | |
# Set the name. | |
font.name = "Times New Roman" | |
# Set the font size. | |
font.size = 18 | |
# Set the font color | |
font.color = Color.blue | |
# Bold the text | |
font.is_bold = True | |
# Make it italic | |
font.is_italic = True | |
# Set the backgrond color of C6 Cell to Red | |
style.foreground_color = Color.red | |
style.pattern = BackgroundType.SOLID | |
# Apply the Style to C6 Cell. | |
cells.get(5, 2).set_style(style) | |
# Save the Workbook. | |
wbk.save(dataDir + "mergingcells.out.xls") |
Dividere (Separare) celle unite
Utilizzando Microsoft Excel
I seguenti passaggi descrivono come dividere le celle unite usando Microsoft Excel.
- Seleziona la cella unita. Quando le celle sono state unite, su Formato è selezionata l’opzione Unisci e centra.
- Fai clic su Unisci e centra sulla barra degli strumenti Formattazione.
Usando Aspose.Cells per Python via .NET
La classe Aspose.Cells.Cells ha un metodo chiamato UnMerge() che divide le celle nel loro stato originale. Il metodo divide le celle utilizzando il riferimento delle celle nell’intervallo di celle unite.
L’esempio seguente mostra come dividere le celle unite (C6). L’esempio utilizza il file creato nel precedente esempio e divide le celle unite.
from aspose.cells import Workbook | |
# 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(".") | |
# Create a Workbook. | |
# Open the excel file. | |
wbk = Workbook(dataDir + "mergingcells.xls") | |
# Create a Worksheet and get the first sheet. | |
worksheet = wbk.worksheets[0] | |
# Create a Cells object ot fetch all the cells. | |
cells = worksheet.cells | |
# Unmerge the cells. | |
cells.un_merge(5, 2, 2, 3) | |
# Save the file. | |
wbk.save(dataDir + "unmergingcells.out.xls") |