Unisci o separa Cells in un foglio di lavoro in VSTO e Aspose.Cells
Contents
[
Hide
]
Apri un file excel esistente, unisci alcune celle nel primo foglio di lavoro nella cartella di lavoro e salva il file excel.
Fusione Cells
VSTO
Di seguito sono riportati i frammenti di codice paralleli per VSTO (C#) e Aspose.Cells for .NET (C#).
//Instantiate the Application object.
Excel.Application excelApp = Application;
//Specify the template excel file path.
string myPath = "Book1.xls";
//Open the excel file.
excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
//Get the range of cells i.e.., A1:C1.
Excel.Range rng1 = excelApp.get_Range("A1", "C1");
//Merge the cells.
rng1.Merge(Missing.Value);
rng1 = excelApp.get_Range("A1", Missing.Value);
//Save the file.
excelApp.ActiveWorkbook.Save();
//Quit the Application.
excelApp.Quit();
Aspose.Cells
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Specify the template excel file path.
string myPath = "Book1.xls";
//Open the excel file.
workbook.Open(myPath);
//Get the range of cells i.e.., A1:C1.
Aspose.Cells.Range rng1 = workbook.Worksheets[0].Cells.CreateRange("A1", "C1");
//Merge the cells.
rng1.Merge();
//Save the file.
workbook.Save("Book1.xls");
Separazione Cells
Per separare le celle, utilizzare le seguenti righe di codice per VSTO (C#) e Aspose.Cells for .NET (C#).
VSTO
//UnMerge the cell.
rng1.UnMerge();
Aspose.Cells
Cells rng = workbook.Worksheets[0].Cells;
//UnMerge the cell.
rng.UnMerge(0, 0, 1, 3);
Scarica il codice di esempio
- Github
- SourceForge
- [Bitbucket](https://bitbucket.org/asposemarketplace/aspose-for-vsto/downloads/Merge%20or%20UnMerge%20Cells%20in%20a%20Worksheet%20(Aspose.Cells).cerniera lampo)