Fusione e Separazione Cells
introduzione
Non vuoi sempre lo stesso numero di celle in ogni riga o colonna. Ad esempio, potresti voler inserire un titolo in una cella che si estende su più colonne. Oppure, se crei una fattura, potresti volere meno colonne per il totale. Per creare una cella da due o più celle, uniscile. Microsoft Excel consente agli utenti di selezionare i file e unirli per strutturare il foglio di calcolo nel modo desiderato.
Unire Cells in un foglio di lavoro
Unire Cells in Microsoft Excel
I seguenti passaggi descrivono come unire le celle nel foglio di lavoro utilizzando MS Excel.
- Copia i dati desiderati nella cella in alto a sinistra all’interno dell’intervallo.
- Seleziona le celle che desideri unire.
- Per unire le celle in una riga o colonna e centrare il contenuto della cella, fare clic suUnisci e centra icona sulFormattazione barra degli strumenti.
Unire Cells con Aspose.Cells
La classe Aspose.Cells.Cells ha alcuni metodi utili per il compito. Ad esempio, il metodo Merge() unisce le celle in una singola cella all’interno di un intervallo specificato.
L’esempio seguente mostra come unire le celle (C6:E7) in un foglio di lavoro.
// 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 directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Create a Workbook. | |
Workbook wbk = new Workbook(); | |
// Create a Worksheet and get the first sheet. | |
Worksheet worksheet = wbk.Worksheets[0]; | |
// Create a Cells object ot fetch all the cells. | |
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[5, 2].PutValue("This is my value"); | |
// Create a Style object to fetch the Style of C6 Cell. | |
Style style = worksheet.Cells[5, 2].GetStyle(); | |
// Create a Font object | |
Font font = style.Font; | |
// Set the name. | |
font.Name = "Times New Roman"; | |
// Set the font size. | |
font.Size = 18; | |
// Set the font color | |
font.Color = System.Drawing.Color.Blue; | |
// Bold the text | |
font.IsBold = true; | |
// Make it italic | |
font.IsItalic = true; | |
// Set the backgrond color of C6 Cell to Red | |
style.ForegroundColor = System.Drawing.Color.Red; | |
style.Pattern = BackgroundType.Solid; | |
// Apply the Style to C6 Cell. | |
cells[5, 2].SetStyle(style); | |
// Save the Workbook. | |
wbk.Save(dataDir + "mergingcells.out.xls"); |
Unmerging (Splitting) Unificato Cells
Utilizzando Microsoft Excel
I seguenti passaggi descrivono come dividere le celle unite utilizzando Microsoft Excel.
- Seleziona la cella unita. Quando le celle sono state combinate,Unisci e centra è selezionato sulFormattazione barra degli strumenti.
- ClicUnisci e centra sulFormattazione barra degli strumenti.
Utilizzando Aspose.Cells
La classe Aspose.Cells.Cells ha un metodo chiamato UnMerge() che suddivide le celle nel loro stato originale. Il metodo separa le celle utilizzando il riferimento della cella nell’intervallo di celle unite.
L’esempio seguente mostra come dividere le celle unite (C6). L’esempio usa il file creato nell’esempio precedente e divide le celle unite.
// 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 Workbook. | |
// Open the excel file. | |
Workbook wbk = new Aspose.Cells.Workbook(dataDir + "mergingcells.xls"); | |
// Create a Worksheet and get the first sheet. | |
Worksheet worksheet = wbk.Worksheets[0]; | |
// Create a Cells object ot fetch all the cells. | |
Cells cells = worksheet.Cells; | |
// Unmerge the cells. | |
cells.UnMerge(5, 2, 2, 3); | |
// Save the file. | |
wbk.Save(dataDir + "unmergingcells.out.xls"); |