Formatera ett intervall på Cells

Ställa in teckensnitt och stil för ett intervall på Cells

Innan vi pratar om formateringsinställningar (som vi redan har pratat mycket om i våra tidigare ämnen), bör vi veta om hur man skapar en rad celler. Tja, vi kan skapa en rad celler med hjälp avCellRange klass vars konstruktor tar några parametrar för att specificera cellintervallet. Vi kan specificera cellintervallet med hjälp avNamn ellerRad- och kolumnindex av start- och slutceller.

När vi har skapat enCellRange objekt så kan vi använda de överbelastade versionerna avSetStyle, SetFont & SetFontColor metoder för arbetsblad som kan ta enCellRange objekt för att tillämpa formateringsinställningar på det angivna cellintervallet.

Låt oss kolla in ett exempel för att förstå detta grundläggande koncept.

// 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);