Formattazione di un Intervallo di Celle
Impostazione del Carattere e dello Stile di un Intervallo di Celle
Prima di parlare delle impostazioni di formattazione (di cui abbiamo già parlato molto nei nostri argomenti precedenti), dovremmo sapere come creare un intervallo di celle. Bene, possiamo creare un intervallo di celle utilizzando la classe CellRange il cui costruttore richiede alcuni parametri per specificare l’intervallo di celle. Possiamo specificare l’intervallo di celle utilizzando i Nomi o gli Indici di Riga e Colonna delle celle di inizio e fine.
Una volta creato un oggetto CellRange possiamo utilizzare le versioni sovraccaricate dei metodi SetStyle, SetFont e SetFontColor di Worksheet che possono prendere un oggetto CellRange per applicare le impostazioni di formattazione all’intervallo specificato di celle.
Diamo un’occhiata a un esempio per capire questo concetto di base.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Setting sample values | |
GridCell cell = sheet.Cells["b7"]; | |
cell.SetCellValue("1"); | |
cell = sheet.Cells["c7"]; | |
cell.SetCellValue("2"); | |
cell = sheet.Cells["d7"]; | |
cell.SetCellValue("3"); | |
cell = sheet.Cells["e7"]; | |
cell.SetCellValue("4"); | |
// Creating a CellRange object starting from "B7" to "E7" | |
CellRange range = new CellRange(6, 1, 6, 4); | |
// Accessing and setting Style attributes | |
Style style = new Style(this.gridDesktop1); | |
style.Color = Color.Yellow; | |
// Applying Style object on the range of cells | |
sheet.SetStyle(range, style); | |
// Creating a customized Font object | |
Font font = new Font("Courier New", 12f); | |
// Setting the font of range of cells to the customized Font object | |
sheet.SetFont(range, font); | |
// Setting the font color of range of cells to Red | |
sheet.SetFontColor(range, Color.Red); |