Formateo de un rango de Cells
Configuración de fuente y estilo de un rango de Cells
Antes de hablar sobre la configuración de formato (que ya hemos hablado mucho en nuestros temas anteriores), debemos saber cómo crear un rango de celdas. Bueno, podemos crear un rango de celdas usandorango de celdas clase cuyo constructor toma algunos parámetros para especificar el rango de celdas. Podemos especificar el rango de celdas usando elnombres oÍndices de fila y columna de celdas iniciales y finales.
Una vez que hemos creado unrango de celdas objeto entonces podemos usar las versiones sobrecargadas deEstablecerEstilo, Establecer fuente & Establecer color de fuente métodos de hoja de trabajo que pueden tomar unrango de celdas objeto para aplicar la configuración de formato en el rango de celdas especificado.
Veamos un ejemplo para entender este concepto básico.
// 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); |