Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Microsoft Excel allows users to format cells by adding borders. The type of border depends on where it is added. For example, a top border is one added to the top position of a cell. Users can also modify the borders' line style and color.
With Aspose.Cells for Node.js via C++, developers can add borders and customize what they look like in the same flexible way as in Microsoft Excel.
Aspose.Cells provides a class, Workbook that represents a Microsoft Excel file. The Workbook class contains a worksheets collection that allows access to each worksheet in the Excel file. A worksheet is represented by the Worksheet class. The Worksheet class provides the cells collection. Each item in the cells collection represents an object of the Cell class.
Aspose.Cells provides the getStyle method in the Cell class. The setStyle method is used to set a cell’s formatting style. The Style class provides properties for adding borders to cells.
Developers can add borders to a cell by using the Style object’s borders collection. The border type is passed as an index to the borders collection. All border types are pre-defined in the BorderType enumeration.
Border enumeration
| Border Types | Description |
|---|---|
| BottomBorder | A bottom border line |
| DiagonalDown | A diagonal line from top left to right bottom |
| DiagonalUp | A diagonal line from bottom left to right top |
| LeftBorder | A left border line |
| RightBorder | A right border line |
| TopBorder | A top border line |
The borders collection stores all borders. Each border in the borders collection is represented by a Border object which provides two properties, setColor and setLineStyle to set a border’s line color and style respectively.
To set a border’s line color, select a color using the Color enumeration (part of Node.js) and assign it to the Border object’s color property.
The border’s line style is set by selecting a line style from the CellBorderType enumeration.
CellBorderType enumeration
| Line Styles | Description |
|---|---|
| DashDot | Thin dash-dotted line |
| DashDotDot | Thin dash-dot-dotted line |
| Dashed | Dashed line |
| Dotted | Dotted line |
| Double | Double line |
| Hair | Hairline |
| MediumDashDot | Medium dash-dotted line |
| MediumDashDotDot | Medium dash-dot-dotted line |
| MediumDashed | Medium dashed line |
| None | No line |
| Medium | Medium line |
| SlantedDashDot | Slanted medium dash-dotted line |
| Thick | Thick line |
| Thin | Thin line |
| Select one of the line styles and then assign it to the Border object’s lineStyle property. |
It is also possible to add borders to a range of cells rather than just a single cell. To do so, first, create a range of cells by calling the cells collection’s createRange method. It takes the following parameters:
The createRange method returns a Range object, which contains the specified range of cells. The Range object provides a setOutlineBorder method that takes the following parameters to add a border to the range of cells:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.